for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Maketok\DataMigration\Input;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
class CsvTest extends \PHPUnit_Framework_TestCase
{
/**
* @var vfsStreamDirectory
*/
protected $root;
public function setUp()
$this->root = vfsStream::setup('root');
}
public function testRead()
$content = <<<CSV
id,name
1,John
2,Peter
CSV;
vfsStream::newFile('test.csv')->setContent($content)->at($this->root);
$csv = new Csv(vfsStream::url('root/test.csv'));
$this->assertSame([
'id' => '1',
'name' => 'John',
], $csv->get());
'id' => '2',
'name' => 'Peter',
$this->assertSame(false, $csv->get());
* @expectedException \Maketok\DataMigration\Storage\Exception\ParsingException
* @expectedExceptionMessage Row contains wrong number of columns compared to header
public function testWrongRead()
1,John,Smith
$csv->get();
* @depends testRead
public function testReset()
$csv->reset();
public function testWrite()
$file = vfsStream::newFile('test.csv');
$file->at($this->root);
$csv = new Csv(vfsStream::url('root/test.csv'), 'w');
$csv->add([
]);
$expected = <<<CSV
$this->assertEquals($expected, $file->getContent());