Completed
Push — master ( bae860...fc1986 )
by Grégoire
11s
created

tests/Filter/CallbackFilterTest.php (6 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\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
17
use Sonata\DoctrineMongoDBAdminBundle\Filter\CallbackFilter;
18
19
class CallbackFilterTest extends FilterWithQueryBuilderTest
20
{
21
    public function testFilterClosureEmpty(): void
22
    {
23
        $builder = new ProxyQuery($this->getQueryBuilder());
24
25
        $filter = new CallbackFilter();
26
        $filter->initialize('field_name', [
27
            'callback' => function ($builder, $alias, $field, $value) {
28
                return true;
29
            },
30
        ]);
31
32
        $filter->filter($builder, 'alias', 'field', false);
0 ignored issues
show
false is of type boolean, 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...
33
        $filter->filter($builder, 'alias', 'field', 'scalarValue');
34
        $filter->filter($builder, 'alias', 'field', ['value' => '']);
0 ignored issues
show
array('value' => '') 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...
35
36
        $this->assertFalse($filter->isActive());
37
    }
38
39
    public function testFilterClosureNotEmpty(): void
40
    {
41
        $builder = new ProxyQuery($this->getQueryBuilder());
42
43
        $filter = new CallbackFilter();
44
        $filter->initialize('field_name', [
45
            'callback' => function ($builder, $alias, $field, $value) {
46
                return true;
47
            },
48
        ]);
49
50
        $filter->filter($builder, 'alias', 'field', ['value' => 'myValue']);
0 ignored issues
show
array('value' => 'myValue') 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...
51
52
        $this->assertTrue($filter->isActive());
53
    }
54
55
    public function testFilterMethodEmpty(): void
56
    {
57
        $builder = new ProxyQuery($this->getQueryBuilder());
58
59
        $filter = new CallbackFilter();
60
        $filter->initialize('field_name', [
61
            'callback' => [$this, 'customCallback'],
62
        ]);
63
64
        $filter->filter($builder, 'alias', 'field', false);
0 ignored issues
show
false is of type boolean, 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...
65
        $filter->filter($builder, 'alias', 'field', 'scalarValue');
66
        $filter->filter($builder, 'alias', 'field', ['value' => '']);
0 ignored issues
show
array('value' => '') 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...
67
68
        $this->assertFalse($filter->isActive());
69
    }
70
71
    public function testFilterMethodNotEmpty(): void
72
    {
73
        $builder = new ProxyQuery($this->getQueryBuilder());
74
75
        $filter = new CallbackFilter();
76
        $filter->initialize('field_name', [
77
            'callback' => [$this, 'customCallback'],
78
        ]);
79
80
        $filter->filter($builder, 'alias', 'field', ['value' => 'myValue']);
0 ignored issues
show
array('value' => 'myValue') 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...
81
82
        $this->assertTrue($filter->isActive());
83
    }
84
85
    public function customCallback($builder, $alias, $field, $value)
86
    {
87
        return true;
88
    }
89
90
    public function testFilterException(): void
91
    {
92
        $this->expectException(\RuntimeException::class);
93
94
        $builder = new ProxyQuery($this->getQueryBuilder());
95
96
        $filter = new CallbackFilter();
97
        $filter->initialize('field_name', []);
98
99
        $filter->filter($builder, 'alias', 'field', 'myValue');
100
    }
101
}
102