Passed
Push — master ( 7abca6...282bb4 )
by Florian
01:26 queued 11s
created

CsvParserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 43
wmc 2
lcom 1
cbo 3
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseCsvFixture() 0 21 1
A getFinderMock() 0 12 1
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);
0 ignored issues
show
Bug introduced by
It seems like $finder defined by $this->getFinderMock($da.../laposte_hexasmal.csv') on line 12 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Fmaj\LaposteDatanovaBund...svParser::__construct() does only seem to accept object<Fmaj\LaposteDatanovaBundle\Service\Finder>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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