Add test for Icinga\File\Csv

refs #6011
This commit is contained in:
Johannes Meyer 2014-04-23 14:40:39 +02:00
parent e8ed7c7166
commit 87863d3212
2 changed files with 43 additions and 0 deletions

View File

@ -1,4 +1,6 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\File;
@ -10,6 +12,7 @@ class Csv
protected function __construct()
{
}
public static function fromQuery(BaseQuery $query)
@ -40,6 +43,7 @@ class Csv
}
$csv .= implode(',', $out) . "\r\n";
}
return $csv;
}
}

View File

@ -0,0 +1,39 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\File;
use Mockery;
use Icinga\File\Csv;
use Icinga\Test\BaseTestCase;
class CsvTest extends BaseTestCase
{
public function testWhetherValidCsvIsRendered()
{
$queryMock = Mockery::mock(
'Icinga\Data\BaseQuery',
array(
'fetchAll' => array(
array('col1' => 'val1', 'col2' => 'val2', 'col3' => 'val3', 'col4' => 'val4'),
array('col1' => 'val5', 'col2' => 'val6', 'col3' => 'val7', 'col4' => 'val8')
)
)
);
$csv = Csv::fromQuery($queryMock);
$this->assertEquals(
join(
"\r\n",
array(
'col1,col2,col3,col4',
'"val1","val2","val3","val4"',
'"val5","val6","val7","val8"'
)
) . "\r\n",
(string) $csv,
'Csv does not render valid/correct csv structured data'
);
}
}