title: How to skip tests on error in PHPUnit?
body: <p>How do I get PHPUnit to skip tests when the dependent one has an error with a data set?</p>
  
  <hr>
  
  <h1>Works</h1>
  
  <p>If my data provider only has things that cause errors, then it will appropriately skip the dependent tests. <strong>Note</strong> the <code>Skipped: 1</code></p>
  
  <pre><code>class DataProviderDependsTest extends PHPUnit_Framework_TestCase
  {
      public function getDataProvider(){
        return [
          ['non-existent_file.txt'],
        ];
      }
  
      /**
       *  @dataProvider getDataProvider
       */
      public function testCanBeDependedOn($data){
        $actual = file_get_contents($data);
        $this-&gt;assertSame('expected',$actual);
      }
  
      /**
       *  @dataProvider getDataProvider
       *  @depends testCanBeDependedOn
       */
      public function testCanDepend($data){
        $this-&gt;assertTrue(false);
      }
  }
  </code></pre>
  
  <blockquote>
  <pre><code>PHPUnit 5.5.0 by Sebastian Bergmann and contributors.
  
  ES                                                                  2 / 2 (100%)
  
  Time: 28 ms, Memory: 4.00MB
  
  There was 1 error:
  
  1) DataProviderDependsTest::testCanBeDependedOn with data set #0 ('non-existent_file.txt')
  file_get_contents(non-existent_file.txt): failed to open stream: No such file or directory
  
  /home/xenial/phpunittest/test.php:16
  
  ERRORS!
  Tests: 1, Assertions: 0, Errors: 1, Skipped: 1.
  </code></pre>
  </blockquote>
  
  <hr>
  
  <h1>Does Not Work</h1>
  
  <p>However, if I add one piece of good data to the provider, then despite the errors caused by the rest, PHPUnit proceeds to execute <strong><em>all</em></strong> the dependent tests anyway (even the corresponding data sets with errors). It doesn't skip anything. <strong>Note</strong> the added <code>['real_file.txt'],</code> to the data provider.</p>
  
  <pre><code>class DataProviderDependsTest extends PHPUnit_Framework_TestCase
  {
      public function getDataProvider(){
        return [
          ['real_file.txt'],
          ['non-existent_file.txt'],
        ];
      }
  
      /**
       *  @dataProvider getDataProvider
       */
      public function testCanBeDependedOn($data){
        $actual = file_get_contents($data);
        $this-&gt;assertSame('expected',$actual);
      }
  
      /**
       *  @dataProvider getDataProvider
       *  @depends testCanBeDependedOn
       */
      public function testCanDepend($data){
        $this-&gt;assertTrue(false);
      }
  }
  </code></pre>
  
  <blockquote>
  <pre><code>PHPUnit 5.5.0 by Sebastian Bergmann and contributors.
  
  .EFF                                                                4 / 4 (100%)
  
  Time: 19 ms, Memory: 4.00MB
  
  There was 1 error:
  
  1) DataProviderDependsTest::testCanBeDependedOn with data set #1 ('non-existent_file.txt')
  file_get_contents(non-existent_file.txt): failed to open stream: No such file or directory
  
  /home/xenial/phpunittest/test.php:16
  
  --
  
  There were 2 failures:
  
  1) DataProviderDependsTest::testCanDepend with data set #0 ('real_file.txt')
  Failed asserting that false is true.
  
  /home/xenial/phpunittest/test.php:25
  
  2) DataProviderDependsTest::testCanDepend with data set #1 ('non-existent_file.txt')
  Failed asserting that false is true.
  
  /home/xenial/phpunittest/test.php:25
  
  ERRORS!
  Tests: 4, Assertions: 3, Errors: 1, Failures: 2.
  </code></pre>
  </blockquote>
  
  <p>PHPUnit doesn't skip <a href="https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.depends" rel="nofollow"><code>@depends</code></a> tests on error when using <a href="https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers" rel="nofollow"><code>@dataProvider</code></a></p>
  
  <p>From <a href="https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.test-dependencies" rel="nofollow">their docs</a>:</p>
  
  <blockquote>
    <h1>Note</h1>
    
    <p>When a test depends on a test that uses data providers, <em>the depending test will be executed when the test it depends upon is successful for <strong>at least one data set.</em></strong></p>
  </blockquote>
  
  <p>I would like to skip some tests all together if any part of the provided data in the depended test causes an error. Is there any way to workaround this limitation?</p>
  
  <hr>
  
  <p>You can <a href="https://github.com/admonkey/phpunittest/fork" rel="nofollow">fork these files</a> for quick tests if you want, or just clone:</p>
  
  <pre><code>git clone https://github.com/admonkey/phpunittest.git
  </code></pre>