title: How to use a csv file in PHPUnit test
body: <p>I wrote a DataTest case following the example 4.5 of PHPUnit manual, the url is:<br> <a href="http://www.phpunit.de/manual/3.6/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers" rel="noreferrer">http://www.phpunit.de/manual/3.6/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers</a>. <br>But I came across with an error:</p>
  
  <blockquote>
    <p><em>The data provider specified for DataTest::testAdd is invalid.<br>
    Data set #0 is invalid.</em></p>
  </blockquote>
  
  <p>I thought it maybe that I edit the data.csv file in a wrong way, then I used php function fputcsv() to create data.csv file, but it also didn't work, I want to know why, and how to resolve this problem. Thanks!<br></p>
  
  <p>P. S.: the data in data.csv is:<br></p>
  
  <blockquote>
    <p>0,0,0<br>
    0,1,1<br></p>
  </blockquote>
  
  <p><hr/>
  The codes are show as follows:<br>
  DataTest.php<br></p>
  
  <pre><code>require 'CsvFileIterator.php';
  class DataTest extends PHPUnit_Framework_TestCase
  {
  public function provider()
      {
          return new CsvFileIterator('data.csv');
      }
  
      /**
      * @dataProvider provider
      */
      public function testAdd($a, $b, $c)
      {
           $this-&gt;assertEquals($c, $a + $b);
      }
  }
  </code></pre>
  
  <p>CsvFileIterator.php</p>
  
  <pre><code>class CsvFileIterator implements Iterator
  {
      protected $file;
      protected $key = 0;
  protected $current;
  
  public function __construct($file)
  {
      $this-&gt;file = fopen($file, 'r');
  }
  
  public function __destruct()
  {
      fclose($this-&gt;file);
  }
  
  public function rewind()
  {
      rewind($this-&gt;file);
      $this-&gt;current = fgetcsv($this-&gt;file);
      $this-&gt;key = 0;
  }
  
  public function valid()
  {
      return !feof($this-&gt;file);
  }
  
  public function key()
  {
      return $this-&gt;key;
  }
  
  public function current()
  {
      return $this-&gt;current;
  }
  
  public function next()
  {
      $this-&gt;current = fgetcsv($this-&gt;file);
      $this-&gt;key++;
  }
  }
  </code></pre>
  
  <p>The data.csv file is create by function fputcsv():</p>
  
  <pre><code>$data = array(
  array(0, 0, 0),
  array(0, 1, 1)
  );
  
  $fp = fopen('data.csv', 'w');
  
  foreach($data as $v)
  {
  fputcsv($fp, $v);
  }
  fclose($fp);
  </code></pre>