SimpleArrayTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 34 1
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 SimpleArrayTest extends CommonTestClass
12
{
13
    public function testProcess(): void
14
    {
15
        $variables = new Filtered\SimpleFromArrays([
16
            'foo' => 'val1',
17
            'bar' => ['bal1', 'bal2'],
18
            'baz' => true,
19
            'aff' => 42,
20
        ], Interfaces\IEntry::SOURCE_POST);
21
22
        /** @var Interfaces\IEntry[] $entries */
23
        $entries = $variables->getInArray(null, [Interfaces\IEntry::SOURCE_GET]); // sources have no meaning here
24
        $input = new Filtered\FilterAdapter($variables, [Interfaces\IEntry::SOURCE_GET]);
25
        $this->assertNotEmpty(iterator_to_array($input->getIterator()));
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_POST, $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_POST, $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_POST, $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_POST, $input->offsetGet('aff')->getSource());
47
    }
48
}
49