2

I have a PHPUnit test that looks something like this:

/**
 * @dataProvider provideSomeStuff
 */
public function testSomething($a, $b, $c)
{
    ...
}

/**
 * @dataProvider provideSomeStuff
 * @depends testSomething
 */
public function testSomethingElse($a, $b, $c)
{
    ...
}

/**
 * @depends testSomething
 */
public function testMoreStuff()
{
    ...
}

// Several more tests with the exact same setup as testMoreStuff

Even though testSomething succeeds, all the tests that depend on it is skipped. Some notes in the PHPUnit manual informs that tests can depend on other tests that use data providers:

Note
When a test receives input from both a @dataProvider method and from one or more tests it @depends on, the arguments from the data provider will come before the ones from depended-upon tests.

Note
When a test depends on a test that uses data providers, the depending test will be executed when the test it depends upon is successful for at least one data set. The result of a test that uses data providers cannot be injected into a depending test.

So I have no CLUE why it just skips all my tests. I've been struggling with this for hours, somebody help me out. Here's the complete test code in case the issue can't be derived from the above pseudo code

Screenshot of the test results:

Test results

1

3 Answers 3

2

This appears to be a bug in phpunit 3.4.5, but fixed in phpunit 3.4.12.

Below is a minimal example, based on the one in the manual. I get the same behaviour as you in PHPUnit 3.4.5, but I get 4 passes in PHPUnit 3.6.11. Narrowing it down, the phpunit 3.4 changelog says it was fixed in PHPUnit 3.4.12.

class DataTest extends PHPUnit_Framework_TestCase
{

/**
* @dataProvider provider
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}


/**
* @depends testAdd
*/
public function testAddAgain()
{
$this->assertEquals(5,3+2);
}

/** */
public function provider()
{
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
);
}

}
3
  • I'm using PHPUnit 3.6.10 though and I'm still experiencing this behaviour
    – Hubro
    Jun 17, 2012 at 17:16
  • 1
    (Your screenshot says 3.4.5; I'll assume you mean you've upgraded since then) Do you still get the problem on the minimal example I posted above? That is the complete file, just add a <?php at the top, save it as testdeps.php and run it with phpunit testdeps.php from the same directory. Jun 18, 2012 at 0:21
  • 1
    Oh wow, I didn't realize I had different versions at work and at home. I'll have to try to run the tests again when I get home. Good thing one of us is paying attention *thumbs up*
    – Hubro
    Jun 18, 2012 at 5:35
0

To have a better idea to why your test be getting skipped you can use verbose.

phpunit --verbose .....

-1

You must define the dependant methods AFTER the main method.

public function testSomething()
{
    $foo = [];
    //test something
    return $foo;
}

/** 
 * @depends testSomething
 */
public function testBar(array $foo)
{
    //more tests 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.