phpphpunit

Why is phpunit skipping most of my tests even though their dependency succeeded?


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


Solution

  • 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),
    );
    }
    
    }