EntryArraysTest::testProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 30
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 40
rs 9.44
1
<?php
2
3
namespace FilteredTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_input\Filtered;
8
use kalanis\kw_input\Interfaces;
9
10
11
class EntryArraysTest extends CommonTestClass
12
{
13
    public function testProcess(): void
14
    {
15
        $variables = new Filtered\EntryArrays([
16
            ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'foo', 'val1'),
17
            ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'bar', ['bal1', 'bal2']),
18
            ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'baz', true),
19
            ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'aff', 42),
20
            ExEntry::init(Interfaces\IEntry::SOURCE_EXTERNAL, 'uhb', 'feaht'),
21
        ]);
22
23
        /** @var Interfaces\IEntry[] $entries */
24
        $entries = $variables->getInArray(null, [Interfaces\IEntry::SOURCE_GET]);
25
        $input = new Filtered\FilterAdapter($variables, [Interfaces\IEntry::SOURCE_GET]);
26
        $this->assertNotEmpty(iterator_to_array($input->getIterator()));
27
        $this->assertNotEmpty(count($entries));
28
29
        $this->assertTrue(isset($entries['foo']));
30
        $this->assertEquals('foo', $entries['foo']->getKey());
31
        $this->assertEquals('val1', $entries['foo']->getValue());
32
        $this->assertEquals(Interfaces\IEntry::SOURCE_GET, $entries['foo']->getSource());
33
34
        $this->assertTrue($input->offsetExists('bar'));
35
        $this->assertEquals('bar', $input->offsetGet('bar')->getKey());
36
        $this->assertEquals(['bal1', 'bal2'], $input->offsetGet('bar')->getValue());
37
        $this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->offsetGet('bar')->getSource());
38
39
        $this->assertTrue(isset($input->baz));
0 ignored issues
show
Bug Best Practice introduced by
The property baz does not exist on kalanis\kw_input\Filtered\FilterAdapter. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
        $this->assertEquals('baz', $input->baz->getKey());
0 ignored issues
show
Bug introduced by
The method getKey() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $this->assertEquals('baz', $input->baz->/** @scrutinizer ignore-call */ getKey());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $this->assertEquals(true, $input->baz->getValue());
42
        $this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->baz->getSource());
43
44
        $this->assertTrue($input->offsetExists('aff'));
45
        $this->assertEquals('aff', $input->offsetGet('aff')->getKey());
46
        $this->assertEquals(42, $input->offsetGet('aff')->getValue());
47
        $this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->offsetGet('aff')->getSource());
48
49
        $this->assertFalse($input->offsetExists('uhb'));
50
        $input->offsetSet('uhb', 'feaht');
51
        $this->assertEquals('feaht', $input->offsetGet('uhb')->getValue());
52
        $this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $input->offsetGet('uhb')->getSource());
53
    }
54
}
55