Yii: design-by-contract with PHPUnit 3.7

82 views Asked by At

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

1

There are 1 answers

0
EvilKarter On BEST ANSWER

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'));