|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fmaj\LaposteDatanovaBundle\Tests\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Fmaj\LaposteDatanovaBundle\Parser\CsvParser; |
|
6
|
|
|
|
|
7
|
|
|
class CsvParserTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testParseCsvFixture() |
|
10
|
|
|
{ |
|
11
|
|
|
$dataset = 'laposte_hexasmal'; |
|
12
|
|
|
$finder = $this->getFinderMock($dataset, dirname(__FILE__) . '/Fixtures/laposte_hexasmal.csv'); |
|
13
|
|
|
|
|
14
|
|
|
$csvParser = new CsvParser($finder); |
|
|
|
|
|
|
15
|
|
|
$result = $csvParser->parse($dataset); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertNotFalse($result); |
|
18
|
|
|
$this->assertCount(15, $result); |
|
19
|
|
|
$this->assertArrayHasKey('code_commune_insee', $result[0]); |
|
20
|
|
|
$this->assertArrayHasKey('nom_commune', $result[0]); |
|
21
|
|
|
$this->assertArrayHasKey('code_postal', $result[0]); |
|
22
|
|
|
$this->assertArrayHasKey('libelle_acheminement', $result[0]); |
|
23
|
|
|
$this->assertArrayHasKey('ligne_5', $result[0]); |
|
24
|
|
|
$this->assertEquals('57077', $result[0]['code_commune_insee']); |
|
25
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['nom_commune']); |
|
26
|
|
|
$this->assertEquals('57630', $result[0]['code_postal']); |
|
27
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['libelle_acheminement']); |
|
28
|
|
|
$this->assertEquals('', $result[0]['ligne_5']); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $dataset |
|
33
|
|
|
* @param string $path |
|
34
|
|
|
* |
|
35
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Fmaj\LaposteDatanovaBundle\Service\Finder |
|
36
|
|
|
*/ |
|
37
|
|
|
private function getFinderMock($dataset, $path) |
|
38
|
|
|
{ |
|
39
|
|
|
$mock = $this->getMockBuilder('Fmaj\LaposteDatanovaBundle\Service\Finder') |
|
40
|
|
|
->disableOriginalConstructor() |
|
41
|
|
|
->getMock(); |
|
42
|
|
|
$mock->expects($this->once()) |
|
43
|
|
|
->method('findDataset') |
|
44
|
|
|
->with($dataset, CsvParser::FORMAT) |
|
45
|
|
|
->willReturn($path); |
|
46
|
|
|
|
|
47
|
|
|
return $mock; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.