Passed
Pull Request — master (#1312)
by Michael
08:36 queued 02:22
created

YamlTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 47
c 2
b 0
f 0
dl 0
loc 100
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testDumpAndLoadWrappedStress() 0 11 1
A testSaveAndRead() 0 14 1
A tearDown() 0 2 1
A setUp() 0 2 1
A testDumpAndLoadWrapped() 0 11 1
A testDumpAndLoadWrappedStress2() 0 11 1
A testSaveAndReadWrapped() 0 14 1
A testDumpAndLoad() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xmf\Test;
6
7
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...
8
9
use Xmf\Yaml;
10
11
class YamlTest extends TestCase
12
{
13
    /**
14
     * Sets up the fixture, for example, opens a network connection.
15
     * This method is called before a test is executed.
16
     */
17
    protected function setUp(): void
18
    {
19
    }
20
21
    /**
22
     * Tears down the fixture, for example, closes a network connection.
23
     * This method is called after a test is executed.
24
     */
25
    protected function tearDown(): void
26
    {
27
    }
28
29
    public function testDumpAndLoad()
30
    {
31
        $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => ''];
32
33
        $string = Yaml::dump($inputArray);
34
        $this->assertNotEmpty($string);
35
        $this->assertIsString($string);
36
37
        $outputArray = Yaml::load((string)$string);
38
        $this->assertIsArray($outputArray);
39
        $this->assertSame($inputArray, $outputArray);
40
    }
41
42
    public function testSaveAndRead()
43
    {
44
        $tmpfname   = tempnam(sys_get_temp_dir(), 'TEST');
45
        $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => ''];
46
47
        $byteCount = Yaml::save($inputArray, $tmpfname);
48
        $this->assertNotSame(false, $byteCount);
49
        $this->assertGreaterThan(0, $byteCount);
50
51
        $outputArray = Yaml::read($tmpfname);
52
        $this->assertIsArray($outputArray);
53
        $this->assertSame($inputArray, $outputArray);
54
55
        unlink($tmpfname);
56
    }
57
58
    public function testDumpAndLoadWrapped()
59
    {
60
        $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => ''];
61
62
        $string = Yaml::dumpWrapped($inputArray);
63
        $this->assertNotEmpty($string);
64
        $this->assertIsString($string);
65
66
        $outputArray = Yaml::loadWrapped((string)$string);
67
        $this->assertIsArray($outputArray);
68
        $this->assertSame($inputArray, $outputArray);
69
    }
70
71
    public function testDumpAndLoadWrappedStress()
72
    {
73
        $inputArray = ['start' => '---', 'end' => '...', 'misc' => 'stuff'];
74
75
        $string = Yaml::dumpWrapped($inputArray);
76
        $this->assertNotEmpty($string);
77
        $this->assertIsString($string);
78
79
        $outputArray = Yaml::loadWrapped((string)$string);
80
        $this->assertIsArray($outputArray);
81
        $this->assertSame($inputArray, $outputArray);
82
    }
83
84
    public function testDumpAndLoadWrappedStress2()
85
    {
86
        $inputArray = ['start' => '---', 'end' => '...', 'misc' => 'stuff'];
87
88
        $string = Yaml::dump($inputArray);
89
        $this->assertNotEmpty($string);
90
        $this->assertIsString($string);
91
92
        $outputArray = Yaml::loadWrapped((string)$string);
93
        $this->assertIsArray($outputArray);
94
        $this->assertSame($inputArray, $outputArray);
95
    }
96
97
    public function testSaveAndReadWrapped()
98
    {
99
        $tmpfname   = tempnam(sys_get_temp_dir(), 'TEST');
100
        $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => ''];
101
102
        $byteCount = Yaml::saveWrapped($inputArray, $tmpfname);
103
        $this->assertNotSame(false, $byteCount);
104
        $this->assertGreaterThan(0, $byteCount);
105
106
        $outputArray = Yaml::readWrapped($tmpfname);
107
        $this->assertIsArray($outputArray);
108
        $this->assertSame($inputArray, $outputArray);
109
110
        unlink($tmpfname);
111
    }
112
}
113