1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Laposte\DatanovaBundle\Tests\Model; |
4
|
|
|
|
5
|
|
|
use Laposte\DatanovaBundle\Parser\JsonParser; |
6
|
|
|
|
7
|
|
|
class JsonParserTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testParseJsonFixture() |
10
|
|
|
{ |
11
|
|
|
$dataset = 'laposte_hexasmal'; |
12
|
|
|
$path = dirname(__FILE__) . '/Fixtures/laposte_hexasmal.json'; |
13
|
|
|
$finder = $this->getFinderMock($dataset, $path); |
14
|
|
|
|
15
|
|
|
$jsonParser = new JsonParser($finder); |
|
|
|
|
16
|
|
|
$result = $jsonParser->parse($dataset); |
17
|
|
|
|
18
|
|
|
$this->assertNotFalse($result); |
19
|
|
|
$this->assertCount(15, $result); |
20
|
|
|
$this->assertArrayHasKey('code_commune_insee', $result[0]); |
21
|
|
|
$this->assertArrayHasKey('nom_de_la_commune', $result[0]); |
22
|
|
|
$this->assertArrayHasKey('code_postal', $result[0]); |
23
|
|
|
$this->assertArrayHasKey('libell_d_acheminement', $result[0]); |
24
|
|
|
$this->assertEquals('57077', $result[0]['code_commune_insee']); |
25
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['nom_de_la_commune']); |
26
|
|
|
$this->assertEquals('57630', $result[0]['code_postal']); |
27
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['libell_d_acheminement']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $dataset |
32
|
|
|
* @param string $path |
33
|
|
|
* |
34
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Laposte\DatanovaBundle\Service\Finder |
35
|
|
|
*/ |
36
|
|
|
private function getFinderMock($dataset, $path) |
37
|
|
|
{ |
38
|
|
|
$finder = $this->getMockBuilder('Laposte\DatanovaBundle\Service\Finder') |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
$finder->expects($this->once()) |
43
|
|
|
->method('findDataset') |
44
|
|
|
->with($dataset, JsonParser::FORMAT) |
45
|
|
|
->willReturn($path); |
46
|
|
|
$finder->expects($this->once()) |
47
|
|
|
->method('getContent') |
48
|
|
|
->with($path) |
49
|
|
|
->willReturn(file_get_contents($path)); |
50
|
|
|
|
51
|
|
|
return $finder; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
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.