ArrayAccessedTest::testProcessing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 33
rs 9.52
1
<?php
2
3
namespace FilteredTests;
4
5
6
use ArrayObject;
7
use CommonTestClass;
8
use kalanis\kw_input\Filtered;
9
use kalanis\kw_input\Interfaces;
10
11
12
class ArrayAccessedTest extends CommonTestClass
13
{
14
    public function testProcessing(): void
15
    {
16
        $variables = new Filtered\ArrayAccessed(new ArrayObject([
17
            'foo' => 'val1',
18
            'bar' => ['bal1', 'bal2'],
19
            'baz' => true,
20
            'aff' => 42,
21
        ]), Interfaces\IEntry::SOURCE_CLI);
22
23
        /** @var Interfaces\IEntry[] $entries */
24
        $entries = $variables->getInArray(null, [Interfaces\IEntry::SOURCE_GET]); // sources have no meaning here
25
        $input = new Filtered\FilterAdapter($variables, [Interfaces\IEntry::SOURCE_GET]);
26
        $this->assertNotEmpty(count($entries));
27
28
        $this->assertTrue(isset($input['foo']));
29
        $this->assertEquals('foo', $input['foo']->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

29
        $this->assertEquals('foo', $input['foo']->/** @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...
30
        $this->assertEquals('val1', $input['foo']->getValue());
31
        $this->assertEquals(Interfaces\IEntry::SOURCE_CLI, $input['foo']->getSource());
32
33
        $this->assertTrue($input->offsetExists('bar'));
34
        $this->assertEquals('bar', $input->offsetGet('bar')->getKey());
35
        $this->assertEquals(['bal1', 'bal2'], $input->offsetGet('bar')->getValue());
36
        $this->assertEquals(Interfaces\IEntry::SOURCE_CLI, $input->offsetGet('bar')->getSource());
37
38
        $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...
39
        $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

39
        $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...
40
        $this->assertEquals(true, $input->baz->getValue());
41
        $this->assertEquals(Interfaces\IEntry::SOURCE_CLI, $input->baz->getSource());
42
43
        $this->assertTrue($input->offsetExists('aff'));
44
        $this->assertEquals('aff', $input->offsetGet('aff')->getKey());
45
        $this->assertEquals(42, $input->offsetGet('aff')->getValue());
46
        $this->assertEquals(Interfaces\IEntry::SOURCE_CLI, $input->offsetGet('aff')->getSource());
47
    }
48
}
49