2

So I'm using PHPUnit for testing. Trying to use a DataProvider with one of my tests.

/**
 * Tests Events_Event->Events_Event()
 * @dataProvider provider
 */
public function testEvents_Event($Name, $param, $time) {
        //$this->assertInstanceOf("Events_Event", $this->Events_Event->Events_Event("test2", array()));
        $this->assertTrue(true);
    }

public static function provider()
    {
        return array(
            array("test", array("Like a boss"), "Cheack the time"),
            array("test2", array("Like a boss"), "9:00"),
            array("test3", array("Time to go home"), "4:00"),
            array("test3", array("Time to go home"), "4:00")
            );
    }

The results:

testEvents_Event with data set#0
testEvents_Event with data set#1
testEvents_Event with data set#2
testEvents_Event with data set#3: The test case was unexpectedly terminated

This happens on the last data set no matter how many there are and whether or not the last data set is valid of not. As you can see, we've simplified the test to a simple $this->assertTrue(true) and it's still giving us the error.

What do we need to do to get the Data Provider working?

In case it's important I'm working PHPUnit inside Zend Studio 9.0.3, I've checked for updates and it's telling me all is up to date.

CLo
  • 3,650
  • 3
  • 26
  • 44
  • Run these test locally with xdebug enabled and step through the code line by line until you get to the bit throwing that error. Time-intensive, but the only way to find out in the absence of any other clues. Would help to grep the PHPUnit code for lines that have that error text, then set a breakpoint there and when it stops, use the stacktrace to see where it's got to. – Matt Gibson May 18 '12 at 13:27
  • 2
    Try to upgrade PHPUnit to the latest version – Gordon May 18 '12 at 13:34
  • @MattGibson I'm really hoping to get to an answer without getting that dirty. But definitely a good approach if I can't get anywhere with Google searches. – CLo May 18 '12 at 14:45
  • @Gordon edited the question, I'm working in Zend Studio, with the latest updates for everything. I haven't been able to find the actual version of PHPUnit yet though. – CLo May 18 '12 at 14:47
  • 2
    @Chris this could be a bug in Zend Studio then. They are wrapping PHPUnit with their own scripts and I know from bug reports I gave them in the past that they sometimes fail with that. So you could try to create reproducable testcase and submit it to Zend Support. – Gordon May 18 '12 at 14:52
  • @Gordon - it looks like he already has a reproducible test case. – Spudley May 20 '12 at 20:12
  • 1
    @Spudley I mean a complete one with the whole class declaration, so the support can run it. – Gordon May 20 '12 at 20:47

2 Answers2

1

I was going through

....

Time: 0 seconds, Memory: 12.75Mb

OK (4 tests, 0 assertions)

/**
 * Tests Events_Event->Events_Event()
 * @dataProvider provider
 */
public function testEvents_Event($Name, $param, $time)
{

}

public static function provider()
{
    return array(
        array("test", array("Like a boss"), "Cheack the time"),
        array("test2", array("Like a boss"), "9:00"),
        array("test3", array("Time to go home"), "4:00"),
        array("test3", array("Time to go home"), "4:00")
        );
}

how to you run tests? there do not have any other dependencies? tests runing via any IDE?

RDPanek
  • 96
  • 4
1

PHPUnit instantiates the test case for each data provider method. Due to the magic of PHP you can get away with using static data provider methods, but they are called using an instance and thus should be non-static.

If your test case has a constructor, it must accept three parameters (see the source for PHPUnit_Framework_TestCase) and pass them to the parent constructor. One of them is the data from a provider for that particular test.

I doubt these are the problem, however. My money's on ZendStudio and how it parses the output from PHPUnit as Gordon suggested. When you run this test case from the command line, do you see the same issue?

David Harkness
  • 35,992
  • 10
  • 112
  • 134