Completed
Push — master ( 670f0c...07e238 )
by Pavel
12:30
created

testIteratesNestedConfigurators()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Unit;
4
5
use Doctrine\Common\Collections\Criteria;
6
use Prophecy\Argument;
7
use ScayTrase\Api\Cruds\Criteria\NestedCriteriaConfigurator;
8
use ScayTrase\Api\Cruds\CriteriaConfiguratorInterface;
9
10
class NestedCriteriaConfiguratorTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testIteratesNestedConfigurators()
13
    {
14
        $criteria = [
15
            'criteria1' => 'data1',
16
            'criteria2' => ['data2'],
17
            'criteria3' => null,
18
        ];
19
20
        $fqcn    = \stdClass::class;
21
        $crit    = Criteria::create();
22
        $filters = [];
23
        foreach ($criteria as $key => $value) {
24
            $filters[$key] = $this->createConfigurator($fqcn, $crit, $value);
25
        }
26
27
        $nested = new NestedCriteriaConfigurator($filters);
28
        $nested->configure($fqcn, $crit, $criteria);
29
30
    }
31
32
    /**
33
     * @expectedException \ScayTrase\Api\Cruds\Exception\NestedConfiguratorException
34
     */
35 View Code Duplication
    public function testExceptionThrownOnUnknownNesting()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $criteria = [
38
            'criteria1' => 'data1',
39
        ];
40
41
        $fqcn    = \stdClass::class;
42
        $crit    = Criteria::create();
43
        $filters = [];
44
        foreach ($criteria as $key => $value) {
45
            $filters[$key] = $this->createConfigurator($fqcn, $crit, $value, true);
46
        }
47
48
        $criteria['criteria2'] = 'data2';
49
50
        $nested = new NestedCriteriaConfigurator($filters);
51
        $nested->configure($fqcn, $crit, $criteria);
52
    }
53
54
    /**
55
     * @expectedException \ScayTrase\Api\Cruds\Exception\NestedConfiguratorException
56
     */
57 View Code Duplication
    public function testExceptionThrownInvalidDataSupplied()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $criteria = [
60
            'criteria1' => 'data1',
61
        ];
62
63
        $fqcn    = \stdClass::class;
64
        $crit    = Criteria::create();
65
        $filters = [];
66
        foreach ($criteria as $key => $value) {
67
            $filters[$key] = $this->createConfigurator($fqcn, $crit, $value, true);
68
        }
69
70
        $criteria = 'data2';
71
72
        $nested = new NestedCriteriaConfigurator($filters);
73
        $nested->configure($fqcn, $crit, $criteria);
74
    }
75
76
77
    /**
78
     *
79
     */
80
    public function testUnknownException()
81
    {
82
83
    }
84
85
    private function createConfigurator($fqcn, Criteria $criteria, $data, $e = false)
86
    {
87
        $mock   = self::prophesize(CriteriaConfiguratorInterface::class);
88
        $method = $mock->configure(Argument::exact($fqcn), Argument::exact($criteria), Argument::exact($data));
89
90
        if (!$e) {
91
            $method->shouldBeCalled();
92
        }
93
94
        return $mock->reveal();
95
    }
96
}
97