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
}
}
@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