Question

I am using the yii framework and phpunit. I can run phpunit test.

But I want to add asserts in my controller like it is described here. I think the class

 BankAccount

is no test. So there must be a way to use the asserts not in tests.

If I call an assert like this in my controller, which is no test:

 PHPUnit_Framework_Assert::assertTrue(false);

I get

currentPath\PHPUnit_Framework_Assert.php): failed to open stream: No such file or directory 

The file exists in my pear\phpunit directory.

So how can I use PHPUnit for design-by-contract? Or is there no way to add asserts like this for design-by-contract?

Ps: I am using namespaces

Was it helpful?

Solution

Thanks to this post I found the solution for my problem. Here is the code to enable Design-By-Contract asserts of PHPUnit in Yii Controllers and Helper Classes.

spl_autoload_unregister(array('YiiBase','autoload'));
require_once('PHPUnit/Autoload.php');
spl_autoload_register(array('YiiBase','autoload'));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top