0

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

EvilKarter
  • 267
  • 7
  • 22
  • Would you kindly tell us how you're running your tests? The Definite Guide to Yii has an [entire chapter](http://www.yiiframework.com/doc/guide/1.1/en/test.overview) dedicated to that topic. – DaSourcerer Dec 10 '13 at 13:56
  • Hi i edited my question. But I execute the unit test on command line. But the `PHPUnit_Framework_Assert::assertTrue(false);` is not in my unit test. It is in one of my controllers. – EvilKarter Dec 10 '13 at 14:02
  • Well, it doesn't belong there in the first place. – DaSourcerer Dec 10 '13 at 14:22
  • Why? It enables design-by-contract style. – EvilKarter Dec 10 '13 at 14:24
  • Ah, scrap that. I got distracted and fell back t the way I test controllers. – DaSourcerer Dec 10 '13 at 14:49
  • I've been trying for an hour now without satisfiable results, sorry :-/ If you're in for a not-so-quick hack: You can declare all required classes and interfaces in the [class map](http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace#importing-classes). But it really should be a question of beating Yii's autoloader into submission. – DaSourcerer Dec 10 '13 at 16:36

1 Answers1

0

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'));
EvilKarter
  • 267
  • 7
  • 22