Skip to content

Instantly share code, notes, and snippets.

@localheinz
Last active August 29, 2015 14:13
Show Gist options
  • Save localheinz/2ad804a3c5451780486d to your computer and use it in GitHub Desktop.
Save localheinz/2ad804a3c5451780486d to your computer and use it in GitHub Desktop.
How can you mark a test as skipped if the annotated data provider returns an empty array?
<?php
namespace Foo;
class BarTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (null === $this->providerBaz()) {
$this->markTestSkipped('No data');
}
}
/**
* @dataProvider providerBaz
*
* @param string $baz
*/
public function testBaz($baz)
{
// ...
}
/**
* @return array
*/
public function providerBaz()
{
// retrieve some data, may not have any
if (0 === count($data)) {
return null;
}
// return a not-empty array
}
}
@localheinz
Copy link
Author

I'm aware that this is only an interesting problem until providerBaz() returns a non-empty array - which should be pretty soon, but I'd still prefer not get a warning until then.

Running the test suite currently fails with

There was 1 failure:

1) Warning
No tests found in suite "Foo\BarTest::testBaz".

@stm555
Copy link

stm555 commented Jan 7, 2015

Maybe just prime the argument set array in the provider with an empty record?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment