BooleanFilterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 79
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilterEmpty() 0 22 1
A testFilterNo() 0 17 1
A testFilterYes() 0 17 1
A testFilterArray() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Filter;
15
16
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
17
use Sonata\DoctrineMongoDBAdminBundle\Filter\BooleanFilter;
18
use Sonata\Form\Type\BooleanType;
19
20
class BooleanFilterTest extends FilterWithQueryBuilderTest
21
{
22
    public function testFilterEmpty(): void
23
    {
24
        $filter = new BooleanFilter();
25
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
26
27
        $builder = new ProxyQuery($this->getQueryBuilder());
28
29
        $builder->getQueryBuilder()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Builder>.

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
            ->expects($this->never())
31
            ->method('field')
32
        ;
33
34
        $filter->filter($builder, 'alias', 'field', null);
35
        $filter->filter($builder, 'alias', 'field', '');
36
        $filter->filter($builder, 'alias', 'field', 'test');
37
        $filter->filter($builder, 'alias', 'field', false);
38
39
        $filter->filter($builder, 'alias', 'field', []);
40
        $filter->filter($builder, 'alias', 'field', [null, 'test']);
41
42
        $this->assertFalse($filter->isActive());
43
    }
44
45
    public function testFilterNo(): void
46
    {
47
        $filter = new BooleanFilter();
48
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
49
50
        $builder = new ProxyQuery($this->getQueryBuilder());
51
52
        $builder->getQueryBuilder()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Builder>.

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...
53
            ->expects($this->once())
54
            ->method('equals')
55
            ->with(false)
56
        ;
57
58
        $filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => BooleanType::TYPE_NO]);
59
60
        $this->assertTrue($filter->isActive());
61
    }
62
63
    public function testFilterYes(): void
64
    {
65
        $filter = new BooleanFilter();
66
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
67
68
        $builder = new ProxyQuery($this->getQueryBuilder());
69
70
        $builder->getQueryBuilder()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Builder>.

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...
71
            ->expects($this->once())
72
            ->method('equals')
73
            ->with(true)
74
        ;
75
76
        $filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => BooleanType::TYPE_YES]);
77
78
        $this->assertTrue($filter->isActive());
79
    }
80
81
    public function testFilterArray(): void
82
    {
83
        $filter = new BooleanFilter();
84
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
85
86
        $builder = new ProxyQuery($this->getQueryBuilder());
87
88
        $builder->getQueryBuilder()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Builder>.

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...
89
            ->expects($this->once())
90
            ->method('in')
91
            ->with([false])
92
        ;
93
94
        $filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => [BooleanType::TYPE_NO]]);
95
96
        $this->assertTrue($filter->isActive());
97
    }
98
}
99