I’m using PHPUnit 3.4.9, but I’m having some problems with the @depends annotation. It works like in the examples, but breaks when the producer reliers on a provider. I don’t know if this is meant to work or not, but my code is basically in the form:
<?php
class StackTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider provider
*/
public function testEmpty ($data)
{
$stack = array();
$this->assertTrue(empty($stack));
return $stack;
}
/**
* @depends testEmpty
*/
public function testPush (array $stack)
{
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertFalse(empty($stack));
return $stack;
}
/**
* @depends testPush
*/
public function testPop (array $stack)
{
$this->assertEquals('foo', array_pop($stack));
$this->assertTrue(empty($stack));
}
public function provider ()
{
return array(
// Some testing data here...
);
}
}
The code above is just an example, but shows what my code’s structure is like. When ran, it skips the consumer tests, acting as though the producer had failed. I’m expecting that for every set of testing data in the provider, the producer will be run with that data, and all of its consumer correspondingly run.
Since the question is already 2 days old i give it a shot:
It doesn’t seem to work the way you want it to.
@dependsjust looks if a test with the name provided has run and gets the result. It doesn’t even know or care about the @annotations of said test.I’d guess (haven’t dug deep enough into the phpunit source to be 100% sure) tests with
@dependsare run as “group of tests” internally and not as a single one so there is not test named “testEmpty” and the depends fails.So to provide a workaround the only thing i can think of right now is to call those “sub tests” directly.
Hope that helps or at least motivates someone else to answer 😉