Completed
Push — master ( 298f36...c6c82d )
by Mihail
06:19 queued 10s
created

XmlSerializerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 24
c 2
b 0
f 1
dl 0
loc 55
rs 10
wmc 7
1
<?php
2
3
namespace Koded\Stdlib\Serializer;
4
5
use Koded\Stdlib\Interfaces\Serializer;
6
use PHPUnit\Framework\TestCase;
7
8
class XmlSerializerTest extends TestCase
9
{
10
11
    const XML_FILE = __DIR__ . '/../fixtures/error-message.xml';
12
    const PHP_FILE = __DIR__ . '/../fixtures/error-message.php';
13
14
    /** @var XmlSerializer */
15
    private $SUT;
16
17
    public function test_serialize()
18
    {
19
        $xml = $this->SUT->serialize(require self::PHP_FILE);
20
        $this->assertXmlStringEqualsXmlFile(self::XML_FILE, $xml);
21
    }
22
23
    public function test_unserialize()
24
    {
25
        $array = $this->SUT->unserialize(file_get_contents(self::XML_FILE));
26
        $this->assertEquals(require self::PHP_FILE, $array);
27
    }
28
29
    public function test_unserialize_error_should_return_empty_array()
30
    {
31
        $this->assertSame([], $this->SUT->unserialize(''));
32
    }
33
34
    public function test_frankenstein_array()
35
    {
36
        $array = require __DIR__ . '/../fixtures/nested-array.php';
37
        $this->SUT->serialize($array);
38
        $this->assertEquals(require __DIR__ . '/../fixtures/nested-array.php', $array);
39
    }
40
41
    public function test_non_utf8_file_should_fail_to_serialize()
42
    {
43
        $xml = $this->SUT->serialize(require __DIR__ . '/../fixtures/non-utf8-file.php');
44
        $this->assertEquals(<<<XML
45
<?xml version="1.0" encoding="UTF-8"?>
46
<payload>
47
  <diva><![CDATA[]]></diva>
48
</payload>
49
50
XML
51
            , $xml);
52
    }
53
54
    public function testName()
55
    {
56
        $this->assertSame(Serializer::XML, $this->SUT->type());
57
    }
58
59
    protected function setUp(): void
60
    {
61
        $this->markTestSkipped();
62
        $this->SUT = new XmlSerializer('payload');
63
    }
64
}
65