Passed
Branch dev (1a31b5)
by Dispositif
03:03
created

WebMapperTest::provideMappingFromFile()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 58
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 79
rs 8.9163

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Domain\Publisher\Tests;
6
7
use App\Application\PublisherAction;
8
use App\Domain\Publisher\WebMapper;
9
use App\Infrastructure\Logger;
10
use Exception;
11
use PHPUnit\Framework\TestCase;
12
13
class WebMapperTest extends TestCase
14
{
15
16
    /**
17
     * @dataProvider provideMappingFromFile
18
     *
19
     * @param       $filename
20
     * @param array $expected
21
     *
22
     * @return void
23
     * @throws Exception
24
     */
25
    public function testMappingProcess($filename, array $expected): void
26
    {
27
        $html = file_get_contents($filename);
28
29
        $publiAction = new PublisherAction('bla');
30
        $htmlData = $publiAction->extractWebData($html);
31
        $mapper = new WebMapper(new Logger());
32
        $data = $mapper->process($htmlData);
33
        if (isset($data['consulté le'])) {
34
            $data['consulté le'] = '11-04-2020';// unit testing date...
35
        }
36
        $this::assertSame($expected, $data);
37
    }
38
39
    public function provideMappingFromFile()
40
    {
41
        return [
42
            [
43
                __DIR__.'/fixture_lemonde.html',
44
                [
45
                    'DATA-TYPE' => 'JSON-LD',
46
                    'DATA-ARTICLE' => true,
47
                    'périodique' => 'Le Monde',
48
                    'titre' => 'Coronavirus : la Californie placée à son tour en confinement',
49
                    'url' => 'https://www.lemonde.fr/planete/article/2020/03/20/coronavirus-la-californie-placee-en-confinement_6033754_3244.html',
50
                    'date' => '20-03-2020',
51
                ],
52
            ],
53
            [
54
                __DIR__.'/fixture_journalsOpenEdition.html',
55
                [
56
57
                    'DATA-TYPE' => 'Open Graph/Dublin Core',
58
                    'DATA-ARTICLE' => true,
59
                    'titre' => 'Alger',
60
                    'url' => 'http://journals.openedition.org/encyclopedieberbere/2434',
61
                    'consulté le' => '11-04-2020',
62
                    'date' => '01-07-1986',
63
                    'url-access' => 'limité',
64
                    'périodique' => 'Encyclopédie berbère',
65
                    'et al.' => 'oui',
66
                    'auteur1' => 'Camps, G.; Leglay, M.',
67
                    'numéro' => '4',
68
                    'page' => '447–472',
69
                    'éditeur' => 'Éditions Peeters',
70
                    'issn' => '1015-7344',
71
                    'isbn' => '2-85744-282-3',
72
                ],
73
            ],
74
            [
75
                __DIR__.'/fixture_pubmed.html',
76
                [
77
                    'DATA-TYPE' => 'Open Graph/Dublin Core',
78
                    'DATA-ARTICLE' => true,
79
                    'site' => 'PubMed Central (PMC)',
80
                    'titre' => 'The Diesel Exhaust in Miners Study: A Nested Case–Control Study of Lung Cancer and Diesel Exhaust',
81
                    'url' => 'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3369553/',
82
                    'consulté le' => '11-04-2020',
83
                    'date' => '06-06-2012',
84
                    'périodique' => 'JNCI Journal of the National Cancer Institute',
85
                    'et al.' => 'oui',
86
                    'auteur1' => 'Debra T. Silverman, Claudine M. Samanic',
87
                    'volume' => '104',
88
                    'numéro' => '11',
89
                    'page' => '855',
90
                    'doi' => '10.1093/jnci/djs034',
91
                    'pmid' => '22393209',
92
                ],
93
            ],
94
            [
95
                __DIR__.'/fixture_figaro.html',
96
                [
97
                    'DATA-TYPE' => 'JSON-LD',
98
                    'DATA-ARTICLE' => true,
99
                    'périodique' => 'Le Figaro',
100
                    'titre' => 'Face au Covid-19, les cliniques privées mobilisées… mais en manque de masques',
101
                    'url' => 'http://www.lefigaro.fr/sciences/face-au-covid-19-les-cliniques-privees-mobilisees-mais-en-manque-de-masques-20200318',
102
                    'date' => '18-03-2020',
103
                    'auteur1' => 'Marie-Cécile Renault',
104
                    'url-access' => 'limité',
105
                ],
106
            ],
107
            [
108
                __DIR__.'/fixture_liberation.html',
109
                [
110
                    'DATA-TYPE' => 'JSON-LD',
111
                    'DATA-ARTICLE' => true,
112
                    'périodique' => 'Libération',
113
                    'titre' => 'En Bretagne, le Parisiens-bashing guette',
114
                    'url' => 'https://www.liberation.fr/france/2020/03/20/en-bretagne-le-parisiens-bashing-guette_1782471',
115
                    'date' => '20-03-2020',
116
                    'auteur1' => 'Pierre-Henri Allain',
117
                    'url-access' => 'ouvert',
118
                ],
119
            ],
120
121
        ];
122
    }
123
124
}
125