Passed
Push — master ( b2accd...5a4945 )
by WEBEWEB
01:50
created

SkiDataStartRecordFormatParserTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Disclaimer: This source code is protected by copyright law and by
5
 * international conventions.
6
 *
7
 * Any reproduction or partial or total distribution of the source code, by any
8
 * means whatsoever, is strictly forbidden.
9
 *
10
 * Anyone not complying with these provisions will be guilty of the offense of
11
 * infringement and the penal sanctions provided for by law.
12
 *
13
 * © 2017 All rights reserved.
14
 */
15
16
namespace WBW\Library\SkiData\Tests\Parser;
17
18
use DateTime;
19
use Exception;
20
use PHPUnit_Framework_TestCase;
21
use WBW\Library\SkiData\Entity\SkiDataStartRecordFormat;
22
use WBW\Library\SkiData\Exception\SkiDataTooLongDataException;
23
use WBW\Library\SkiData\Parser\SkiDataStartRecordFormatParser;
24
25
/**
26
 * SkiData start record format parser test.
27
 *
28
 * @author webeweb <https://github.com/webeweb/>
29
 * @package WBW\Library\SkiData\Tests\Parser
30
 * @final
31
 */
32
final class SkiDataStartRecordFormatParserTest extends PHPUnit_Framework_TestCase {
33
34
    /**
35
     * Tests teh __construct() method.
36
     *
37
     * @return void
38
     */
39
    public function testConstruct() {
40
41
        $obj = new SkiDataStartRecordFormatParser();
42
43
        $this->assertEquals(null, $obj->getStartRecordFormat());
44
45
        $res = new SkiDataStartRecordFormat();
46
        $obj->setStartRecordFormat($res);
47
        $this->assertEquals($res, $obj->getStartRecordFormat());
48
    }
49
50
    /**
51
     * Tests the parseEntity() method.
52
     *
53
     * @return void
54
     */
55
    public function testParseEntity() {
56
57
        $obj = new SkiDataStartRecordFormat();
58
        $obj->setVersionRecordStructure(190000);
59
        $obj->setFacilityNumber(202747);
60
        $obj->setDateFile(new DateTime("2017-09-21 16:10:00"));
61
        $obj->setNumberRecords(18);
62
        $obj->setCurrency("EUR");
63
64
        $res = '190000;0202747;20170921;00018;"EUR"';
65
        $this->assertEquals($res, (new SkiDataStartRecordFormatParser())->parseEntity($obj));
66
67
        try {
68
            $obj->setVersionRecordStructure(2000000);
69
            (new SkiDataStartRecordFormatParser())->parseEntity($obj);
70
        } catch (Exception $ex) {
71
72
            $this->assertInstanceOf(SkiDataTooLongDataException::class, $ex);
73
            $this->assertEquals("The data \"2000000\" exceeds the length \"6\" allowed", $ex->getMessage());
74
        }
75
76
        try {
77
            $obj->setVersionRecordStructure(190000);
78
            $obj->setCurrency("Exception");
79
            (new SkiDataStartRecordFormatParser())->parseEntity($obj);
80
        } catch (Exception $ex) {
81
82
            $this->assertInstanceOf(SkiDataTooLongDataException::class, $ex);
83
            $this->assertEquals("The data \"Exception\" exceeds the length \"6\" allowed", $ex->getMessage());
84
        }
85
    }
86
87
    /**
88
     * Tests the parseLine() method.
89
     *
90
     * @return void
91
     */
92
    public function testParseLine() {
93
94
        $res = '190000;0202747;20170921;00018;"EUR"';
95
96
        $obj = (new SkiDataStartRecordFormatParser())->parseLine($res);
97
        $this->assertEquals(190000, $obj->getVersionRecordStructure());
98
        $this->assertEquals(202747, $obj->getFacilityNumber());
99
        $this->assertEquals(new DateTime("2017-09-21 00:00:00"), $obj->getDateFile());
100
        $this->assertEquals(18, $obj->getNumberRecords());
101
        $this->assertEquals("EUR", $obj->getCurrency());
102
    }
103
104
}
105