I have a PHPUnit test which uses a @dataProvider
. The dataprovider checks the filesystem for certain files.
However I'm using this test in different environments what means it can happen that the files do not exist. This means that the dataProvider does not find anything and that the test is not executed.
And this causes the test run to end in a failure.
Question: is the a way to configure PHPUnit to ignore tests which have providers that produce nothing?
While I do not know of any phpunit option (which doesn't mean one doesn't exist), you could just use something like the following:
public function providerNewFileProvider()
{
//get files from the "real" provider
$files = $this->providerOldFileProvider();
//no files? then, make a fake entry to "skip" the test
if (empty($files)) {
$files[] = array(false,false);
}
return $files;
}
/**
* @dataProvider providerNewFileProvider
*/
public function testMyFilesTest($firstArg,$secondArg)
{
if (false === $firstArg) {
//no files existing is okay, so just end immediately
$this->markTestSkipped('No files to test');
}
//...normal operation code goes here
}
It's a workaround, sure, but it should stop an error from showing up. Obviously, whatever you do will depend on whether the first (or any arbitrary) argument is allowed to be false
, but you can make tweaks to fit your tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With