Completed
Push — upgrade-boilerplate ( 903b21 )
by Kamil
17:46
created

EntityFilterSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_a_filter_interface() 0 4 1
A it_gets_type() 0 4 1
A it_filters_by_id() 0 11 1
A it_does_not_filters_when_data_is_not_defined() 0 11 1
A it_does_not_filters_when_id_is_not_defined() 0 11 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Component\Grid\Filter;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Component\Grid\Data\DataSourceInterface;
17
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
18
use Sylius\Component\Grid\Filter\EntityFilter;
19
use Sylius\Component\Grid\Filtering\FilterInterface;
20
21
/**
22
 * @author Grzegorz Sadowski <[email protected]>
23
 */
24
final class EntityFilterSpec extends ObjectBehavior
25
{
26
    function it_is_initializable()
27
    {
28
        $this->shouldHaveType(EntityFilter::class);
29
    }
30
31
    function it_implements_a_filter_interface()
32
    {
33
        $this->shouldImplement(FilterInterface::class);
34
    }
35
36
    function it_gets_type()
37
    {
38
        $this->getType()->shouldReturn('entity');
39
    }
40
41
    function it_filters_by_id(
42
        DataSourceInterface $dataSource,
43
        ExpressionBuilderInterface $expressionBuilder
44
    ) {
45
        $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
46
47
        $expressionBuilder->equals('entity', '7')->willReturn('EXPR');
48
        $dataSource->restrict('EXPR')->shouldBeCalled();
49
50
        $this->apply($dataSource, 'entity', ['id' => '7'], []);
51
    }
52
53
    function it_does_not_filters_when_data_is_not_defined(
54
        DataSourceInterface $dataSource,
55
        ExpressionBuilderInterface $expressionBuilder
56
    ) {
57
        $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
58
59
        $expressionBuilder->equals('entity', Argument::any())->shouldNotBeCalled();
60
        $dataSource->restrict(Argument::any())->shouldNotBeCalled();
61
62
        $this->apply($dataSource, 'entity', [], []);
63
    }
64
65
    function it_does_not_filters_when_id_is_not_defined(
66
        DataSourceInterface $dataSource,
67
        ExpressionBuilderInterface $expressionBuilder
68
    ) {
69
        $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
70
71
        $expressionBuilder->equals('entity', Argument::any())->shouldNotBeCalled();
72
        $dataSource->restrict(Argument::any())->shouldNotBeCalled();
73
74
        $this->apply($dataSource, 'entity', ['id' => ''], []);
75
    }
76
}
77