Completed
Push — master ( 4ae855...8f18c8 )
by
unknown
06:32 queued 11s
created

StringFilterTest::getMongoRegexClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Doctrine\ODM\MongoDB\Query\Builder;
17
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
18
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
19
use Sonata\DoctrineMongoDBAdminBundle\Filter\Filter;
20
use Sonata\DoctrineMongoDBAdminBundle\Filter\StringFilter;
21
22
class StringFilterTest extends FilterWithQueryBuilderTest
23
{
24
    public function testEmpty(): void
25
    {
26
        $filter = new StringFilter();
27
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
28
29
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
31
        $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...
32
            ->expects($this->never())
33
            ->method('field')
34
        ;
35
36
        $filter->filter($builder, 'alias', 'field', null);
37
        $filter->filter($builder, 'alias', 'field', '');
38
39
        $this->assertFalse($filter->isActive());
40
    }
41
42
    public function testContains(): void
43
    {
44
        $filter = new StringFilter();
45
        $filter->initialize('field_name', ['format' => '%s']);
46
47
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
49
        $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...
50
            ->expects($this->exactly(2))
51
            ->method('equals')
52
            ->with($this->isInstanceOf($this->getMongoRegexClass()))
53
        ;
54
55
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', ...iceType::TYPE_CONTAINS) is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => null]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', 'type' => null) is of type array<string,string|null...string","type":"null"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        $this->assertTrue($filter->isActive());
58
    }
59
60
    public function testNotContains(): void
61
    {
62
        $filter = new StringFilter();
63
        $filter->initialize('field_name', ['format' => '%s']);
64
65
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
67
        $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...
68
            ->expects($this->once())
69
            ->method('not')
70
            ->with($this->isInstanceOf($this->getMongoRegexClass()))
71
        ;
72
73
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_NOT_CONTAINS]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', ...ype::TYPE_NOT_CONTAINS) is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
        $this->assertTrue($filter->isActive());
75
    }
76
77
    public function testEquals(): void
78
    {
79
        $filter = new StringFilter();
80
        $filter->initialize('field_name', ['format' => '%s']);
81
82
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
84
        $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...
85
            ->expects($this->once())
86
            ->method('equals')
87
            ->with('asd')
88
        ;
89
90
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_EQUAL]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', ...ChoiceType::TYPE_EQUAL) is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
        $this->assertTrue($filter->isActive());
92
    }
93
94
    public function testEqualsWithValidParentAssociationMappings(): void
95
    {
96
        $filter = new StringFilter();
97
        $filter->initialize('field_name', [
98
            'format' => '%s',
99
            'field_name' => 'field_name',
100
            'parent_association_mappings' => [
101
                [
102
                    'fieldName' => 'association_mapping',
103
                ],
104
                [
105
                    'fieldName' => 'sub_association_mapping',
106
                ],
107
                [
108
                    'fieldName' => 'sub_sub_association_mapping',
109
                ],
110
            ],
111
        ]);
112
113
        $queryBuilder = $this->createMock(Builder::class);
114
115
        $builder = new ProxyQuery($queryBuilder);
0 ignored issues
show
Documentation introduced by
$queryBuilder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
117
        $builder->getQueryBuilder()
0 ignored issues
show
Bug introduced by
The method method() 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...
118
            ->method('field')
119
            ->with('field_name')
120
            ->willReturnSelf()
121
        ;
122
123
        $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...
124
            ->expects($this->once())
125
            ->method('equals')
126
            ->with('asd')
127
        ;
128
129
        $filter->apply($builder, ['type' => ChoiceType::TYPE_EQUAL, 'value' => 'asd']);
130
        $this->assertTrue($filter->isActive());
131
    }
132
133
    public function testOr(): void
134
    {
135
        $filter = new StringFilter();
136
        $filter->initialize('field_name', ['format' => '%s']);
137
        $filter->setCondition(Filter::CONDITION_OR);
138
139
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
        $builder->getQueryBuilder()->expects($this->once())->method('addOr');
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...
141
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', ...iceType::TYPE_CONTAINS) is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
        $this->assertTrue($filter->isActive());
143
144
        $filter->setCondition(Filter::CONDITION_AND);
145
146
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
        $builder->getQueryBuilder()->expects($this->never())->method('addOr');
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...
148
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
0 ignored issues
show
Documentation introduced by
array('value' => 'asd', ...iceType::TYPE_CONTAINS) is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
149
        $this->assertTrue($filter->isActive());
150
    }
151
152
    private function getMongoRegexClass()
153
    {
154
        return \MongoRegex::class;
155
    }
156
}
157