dataProviderTestParseSerialise()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 20
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.6
1
<?php
2
3
/**
4
 * This file is part of graze/unicontroller-client.
5
 *
6
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md
12
 * @link https://github.com/graze/unicontroller-client
13
 */
14
15
namespace Graze\UniControllerClient\Test\Integration;
16
17
use Graze\UnicontrollerClient\UnicontrollerClient;
18
use Graze\UnicontrollerClient\Entity\Entity\EntityInterface;
19
use Graze\UnicontrollerClient\Parser\ParserResolver;
20
21
class ParseSerialiseTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var UnicontrollerClient
25
     */
26
    private $unicontrollerClient;
27
28
    /**
29
     * @var ParserResolver
30
     */
31
    private $parserResolver;
32
33
    /**
34
     * @return UnicontrollerClient
35
     */
36
    private function getUnicontrollerClient()
37
    {
38
        if (!$this->unicontrollerClient) {
39
            $this->unicontrollerClient = UnicontrollerClient::factory();
40
        }
41
42
        return $this->unicontrollerClient;
43
    }
44
45
    /**
46
     * @return ParserResolver
47
     */
48
    private function getParserResolver()
49
    {
50
        if (!$this->parserResolver) {
51
            $this->parserResolver = new ParserResolver();
52
        }
53
54
        return $this->parserResolver;
55
    }
56
57
    /**
58
     * @dataProvider dataProviderTestParseSerialise
59
     * @param string $name
60
     */
61
    public function testParseSerialise($name)
62
    {
63
        $filePath = sprintf('%s/../integration/Fixture/Fixture%s', __DIR__, $name);
64
        $fixture = file_get_contents($filePath);
65
66
        $parserResolver = $this->getParserResolver();
67
        $parser = $parserResolver->resolve($name);
68
69
        $entity = $parser->parse($fixture);
70
        $this->assertInstanceOf(EntityInterface::class, $entity);
71
72
        $unicontrollerClient = $this->getUnicontrollerClient();
73
        $serialised = $unicontrollerClient->serialise($entity);
74
75
        $this->assertEquals($fixture, $serialised);
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function dataProviderTestParseSerialise()
82
    {
83
        return [
84
            ['BarcodeItem'],
85
            ['BoxItem'],
86
            ['LineItem'],
87
            ['PictureItem'],
88
            ['ReadDesign'],
89
            ['SettingsById'],
90
            ['ShiftDefinition'],
91
            ['TtfItem'],
92
            ['VarDatabase'],
93
            ['VarDatabaseField'],
94
            ['VarMachineId'],
95
            ['VarMacro'],
96
            ['VarMacroOutput'],
97
            ['VarPrompt'],
98
            ['VarRtc'],
99
            ['VarSeq'],
100
            ['VarSerial'],
101
            ['VarShiftCode'],
102
            ['VarUserId'],
103
        ];
104
    }
105
}
106