|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Laposte\DatanovaBundle\Tests\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Laposte\DatanovaBundle\Parser\CsvParser; |
|
6
|
|
|
|
|
7
|
|
|
class CsvParserTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testParseCsvFixture() |
|
10
|
|
|
{ |
|
11
|
|
|
$dataset = 'laposte_hexasmal'; |
|
12
|
|
|
$path = dirname(__FILE__) . '/Fixtures/laposte_hexasmal.csv'; |
|
13
|
|
|
$finder = $this->getFinderMock(); |
|
14
|
|
|
$finder->expects($this->once()) |
|
|
|
|
|
|
15
|
|
|
->method('findDataset') |
|
16
|
|
|
->with($dataset, CsvParser::FORMAT) |
|
17
|
|
|
->willReturn($path); |
|
18
|
|
|
|
|
19
|
|
|
$csvParser = new CsvParser($finder); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
$result = $csvParser->parse($dataset); |
|
22
|
|
|
$this->assertNotFalse($result); |
|
23
|
|
|
$this->assertCount(15, $result); |
|
24
|
|
|
$this->assertArrayHasKey('code_commune_insee', $result[0]); |
|
25
|
|
|
$this->assertArrayHasKey('nom_commune', $result[0]); |
|
26
|
|
|
$this->assertArrayHasKey('code_postal', $result[0]); |
|
27
|
|
|
$this->assertArrayHasKey('libelle_acheminement', $result[0]); |
|
28
|
|
|
$this->assertArrayHasKey('ligne_5', $result[0]); |
|
29
|
|
|
$this->assertEquals('57077', $result[0]['code_commune_insee']); |
|
30
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['nom_commune']); |
|
31
|
|
|
$this->assertEquals('57630', $result[0]['code_postal']); |
|
32
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['libelle_acheminement']); |
|
33
|
|
|
$this->assertEquals('', $result[0]['ligne_5']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Laposte\DatanovaBundle\Service\Finder |
|
38
|
|
|
*/ |
|
39
|
|
|
private function getFinderMock() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->getMockBuilder('Laposte\DatanovaBundle\Service\Finder') |
|
42
|
|
|
->disableOriginalConstructor() |
|
43
|
|
|
->getMock(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: