mardi 2 août 2016

PHPUnit tight coupling causing test failure

I'm working on writing PHPUnit & dbUnit test cases for existing software while my coworker is currently working on similar test cases for similar software. I've been using him as a resource (he knows what he's doing testing-wise), but he doesn't really know how to solve this problem.

I have a coupling issue. I have three files that are causing the issue: database.php, session.php, and functions.php.

database.php requires that a function called "decrypt" exists in functions.php.

session.php requires that database objects exists (created by database.php).

functions.php requires that session and database objects are already created.

So, the tree looks roughly like this

database requires functions requires database requires functions requires database etc. and so on.

This is causing PHPUnit to throw up. I've tried to get around this via mocking the database and session objects, but PHPUnit still isn't a fan - it's not liking the mysql_connect parameters for some reason.

Is there a way around the coupling or should I get the code rewritten? I know coupling this tight is terrible programming practice, but it does work when it's run on a page; PHPUnit is the only thing throwing a hissy-fit over it.

Aucun commentaire:

Enregistrer un commentaire