BreadBoard icon indicating copy to clipboard operation
BreadBoard copied to clipboard

Make it possible to track whether a service has been instantiated?

Open autarch opened this issue 9 years ago • 1 comments

I was working on some code recently where I had a container for my test code that could be used to create a temporary database for fixtures. The database should be removed at the end of each test run, or else I end up with a million databases named "Foo_12345".

However, it's possible some tests would never resolve the fixtures service, so the database would never be created. I tried to get the database object to clean up after itself on DEMOLISH, but the unpredictability of Perl's global destruction order make this really difficult (or plain impossible).

I have a test runner that wraps my TCM classes that is perfectly positioned to do this, though. It can run the tests and then check if the container resolved the fixtures. If so, it disconnects the database handle (also made by the container), then drops the test database.

I made this all work by just wrapping the Bread::Board::Container in my own object that has its own resolve method that just tracks what strings it sees. It'd be a lot nicer if it knew that '/foo' and 'foo' were equivalent services though, which is why I'd like to see this in BB itself. Something like a $container->resolved_service or ->service_was_resolved or something like that.

autarch avatar Sep 08 '16 21:09 autarch

Sounds sensible to me.

stevan avatar Sep 08 '16 22:09 stevan