Wow, only 9 days after you sent the question :-) I've never used Enhance, but have logged lots of hours using PHPUnit:
https://github.com/sebastianbergmann/phpunit/ It's very powerful in my experience, and it also supports test coverage reporting with Xdebug http://xdebug.org/ If you want a bunch of good advice on writing test cases, I can recommend the book xUnit Test Patterns http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Code/dp/0131495054 And when you have it memorized you can use it as a doorstop, since it's 900 pages long :-) -- Walt On 12/05/2011 05:27 PM, Aaron Luman wrote: > I am just starting a new job and they would like me to start creating test > cases to incorporate into the project development. I would like to use > Enhance PHP [1] as it does not require an 'installation' and seems to be > popular on stackoverflow. But, since it's so new, I'm having trouble finding > good guides online with sample usages. I followed the all of the guides but > am having a hard time getting the "Mock" stuff working correctly. It could > be that I just don't really know what's going on as this is all fairly new to > me... > > Here is what I have: > > <?php > > include_once('EnhanceTestFramework.php'); > > class ExampleClass > { > private $OtherClass; > > function __construct() > { > $this->OtherClass = new OtherExampleClass; > } > > public function doSomething() > { > return $this->OtherClass->getSomething(1, 'Arg2'); > } > } > > class OtherExampleClass > { > public function getSomething() > { > return "Something"; > } > } > > class ExampleClassTests extends \Enhance\TestFixture > { > public function setUp() > { > } > > public function tearDown() > { > } > > public function verifyWithAMock() > { > $mock = \Enhance\MockFactory::createMock('OtherExampleClass'); > $mock->addExpectation( > \Enhance\Expect::method('getSomething') > ->with(1, 'Arg2') > ->returns('Something') > ->times(1) > ); > $target = new ExampleClass($mock); > $result = $target->doSomething(); > \Enhance\Assert::areIdentical("Something", $result); > > $mock->verifyExpectations(); > } > } > > \Enhance\Core::runTests(); > ?> > > which, when run, gives me this result: > > verifyWithAMock - Failed - Expectation failed > OtherExampleClass->getSomething(1, Arg2) Expected #1 Called #0 > > What is it that I am missing? > > Thanks for the help, > > Aaron > > 1 - http://www.enhance-php.com/ > > _______________________________________________ > > UPHPU mailing list > [email protected] > http://uphpu.org/mailman/listinfo/uphpu > IRC: #uphpu on irc.freenode.net _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
