test case
This commit is contained in:
parent
4eb4568215
commit
26604381ab
|
@ -2,78 +2,7 @@
|
||||||
|
|
||||||
use Deblan\Csv\Csv;
|
use Deblan\Csv\Csv;
|
||||||
|
|
||||||
class CsvTest extends \PHPUnit_Framework_TestCase
|
class CsvParserTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testAddLine()
|
|
||||||
{
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
$this->assertEquals('"foo";"bar"'."\n", $csv->compile());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSetLegend()
|
|
||||||
{
|
|
||||||
$csv = new Csv();
|
|
||||||
|
|
||||||
$this->assertEquals(false, $csv->getHasLegend());
|
|
||||||
|
|
||||||
$csv->setLegend(array('bim', 'bam'));
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
|
|
||||||
$this->assertEquals(true, $csv->getHasLegend());
|
|
||||||
$this->assertEquals(
|
|
||||||
'"bim";"bam"'."\n".
|
|
||||||
'"foo";"bar"'."\n",
|
|
||||||
$csv->compile()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testHasDatas()
|
|
||||||
{
|
|
||||||
$csv = new Csv();
|
|
||||||
$this->assertEquals(false, $csv->hasDatas());
|
|
||||||
|
|
||||||
$csv->setLegend(array('bim', 'bam'));
|
|
||||||
$this->assertEquals(false, $csv->hasDatas());
|
|
||||||
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
$this->assertEquals(true, $csv->hasDatas());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
$this->assertEquals(true, $csv->hasDatas());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDatasToCsvLine()
|
|
||||||
{
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->addLine(array('fo\\o', 'bar'));
|
|
||||||
$this->assertEquals('"fo\\\\o";"bar"'."\n", $csv->compile());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->setDelimiter(':');
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
$this->assertEquals('"foo":"bar"'."\n", $csv->compile());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->setDelimiter(':');
|
|
||||||
$csv->addLine(array('fo:o', 'bar'));
|
|
||||||
$this->assertEquals('"fo:o":"bar"'."\n", $csv->compile());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->setDelimiter(':');
|
|
||||||
$csv->setEnclosure('');
|
|
||||||
$csv->addLine(array('fo:o', 'bar'));
|
|
||||||
$this->assertEquals('fo\\:o:bar'."\n", $csv->compile());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->setEnclosure('#');
|
|
||||||
$csv->addLine(array('foo', 'bar'));
|
|
||||||
$this->assertEquals('#foo#;#bar#'."\n", $csv->compile());
|
|
||||||
|
|
||||||
$csv = new Csv();
|
|
||||||
$csv->setEnclosure('#');
|
|
||||||
$csv->addLine(array('f#oo', 'bar'));
|
|
||||||
$this->assertEquals('#f\\#oo#;#bar#'."\n", $csv->compile());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,18 @@ class CsvTest extends \PHPUnit_Framework_TestCase
|
||||||
$csv->setLegend(array('bim', 'bam'));
|
$csv->setLegend(array('bim', 'bam'));
|
||||||
$csv->addLine(array('foo', 'bar'));
|
$csv->addLine(array('foo', 'bar'));
|
||||||
|
|
||||||
|
$this->assertEquals(true, $csv->getHasLegend());
|
||||||
|
$this->assertEquals(
|
||||||
|
'"bim";"bam"'."\n".
|
||||||
|
'"foo";"bar"'."\n",
|
||||||
|
$csv->compile()
|
||||||
|
);
|
||||||
|
|
||||||
|
$csv = new Csv();
|
||||||
|
|
||||||
|
$csv->addLine(array('foo', 'bar'));
|
||||||
|
$csv->setLegend(array('bim', 'bam'));
|
||||||
|
|
||||||
$this->assertEquals(true, $csv->getHasLegend());
|
$this->assertEquals(true, $csv->getHasLegend());
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'"bim";"bam"'."\n".
|
'"bim";"bam"'."\n".
|
||||||
|
|
Loading…
Reference in a new issue