Completed
Push — master ( 511693...0349ad )
by Dispositif
04:19
created

OuvrageCompleteTest::provideComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 40
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 81
rs 9.28

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
 * This file is part of dispositif/wikibot application
4
 * 2019 : Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the LICENSE file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\Tests;
11
12
use App\Domain\Models\Wiki\OuvrageClean;
13
use App\Domain\Models\Wiki\OuvrageTemplate;
14
use App\Domain\OuvrageComplete;
15
use Exception;
16
use PHPUnit\Framework\TestCase;
17
18
class OuvrageCompleteTest extends TestCase
19
{
20
    public function testGetResult()
21
    {
22
        $origin = new OuvrageTemplate();
23
        $origin->hydrateFromText(
24
            '{{Ouvrage |id =Bonneton|nom1=Collectif | titre = Loiret : un département à l\'élégance naturelle | éditeur = Christine Bonneton | lieu = Paris | année = 2 septembre 1998 | isbn = 978-2-86253-234-9| pages totales = 319 }}'
25
        );
26
27
        $google = new OuvrageTemplate();
28
        $google->hydrateFromText(
29
            '{{ouvrage|langue=fr|auteur1=Clément Borgal|titre=Loiret|année=1998|pages totales=319|isbn=9782862532349}}'
30
        );
31
32
        $comp = new OuvrageComplete($origin, $google);
33
        $this::assertEquals(
34
            '{{Ouvrage |id=Bonneton |nom1=Collectif |titre=Loiret : un département à l\'élégance naturelle |éditeur=Christine Bonneton |lieu=Paris |année=2 septembre 1998 |isbn=978-2-86253-234-9 |pages totales=319 |langue=fr}}',
35
            $comp->getResult()->serialize()
36
        );
37
    }
38
39
    /**
40
     * @dataProvider provideComplete
41
     *
42
     * @param string $originStr
43
     * @param string $onlineStr
44
     * @param string $expected
45
     *
46
     * @throws Exception
47
     */
48
    public function testComplete(string $originStr, string $onlineStr, string $expected)
49
    {
50
        $origin = new OuvrageTemplate();
51
        $origin->hydrateFromText($originStr);
52
53
        $online = new OuvrageClean();
54
        $online->hydrateFromText($onlineStr);
55
56
        $comp = new OuvrageComplete($origin, $online);
57
        $this::assertEquals(
58
            $expected,
59
            $comp->getResult()->serialize(true)
60
        );
61
    }
62
63
    public function provideComplete()
64
    {
65
        return [
66
            [
67
                // Google partiel
68
                '{{Ouvrage|titre=}}',
69
                '{{Ouvrage|titre=|présentation en ligne=Google}}',
70
                '{{Ouvrage|titre=|éditeur=|année=|isbn=|présentation en ligne=Google}}',
71
            ],
72
            [
73
                // Google total
74
                '{{Ouvrage|titre=}}',
75
                '{{Ouvrage|titre=|lire en ligne=Google}}',
76
                '{{Ouvrage|titre=|éditeur=|année=|isbn=|lire en ligne=Google}}',
77
            ],
78
            [
79
                //isbn invalide
80
                '{{Ouvrage|titre=}}',
81
                '{{Ouvrage|titre=|isbn invalide=bla}}',
82
                '{{Ouvrage|titre=|éditeur=|année=|isbn=}}',
83
            ],
84
            // date/année
85
            [
86
                '{{Ouvrage|titre=}}',
87
                '{{Ouvrage|titre=|année=2009}}',
88
                '{{Ouvrage|titre=|éditeur=|année=2009|isbn=}}',
89
            ],
90
            [
91
                '{{Ouvrage|titre=|date=2011}}',
92
                '{{Ouvrage|titre=|année=2009}}',
93
                '{{Ouvrage|titre=|éditeur=|date=2011|isbn=}}',
94
            ],
95
            /**
96
             * titre + sous-titre
97
             */
98
            // pas d'ajout si déjà titre volume/chapitre/tome ou nature ouvrage
99
            [
100
                '{{Ouvrage|titre = Loiret Joli|titre chapitre=Bla}}',
101
                '{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}',
102
                '{{Ouvrage|titre=Loiret Joli|éditeur=|année=|isbn=|titre chapitre=Bla}}',
103
            ],
104
            // titres identiques mais sous-titre manquant
105
            [
106
                '{{Ouvrage|titre = Loiret Joli}}',
107
                '{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}',
108
                '{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}',
109
            ],
110
            // punctuation titre différente, sous-titre manquant
111
            [
112
                '{{Ouvrage|titre = Loiret Joli !!!!}}',
113
                '{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}',
114
                '{{Ouvrage|titre=Loiret Joli !!!!|sous-titre=un département|éditeur=|année=|isbn=}}',
115
            ],
116
            // sous-titre inclus dans titre original
117
            [
118
                '{{Ouvrage|titre = Loiret Joli : un département}}',
119
                '{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}',
120
                '{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}',
121
            ],
122
            // sous-titre absent online
123
            [
124
                '{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}',
125
                '{{Ouvrage|titre = Loiret Joli}}',
126
                '{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}',
127
            ],
128
            // titre absent online
129
            [
130
                '{{Ouvrage|auteur1=bla|titre = Loiret Joli}}',
131
                '{{Ouvrage|auteur1=bla}}',
132
                '{{Ouvrage|auteur1=bla|titre=Loiret Joli|éditeur=|année=|isbn=}}',
133
            ],
134
            // titre volume existe -> skip
135
            [
136
                '{{Ouvrage|titre = Loiret Joli|titre volume=Bla}}',
137
                '{{Ouvrage|titre = Loiret Joli|sous-titre=Fubar}}',
138
                '{{Ouvrage|titre=Loiret Joli|titre volume=Bla|éditeur=|année=|isbn=}}',
139
            ],
140
            [
141
                '{{Ouvrage|titre = Loiret Joli|collection=Bla}}',
142
                '{{Ouvrage|titre = Loiret Joli|sous-titre=Fubar}}',
143
                '{{Ouvrage|titre=Loiret Joli|éditeur=|collection=Bla|année=|isbn=}}',
144
            ],
145
        ];
146
    }
147
}
148