DayTest::testGetDayIndex()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 27
rs 9.568
c 0
b 0
f 0
cc 3
nc 5
nop 0
1
<?php
2
3
namespace Tests\Geo6;
4
5
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidDayException;
6
use Bpost\BpostApiClient\Geo6\Day;
7
use Exception;
8
use PHPUnit_Framework_TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class DayTest extends PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * Tests Day::createFromXml()
14
     */
15
    public function testCreateFromXml()
16
    {
17
        $data = array(
18
            'AMOpen' => '9:00',
19
            'AMClose' => '12:00',
20
            'PMOpen' => '13:00',
21
            'PMClose' => '18:00',
22
        );
23
24
        // build xml
25
        $xmlString = '<Monday>';
26
        foreach ($data as $key => $value) {
27
            $xmlString .= '<' . $key . '>' . $value . '</' . $key . '>';
28
        }
29
        $xmlString .= '</Monday>';
30
        $xml = simplexml_load_string($xmlString);
31
32
        $day = Day::createFromXML($xml);
33
34
        $this->assertSame($data['AMOpen'], $day->getAmOpen());
35
        $this->assertSame($data['AMClose'], $day->getAmClose());
36
        $this->assertSame($data['PMOpen'], $day->getPmOpen());
37
        $this->assertSame($data['PMClose'], $day->getPmClose());
38
    }
39
40
    /**
41
     * Tests Day->getDayIndex()
42
     */
43
    public function testGetDayIndex()
44
    {
45
        $day = new Day();
46
        $day->setDay('Monday');
47
        $this->assertSame(1, $day->getDayIndex());
48
        $day->setDay('Tuesday');
49
        $this->assertSame(2, $day->getDayIndex());
50
        $day->setDay('Wednesday');
51
        $this->assertSame(3, $day->getDayIndex());
52
        $day->setDay('Thursday');
53
        $this->assertSame(4, $day->getDayIndex());
54
        $day->setDay('Friday');
55
        $this->assertSame(5, $day->getDayIndex());
56
        $day->setDay('Saturday');
57
        $this->assertSame(6, $day->getDayIndex());
58
        $day->setDay('Sunday');
59
        $this->assertSame(7, $day->getDayIndex());
60
61
        $day = new Day();
62
63
        try {
64
            $day->getDayIndex();
65
            $this->fail('BpostInvalidDayException not launched');
66
        } catch (BpostInvalidDayException $e) {
67
            // Nothing, the exception is good
68
        } catch (Exception $e) {
69
            $this->fail('BpostInvalidDayException not caught');
70
        }
71
    }
72
}
73