testUnknownException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Unit;
4
5
use Doctrine\Common\Collections\Criteria;
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use ScayTrase\Api\Cruds\Criteria\NestedCriteriaConfigurator;
9
use ScayTrase\Api\Cruds\CriteriaConfiguratorInterface;
10
11
final class NestedCriteriaConfiguratorTest extends TestCase
12
{
13
    public function testIteratesNestedConfigurators()
14
    {
15
        $criteria = [
16
            'criteria1' => 'data1',
17
            'criteria2' => ['data2'],
18
            'criteria3' => null,
19
        ];
20
21
        $fqcn    = \stdClass::class;
22
        $crit    = Criteria::create();
23
        $filters = [];
24
        foreach ($criteria as $key => $value) {
25
            $filters[$key] = $this->createConfigurator($fqcn, $crit, $value);
26
        }
27
28
        $nested = new NestedCriteriaConfigurator($filters);
29
        $nested->configure($fqcn, $crit, $criteria);
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
    public function testUnknownException()
80
    {
81
        $this->markTestIncomplete();
82
    }
83
84
    public function testNestedExceptionRethrow()
85
    {
86
        $this->markTestIncomplete();
87
    }
88
89
    private function createConfigurator($fqcn, Criteria $criteria, $data, $e = false): CriteriaConfiguratorInterface
90
    {
91
        $mock   = self::prophesize(CriteriaConfiguratorInterface::class);
92
        $method = $mock->configure(Argument::exact($fqcn), Argument::exact($criteria), Argument::exact($data));
93
94
        if (!$e) {
95
            $method->shouldBeCalled();
96
        }
97
98
        return $mock->reveal();
99
    }
100
}
101