Search This Blog

Tuesday, November 23, 2010

Problem with PHPUnit and Data Providers

Programmer Question

I have the following test case:



include_once('../Logger.php');

class LoggerTest extends PHPUnit_Framework_TestCase {

static public function providerLogger() {
return array(
new Logger
);
}

/**
* @dataProvider providerLogger
*/
public function testAddStream($logger) {
$this->assertTrue(false);
}

}


When I run it in PHPUnit, I get:



PHPUnit 3.4.14 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 5.75Mb

There was 1 failure:

1) Warning
The data provider specified for LoggerTest::testAddStream is invalid.
Data set #0 is invalid.


FAILURES!
Tests: 1, Assertions: 0, Failures: 1.


I remember having it working in a similar fashion before, but I could be wrong. What am I missing?



Thanks in advance for your help.



PHPUnit 3.4.14 (taken from PEAR) on PHP 5.3.3



Find the answer here

1 comment:

  1. The data provider has to provide an array of array, see the documentation on that.

    ReplyDelete

Related Posts with Thumbnails