FilterTest::testAllOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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