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

tests/Filter/FilterTest.php (1 issue)

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 PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
18
use Sonata\DoctrineMongoDBAdminBundle\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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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(
70
            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
71
            ? 'Symfony\Component\Form\Extension\Core\Type\TextType'
72
            : 'text',
73
            $filter->getFieldType()
74
        );
75
        $this->assertSame(['class' => 'FooBar'], $filter->getFieldOptions());
76
    }
77
78
    public function testValues(): void
79
    {
80
        $filter = new FilterTest_Filter();
81
        $this->assertEmpty($filter->getValue());
82
83
        $filter->setValue(42);
84
        $this->assertSame(42, $filter->getValue());
85
    }
86
87
    public function testExceptionOnEmptyFieldName(): void
88
    {
89
        $this->expectException(\RuntimeException::class);
90
91
        $filter = new FilterTest_Filter();
92
        $filter->getFieldName();
93
    }
94
95
    public function testIsActive(): void
96
    {
97
        $filter = new FilterTest_Filter();
98
        $this->assertFalse($filter->isActive());
99
    }
100
}
101