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

NumberFilterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilterEmpty() 0 12 1
A testFilterInvalidOperator() 0 11 1
A testFilter() 0 16 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\AdminBundle\Form\Type\Filter\NumberType;
17
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
18
use Sonata\DoctrineMongoDBAdminBundle\Filter\NumberFilter;
19
20
class NumberFilterTest extends FilterWithQueryBuilderTest
21
{
22
    public function testFilterEmpty(): void
23
    {
24
        $filter = new NumberFilter();
25
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
26
27
        $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...
28
29
        $filter->filter($builder, 'alias', 'field', null);
30
        $filter->filter($builder, 'alias', 'field', 'asds');
31
32
        $this->assertFalse($filter->isActive());
33
    }
34
35
    public function testFilterInvalidOperator(): void
36
    {
37
        $filter = new NumberFilter();
38
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
39
40
        $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...
41
42
        $filter->filter($builder, 'alias', 'field', ['type' => 'foo']);
0 ignored issues
show
Documentation introduced by
array('type' => 'foo') is of type array<string,string,{"type":"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...
43
44
        $this->assertFalse($filter->isActive());
45
    }
46
47
    public function testFilter(): void
48
    {
49
        $filter = new NumberFilter();
50
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
51
52
        $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...
53
54
        $filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_EQUAL, 'value' => 42]);
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...E_EQUAL, 'value' => 42) is of type array<string,integer,{"value":"integer"}>, 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...
55
        $filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_GREATER_EQUAL, 'value' => 42]);
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...R_EQUAL, 'value' => 42) is of type array<string,integer,{"value":"integer"}>, 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', ['type' => NumberType::TYPE_GREATER_THAN, 'value' => 42]);
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...ER_THAN, 'value' => 42) is of type array<string,integer,{"value":"integer"}>, 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
        $filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_LESS_EQUAL, 'value' => 42]);
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...S_EQUAL, 'value' => 42) is of type array<string,integer,{"value":"integer"}>, 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...
58
        $filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_LESS_THAN, 'value' => 42]);
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...SS_THAN, 'value' => 42) is of type array<string,integer,{"value":"integer"}>, 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...
59
        $filter->filter($builder, 'alias', 'field', ['value' => 42]);
0 ignored issues
show
Documentation introduced by
array('value' => 42) is of type array<string,integer,{"value":"integer"}>, 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...
60
61
        $this->assertTrue($filter->isActive());
62
    }
63
}
64