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(); |
14
|
|
|
$finder->expects($this->once()) |
|
|
|
|
15
|
|
|
->method('findDataset') |
16
|
|
|
->with($dataset, JsonParser::FORMAT) |
17
|
|
|
->willReturn($path); |
18
|
|
|
$finder->expects($this->once()) |
19
|
|
|
->method('getContent') |
20
|
|
|
->with($path) |
21
|
|
|
->willReturn(file_get_contents($path)); |
22
|
|
|
|
23
|
|
|
$jsonParser = new JsonParser($finder); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$result = $jsonParser->parse($dataset); |
26
|
|
|
$this->assertNotFalse($result); |
27
|
|
|
$this->assertCount(15, $result); |
28
|
|
|
|
29
|
|
|
$this->assertArrayHasKey('code_commune_insee', $result[0]); |
30
|
|
|
$this->assertArrayHasKey('nom_de_la_commune', $result[0]); |
31
|
|
|
$this->assertArrayHasKey('code_postal', $result[0]); |
32
|
|
|
$this->assertArrayHasKey('libell_d_acheminement', $result[0]); |
33
|
|
|
$this->assertEquals('57077', $result[0]['code_commune_insee']); |
34
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['nom_de_la_commune']); |
35
|
|
|
$this->assertEquals('57630', $result[0]['code_postal']); |
36
|
|
|
$this->assertEquals('BEZANGE LA PETITE', $result[0]['libell_d_acheminement']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Laposte\DatanovaBundle\Service\Finder |
41
|
|
|
*/ |
42
|
|
|
private function getFinderMock() |
43
|
|
|
{ |
44
|
|
|
return $this->getMockBuilder('Laposte\DatanovaBundle\Service\Finder') |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->getMock(); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
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: