These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\Tests\AdminList; |
||
4 | |||
5 | use Kunstmaan\AdminListBundle\AdminList\FilterBuilder; |
||
6 | use Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL\StringFilterType; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use Symfony\Component\HttpFoundation\Request; |
||
9 | use Symfony\Component\HttpFoundation\Session\Session; |
||
10 | |||
11 | class FilterBuilderTest extends TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var FilterBuilder |
||
15 | */ |
||
16 | protected $object; |
||
17 | |||
18 | /** |
||
19 | * Sets up the fixture, for example, opens a network connection. |
||
20 | * This method is called before a test is executed. |
||
21 | */ |
||
22 | protected function setUp() |
||
23 | { |
||
24 | $this->object = new FilterBuilder(); |
||
25 | } |
||
26 | |||
27 | public function testAdd() |
||
28 | { |
||
29 | $result = $this->object->add('columnName', new StringFilterType('string', 'e'), 'filterName', array('option1' => 'value1')); |
||
30 | |||
31 | $this->assertInstanceOf('Kunstmaan\AdminListBundle\AdminList\FilterBuilder', $result); |
||
32 | } |
||
33 | |||
34 | public function testGet() |
||
35 | { |
||
36 | $this->object->add('columnName', new StringFilterType('string', 'e'), 'filterName', array('option1' => 'value1')); |
||
37 | $definition = $this->object->get('columnName'); |
||
38 | |||
39 | $this->assertArrayHasKey('type', $definition); |
||
40 | $this->assertArrayHasKey('filtername', $definition); |
||
41 | $this->assertArrayHasKey('options', $definition); |
||
42 | $this->assertInstanceOf('Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL\StringFilterType', $definition['type']); |
||
43 | $this->assertEquals('filterName', $definition['filtername']); |
||
44 | $this->assertEquals(array('option1' => 'value1'), $definition['options']); |
||
45 | $this->assertTrue(is_array($this->object->getCurrentParameters())); |
||
46 | $this->assertTrue(is_array($this->object->getCurrentFilters())); |
||
47 | } |
||
48 | |||
49 | public function testRemove() |
||
50 | { |
||
51 | $this->object->add('columnName', new StringFilterType('string', 'e'), 'filterName', array('option1' => 'value1')); |
||
52 | $definition = $this->object->get('columnName'); |
||
53 | $this->assertNotNull($definition); |
||
54 | |||
55 | $this->object->remove('columnName'); |
||
56 | $definition = $this->object->get('columnName'); |
||
57 | $this->assertNull($definition); |
||
58 | } |
||
59 | |||
60 | public function testHas() |
||
61 | { |
||
62 | $this->assertFalse($this->object->has('columnName')); |
||
63 | $this->object->add('columnName', new StringFilterType('string', 'e'), 'filterName', array('option1' => 'value1')); |
||
64 | $this->assertTrue($this->object->has('columnName')); |
||
65 | } |
||
66 | |||
67 | public function testGetFilterDefinitions() |
||
68 | { |
||
69 | $filter = new StringFilterType('string', 'e'); |
||
70 | $filterDef = array('columnName' => array('type' => $filter, 'options' => array('option1' => 'value1'), 'filtername' => 'filterName')); |
||
71 | $this->object->add('columnName', $filter, 'filterName', array('option1' => 'value1')); |
||
72 | |||
73 | $this->assertEquals($filterDef, $this->object->getFilterDefinitions()); |
||
74 | } |
||
75 | |||
76 | public function testBindRequest() |
||
77 | { |
||
78 | $session = $this->createMock(Session::class); |
||
79 | $session->expects($this->any())->method('has')->willReturn(true); |
||
80 | $session->expects($this->any())->method('get')->willReturn(['filter_columnname' => ['something' => 'columnName']]); |
||
81 | $request = new Request(); |
||
82 | $request->setSession($session); |
||
0 ignored issues
–
show
|
|||
83 | |||
84 | $filter = new StringFilterType('string', 'e'); |
||
85 | $filterDef = array('columnName' => array('type' => $filter, 'options' => array('option1' => 'value1'), 'filtername' => 'filterName')); |
||
86 | $this->object->add('columnName', $filter, 'filterName', array('option1' => 'value1')); |
||
87 | |||
88 | $this->object->bindRequest($request); |
||
89 | |||
90 | $this->assertEquals($filterDef, $this->object->getFilterDefinitions()); |
||
91 | } |
||
92 | } |
||
93 |
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: