src/lib/Iamapen/ExcelFriendlyDataSet/Database/DataSet/ExcelCsvDataSet.php
public function addTable($tableName, $csvFile)
    {
        if (!is_file($csvFile)) {
            throw new \InvalidArgumentException("Could not find csv file: {$csvFile}");
        }

        if (!is_readable($csvFile)) {
            throw new \InvalidArgumentException("Could not read csv file: {$csvFile}");
        }

        $fh      = fopen($csvFile, 'rb');
        fseek($fh, 2);  // after BOM

        // TODO chunk
        $tmpFp = fopen('php://temp', 'w+b');
        fwrite($tmpFp, mb_convert_encoding(stream_get_contents($fh), 'UTF-8', 'UTF-16LE'));
        rewind($tmpFp);

        $columns = $this->getCsvRow($tmpFp);

        if ($columns === FALSE)
        {
            throw new \InvalidArgumentException("Could not determine the headers from the given file {$csvFile}");
        }

        $metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
        $table    = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);

        while (($row = $this->getCsvRow($tmpFp)) !== FALSE)
        {
            $table->addRow(array_combine($columns, $row));
        }

        $this->tables[$tableName] = $table;
    }
public function addTable($tableName, $csvFile)
    {
        if (!is_file($csvFile)) {
            throw new \InvalidArgumentException("Could not find csv file: {$csvFile}");
        }

        if (!is_readable($csvFile)) {
            throw new \InvalidArgumentException("Could not read csv file: {$csvFile}");
        }

        $fh      = fopen($csvFile, 'rb');
        fseek($fh, 2);  // after BOM

        // TODO chunk
        $tmpFp = fopen('php://temp', 'w+b');
        fwrite($tmpFp, mb_convert_encoding(stream_get_contents($fh), 'UTF-8', 'UTF-16LE'));
        rewind($tmpFp);

        $columns = $this->getCsvRow($tmpFp);

        if ($columns === FALSE)
        {
            throw new \InvalidArgumentException("Could not determine the headers from the given file {$csvFile}");
        }

        $metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
        $table    = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);

        while (($row = $this->getCsvRow($tmpFp)) !== FALSE)
        {
            $table->addRow(array_combine($columns, $row));
        }

        $this->tables[$tableName] = $table;
    }
public function addTable ( $ tableName , $ csvFile ) { if ( ! is_file ( $ csvFile ) ) { throw new \ InvalidArgumentException ( "Could not find csv file: {$csvFile}" ) ; } if ( ! is_readable ( $ csvFile ) ) { throw new \ InvalidArgumentException ( "Could not read csv file: {$csvFile}" ) ; } $ fh = fopen ( $ csvFile , 'rb' ) ; fseek ( $ fh , 2 ) ; // after BOM // TODO chunk $ tmpFp = fopen ( 'php://temp' , 'w+b' ) ; fwrite ( $ tmpFp , mb_convert_encoding ( stream_get_contents ( $ fh ) , 'UTF-8' , 'UTF-16LE' ) ) ; rewind ( $ tmpFp ) ; $ columns = $ this -> getCsvRow ( $ tmpFp ) ; if ( $ columns === FALSE ) { throw new \ InvalidArgumentException ( "Could not determine the headers from the given file {$csvFile}" ) ; } $ metaData = new \ PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData ( $ tableName , $ columns ) ; $ table = new \ PHPUnit_Extensions_Database_DataSet_DefaultTable ( $ metaData ) ; while ( ( $ row = $ this -> getCsvRow ( $ tmpFp ) ) !== FALSE ) { $ table -> addRow ( array_combine ( $ columns , $ row ) ) ; } $ this -> tables [ $ tableName ] = $ table ; }
Adds a table to the dataset

The table will be given the passed name. $csvFile should be a path to
a valid csv file (based on the arguments passed to the constructor.)

@param string $tableName
@param string $csvFile
Adds a table to the dataset