3

Writing a test helper that handles all the fuckery with DB connections and transactions when the legacy under test uses multiple DB connections is so 👌👌👌👌👌👌👌👌👌👌👌👌👌👌

I can write tests for code that was untestable before 💦💦💦
*nerd-gasms*

Comments
  • 0
    What language? What was your strategy?
  • 1
    PHP and Laravel.
    Team collaborated on extending it to the DB facade.

    Had to:
    1. create a fake of the DatabaseManager class via an anonymous class extension so its connection() method always returns the tests' DB connection AND transaction.
    2. Swapped the DB facades' "accessor" to use the fake DB manager.
    3. Set all Models in Laravel to use the fake DB manager as well as the facade.
    4. Put it in a test helper trait so any Dev can use it to test code that uses multiple connections.

    Now the test teardowns the DB correctly + code under test has access to the DB fixture setup by the test as they use the same transaction (they didn't before).

    Glad I've got such an inventive team
Add Comment