FilterTest_Filter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 4 1
A getDefaultOptions() 0 4 1
A getRenderSettings() 0 7 1
A testAssociation() 0 4 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\DoctrineORMAdminBundle\Tests\Filter;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
18
use Sonata\DoctrineORMAdminBundle\Filter\Filter;
19
20
class FilterTest_Filter extends Filter
21
{
22
    /**
23
     * Apply the filter to the QueryBuilder instance.
24
     *
25
     * @param $queryBuilder
26
     * @param string $alias
27
     * @param string $field
28
     * @param string $value
29
     */
30
    public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $value): void
31
    {
32
        // TODO: Implement filter() method.
33
    }
34
35
    public function getDefaultOptions()
36
    {
37
        return ['option1' => 2];
38
    }
39
40
    public function getRenderSettings()
41
    {
42
        return ['sonata_type_filter_default', [
43
            'type' => $this->getFieldType(),
44
            'options' => $this->getFieldOptions(),
45
        ]];
46
    }
47
48
    public function testAssociation(ProxyQueryInterface $queryBuilder, $value)
49
    {
50
        return $this->association($queryBuilder, $value);
51
    }
52
}
53
54
class FilterTest extends TestCase
55
{
56
    public function testFieldDescription(): void
57
    {
58
        $filter = new FilterTest_Filter();
59
        $this->assertSame(['option1' => 2], $filter->getDefaultOptions());
60
        $this->assertNull($filter->getOption('1'));
61
62
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
63
64
        $this->assertSame(2, $filter->getOption('option1'));
65
        $this->assertNull($filter->getOption('foo'));
66
        $this->assertSame('bar', $filter->getOption('foo', 'bar'));
67
68
        $this->assertSame('field_name', $filter->getName());
69
        $this->assertSame(['class' => 'FooBar'], $filter->getFieldOptions());
70
    }
71
72
    public function testValues(): void
73
    {
74
        $filter = new FilterTest_Filter();
75
        $this->assertEmpty($filter->getValue());
76
77
        $filter->setValue(42);
78
        $this->assertSame(42, $filter->getValue());
79
    }
80
81
    public function testExceptionOnEmptyFieldName(): void
82
    {
83
        $this->expectException(\RuntimeException::class);
84
85
        $filter = new FilterTest_Filter();
86
        $filter->getFieldName();
87
    }
88
89
    public function testIsActive(): void
90
    {
91
        $filter = new FilterTest_Filter();
92
        $this->assertFalse($filter->isActive());
93
    }
94
}
95