Completed
Push — master ( d2e735...e0ca75 )
by
unknown
06:42 queued 10s
created

tests/Filter/StringFilterTest.php (8 issues)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\AdminBundle\Form\Type\Filter\ChoiceType;
17
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
18
use Sonata\DoctrineMongoDBAdminBundle\Filter\Filter;
19
use Sonata\DoctrineMongoDBAdminBundle\Filter\StringFilter;
20
21
class StringFilterTest extends FilterWithQueryBuilderTest
22
{
23
    public function testEmpty(): void
24
    {
25
        $filter = new StringFilter();
26
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
27
28
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
29
30
        $filter->filter($builder, 'alias', 'field', null);
31
        $filter->filter($builder, 'alias', 'field', '');
32
33
        $this->assertFalse($filter->isActive());
34
    }
35
36
    public function testContains(): void
37
    {
38
        $filter = new StringFilter();
39
        $filter->initialize('field_name', ['format' => '%s']);
40
41
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
42
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
43
44
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
45
46
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => null]);
47
        $this->assertTrue($filter->isActive());
48
    }
49
50
    public function testNotContains(): void
51
    {
52
        $filter = new StringFilter();
53
        $filter->initialize('field_name', ['format' => '%s']);
54
55
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
56
57
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_NOT_CONTAINS]);
58
        $this->assertTrue($filter->isActive());
59
    }
60
61
    public function testEquals(): void
62
    {
63
        $filter = new StringFilter();
64
        $filter->initialize('field_name', ['format' => '%s']);
65
66
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
67
68
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_EQUAL]);
69
        $this->assertTrue($filter->isActive());
70
    }
71
72
    public function testEqualsWithValidParentAssociationMappings(): void
73
    {
74
        $filter = new StringFilter();
75
        $filter->initialize('field_name', [
76
            'format' => '%s',
77
            'field_name' => 'field_name',
78
            'parent_association_mappings' => [
79
                [
80
                    'fieldName' => 'association_mapping',
81
                ],
82
                [
83
                    'fieldName' => 'sub_association_mapping',
84
                ],
85
                [
86
                    'fieldName' => 'sub_sub_association_mapping',
87
                ],
88
            ],
89
        ]);
90
91
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
92
93
        $filter->apply($builder, ['type' => ChoiceType::TYPE_EQUAL, 'value' => 'asd']);
94
        $this->assertTrue($filter->isActive());
95
    }
96
97
    public function testOr(): void
98
    {
99
        $filter = new StringFilter();
100
        $filter->initialize('field_name', ['format' => '%s']);
101
        $filter->setCondition(Filter::CONDITION_OR);
102
103
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
104
        $builder->getQueryBuilder()->expects($this->once())->method('addOr');
105
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
106
        $this->assertTrue($filter->isActive());
107
108
        $filter->setCondition(Filter::CONDITION_AND);
109
110
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
$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...
111
        $builder->getQueryBuilder()->expects($this->never())->method('addOr');
112
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ChoiceType::TYPE_CONTAINS]);
113
        $this->assertTrue($filter->isActive());
114
    }
115
}
116