JsonTest::testJsonCrash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace FilteredTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_input\Filtered;
8
use kalanis\kw_input\InputException;
9
use kalanis\kw_input\Interfaces;
10
11
12
class JsonTest extends CommonTestClass
13
{
14
    /**
15
     * @throws InputException
16
     */
17
    public function testJson(): void
18
    {
19
        $variables = new Filtered\Json($this->jsonDataset());
20
21
        /** @var Interfaces\IEntry[] $entries */
22
        $entries = $variables->getInArray(); // sources have no meaning here
23
        $this->assertNotEmpty(count($entries));
24
25
        $entries = $variables->getInArray(); // sources have no meaning here
26
        $entry = reset($entries);
27
        $this->assertEquals(Interfaces\IEntry::SOURCE_JSON, $entry->getSource());
28
        $this->assertEquals('foo', $entry->getKey());
29
        $this->assertEquals('bar', $entry->getValue());
30
31
        $entry = next($entries);
32
        $this->assertEquals(Interfaces\IEntry::SOURCE_JSON, $entry->getSource());
33
        $this->assertEquals('baz', $entry->getKey());
34
        $this->assertEquals(['rfv' => 123, 'edc'=> 456], $entry->getValue());
35
36
        $entry = next($entries);
37
        $this->assertEquals(Interfaces\IEntry::SOURCE_JSON, $entry->getSource());
38
        $this->assertEquals('sbr', $entry->getKey());
39
        $this->assertEquals(['cde', 'dgs'], $entry->getValue());
40
    }
41
42
    /**
43
     * @throws InputException
44
     */
45
    public function testJsonCrash(): void
46
    {
47
        $this->expectException(InputException::class);
48
        new Filtered\Json('not a Json string\0{');
49
    }
50
}
51