Completed
Push — master ( d9ba05...3b34d3 )
by Bukashk0zzz
14:04
created

FilterTest::testValueOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the FilterBundle
4
 *
5
 * (c) Denis Golubovskiy <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Bukashk0zzz\FilterBundle\Tests\Annotation;
12
13
use Bukashk0zzz\FilterBundle\Annotation\FilterAnnotation;
14
use PHPUnit\Framework\TestCase;
15
use Zend\Filter\StringTrim;
16
17
/**
18
 * FilterAnnotationTest
19
 */
20
class FilterTest extends TestCase
21
{
22
    /**
23
     * Test annotation with `value` option
24
     */
25
    public function testValueOption(): void
26
    {
27
        $annotation = new FilterAnnotation(['value' => 'StringTrim']);
28
29
        static::assertEquals(StringTrim::class, $annotation->getFilter());
30
        static::assertEmpty($annotation->getOptions());
31
    }
32
33
    /**
34
     * Test annotation with all options
35
     */
36
    public function testAllOptions(): void
37
    {
38
        $annotation = new FilterAnnotation([
39
            'filter' => 'StringTrim',
40
            'options' => ['charlist' => 'test'],
41
        ]);
42
43
        static::assertEquals(StringTrim::class, $annotation->getFilter());
44
        static::assertEquals(['charlist' => 'test'], $annotation->getOptions());
45
    }
46
47
    /**
48
     * Test annotation without any option
49
     *
50
     * @expectedException \LogicException
51
     */
52
    public function testAnnotationWithoutOptions(): void
53
    {
54
        new FilterAnnotation([]);
55
    }
56
57
    /**
58
     * Test annotation with wrong type for `filter` option
59
     *
60
     * @expectedException \InvalidArgumentException
61
     */
62
    public function testWrongTypeForFilterOption(): void
63
    {
64
        new FilterAnnotation(['filter' => 123]);
65
    }
66
67
    /**
68
     * Test annotation with wrong zend filter class for `filter` option
69
     *
70
     * @expectedException \InvalidArgumentException
71
     */
72
    public function testWrongFilterClassForFilterOption(): void
73
    {
74
        new FilterAnnotation(['filter' => 'test']);
75
    }
76
77
    /**
78
     * Test annotation with wrong type for `value` option
79
     *
80
     * @expectedException \InvalidArgumentException
81
     */
82
    public function testWrongTypeForValueOption(): void
83
    {
84
        new FilterAnnotation(['value' => 123]);
85
    }
86
87
    /**
88
     * Test annotation with wrong type for `options` option
89
     *
90
     * @expectedException \TypeError
91
     */
92
    public function testWrongTypeForOptionsOption(): void
93
    {
94
        new FilterAnnotation(['filter' => 'StringTrim', 'options' => 123]);
95
    }
96
}
97