Test Setup Failed
Push — master ( b97929...aafad9 )
by Gabriel
02:07
created

ResultPageTest::getSerializedFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sportic\Timing\RaceTecClient\Tests\Parsers;
4
5
use Sportic\Timing\RaceTecClient\Models\Split;
6
use Sportic\Timing\RaceTecClient\Scrapers\ResultPage as PageScraper;
7
use Sportic\Timing\RaceTecClient\Parsers\ResultPage as PageParser;
8
9
/**
10
 * Class ResultPageTest
11
 * @package Sportic\Timing\RaceTecClient\Tests\Scrapers
12
 */
13
class ResultPageTest extends AbstractPageTest
14
{
15
16
    public function testGenerateResultsBox()
17
    {
18
        self::assertSame('Marius-Alexandru Dragu', self::$parametersParsed['full_name']);
19
20
        self::assertSame('02:12:11.38', self::$parametersParsed['time']);
21
        self::assertSame('10', self::$parametersParsed['pos_gen']);
22
        self::assertSame('211', self::$parametersParsed['race']['participants']);
23
24
        self::assertSame('10', self::$parametersParsed['pos_gender']);
25
        self::assertSame('194', self::$parametersParsed['gender']['participants']);
26
27
        self::assertSame('1', self::$parametersParsed['pos_category']);
28
        self::assertSame('28', self::$parametersParsed['category']['participants']);
29
30
        self::assertSame('188', self::$parametersParsed['bib']);
31
        self::assertSame('male', self::$parametersParsed['gender']['name']);
32
        self::assertSame('Masculin 45-49', self::$parametersParsed['category']['name']);
33
        self::assertSame('Finished', self::$parametersParsed['status']['name']);
34
    }
35
36
    public function testSplits()
37
    {
38
        /** @var Split[] $splits */
39
        $splits = self::$parametersParsed['splits'];
40
        self::assertEquals(12, count($splits));
41
42
        self::assertInstanceOf(Split::class, $splits[0]);
43
        self::assertSame('Swim', $splits[0]->getName());
44
        self::assertSame('00:17:21.53', $splits[0]->getTime());
45
46
        self::assertInstanceOf(Split::class, $splits[8]);
47
        self::assertSame('Ciclism 7', $splits[8]->getName());
48
        self::assertSame('01:17:11.19', $splits[8]->getTimeFromStart());
49
        self::assertSame('00:08:50.52', $splits[8]->getTime());
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    protected static function getNewScraper()
56
    {
57
        return new PageScraper('16648-2091-1-29925');
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    protected static function getNewParser()
64
    {
65
        return new PageParser();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Sportic\Timi...t\Parsers\ResultPage(); (Sportic\Timing\RaceTecClient\Parsers\ResultPage) is incompatible with the return type declared by the abstract method Sportic\Timing\RaceTecCl...tPageTest::getNewParser of type Sportic\Timing\RaceTecCl...crapers\AbstractScraper.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    protected static function getSerializedFile()
72
    {
73
        return 'result_page.serialized';
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    protected static function getHtmlFile()
80
    {
81
        return 'result_page.html';
82
    }
83
}
84