Completed
Push — master ( de9ece...1b5216 )
by Gabriel
05:03
created

EventPageTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 30.34 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 27
loc 89
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerateContentRaces() 0 4 1
A testGenerateContentResultHeader() 0 4 1
A testGenerateContentResultList() 0 19 1
A testGenerateContentResultPagination() 0 11 1
A testGenerateContentAll() 0 4 1
B setUpBeforeClass() 27 27 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Sportic\Timing\RaceTecClient\Tests\Parsers;
4
5
use PHPUnit\Framework\TestCase;
6
use Sportic\Timing\RaceTecClient\Models\Result;
7
use Sportic\Timing\RaceTecClient\Scrapers\EventPage as EventPageScraper;
8
use Sportic\Timing\RaceTecClient\Parsers\EventPage as EventPageParser;
9
use Symfony\Component\DomCrawler\Crawler;
10
11
/**
12
 * Class EventPageTest
13
 * @package Sportic\Timing\RaceTecClient\Tests\Scrapers
14
 */
15
class EventPageTest extends TestCase
16
{
17
    protected static $parameters;
18
19
    /**
20
     * @var EventPageParser
21
     */
22
    protected static $parser;
23
24
    /**
25
     * @var array
26
     */
27
    protected static $parametersParsed;
28
29
    public function testGenerateContentRaces()
30
    {
31
        self::assertCount(5, self::$parametersParsed['races']);
32
    }
33
34
    public function testGenerateContentResultHeader()
35
    {
36
        self::assertCount(8, self::$parametersParsed['results']['header']);
37
    }
38
39
    public function testGenerateContentResultList()
40
    {
41
        self::assertCount(50, self::$parametersParsed['results']['list']);
42
        self::assertInstanceOf(Result::class, self::$parametersParsed['results']['list'][5]);
43
        self::assertEquals(
44
            [
45
                'posGen'      => '6',
46
                'bib'         => '247',
47
                'fullName'    => 'Sorin Boriceanu',
48
                'href'        => 'MyResults.aspx?uid=16648-2091-1-29984',
49
                'time'        => '02:04:16',
50
                'category'    => 'Masculin 35-39',
51
                'posCategory' => '3',
52
                'gender'      => 'Male',
53
                'posGender'   => '6',
54
            ],
55
            self::$parametersParsed['results']['list'][5]->__toArray()
56
        );
57
    }
58
59
    public function testGenerateContentResultPagination()
60
    {
61
        self::assertEquals(
62
            [
63
                'current' => 1,
64
                'all'     => 5,
65
                'items'   => 222,
66
            ],
67
            self::$parametersParsed['results']['pagination']
68
        );
69
    }
70
71
    public function testGenerateContentAll()
72
    {
73
        self::assertEquals(self::$parameters, self::$parametersParsed);
74
    }
75
76 View Code Duplication
    public static function setUpBeforeClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        self::$parameters = unserialize(
79
            file_get_contents(TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.serialized')
80
        );
81
82
        $scrapper = new EventPageScraper('16648', '2091', '1');
83
84
        $crawler = new Crawler(null, $scrapper->getCrawlerUri());
85
        $crawler->addContent(
86
            file_get_contents(
87
                TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.html'
88
            ),
89
            'text/html;charset=utf-8'
90
        );
91
92
        self::$parser = new EventPageParser();
93
        self::$parser->setScraper($scrapper);
94
        self::$parser->setCrawler($crawler);
95
96
        self::$parametersParsed = self::$parser->getContent();
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$parser->getContent() of type * is incompatible with the declared type array of property $parametersParsed.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
98
//        file_put_contents(
99
//            TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.serialized',
100
//            serialize(self::$parametersParsed)
101
//        );
102
    }
103
}
104