Completed
Push — master ( 48a39d...7216ae )
by Chad
10s
created

ArraysTest::filterBasicPass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
use TraderInteractive\Exceptions\FilterException;
7
8
/**
9
 * @coversDefaultClass \TraderInteractive\Filter\Arrays
10
 */
11
final class ArraysTest extends TestCase
12
{
13
    /**
14
     * @test
15
     * @covers ::filter
16
     */
17
    public function filterBasicPass()
18
    {
19
        $this->assertSame(['boo'], Arrays::filter(['boo']));
20
    }
21
22
    /**
23
     * @test
24
     * @covers ::filter
25
     * @expectedException \TraderInteractive\Exceptions\FilterException
26
     * @expectedExceptionMessage Value '1' is not an array
27
     */
28
    public function filterFailNotArray()
29
    {
30
        Arrays::filter(1);
31
    }
32
33
    /**
34
     * @test
35
     * @covers ::filter
36
     * @expectedException \TraderInteractive\Exceptions\FilterException
37
     * @expectedExceptionMessage $value count of 0 is less than 1
38
     */
39
    public function filterFailEmpty()
40
    {
41
        Arrays::filter([]);
42
    }
43
44
    /**
45
     * @test
46
     * @covers ::filter
47
     * @expectedException \TraderInteractive\Exceptions\FilterException
48
     * @expectedExceptionMessage $value count of 1 is less than 2
49
     */
50
    public function filterCountLessThanMin()
51
    {
52
        Arrays::filter([0], 2);
53
    }
54
55
    /**
56
     * @test
57
     * @covers ::filter
58
     * @expectedException \TraderInteractive\Exceptions\FilterException
59
     * @expectedExceptionMessage $value count of 2 is greater than 1
60
     */
61
    public function filterCountGreaterThanMax()
62
    {
63
        Arrays::filter([0, 1], 1, 1);
64
    }
65
66
    /**
67
     * @test
68
     * @covers ::in
69
     */
70
    public function inPassStrict()
71
    {
72
        $this->assertSame('boo', Arrays::in('boo', ['boo']));
73
    }
74
75
    /**
76
     * @test
77
     * @covers ::in
78
     */
79
    public function inFailStrict()
80
    {
81
        try {
82
            Arrays::in('0', [0]);
83
            $this->fail();
84
        } catch (FilterException $e) {
85
            $this->assertSame("Value '0' is not in array array (\n  0 => 0,\n)", $e->getMessage());
86
        }
87
    }
88
89
    /**
90
     * @test
91
     * @covers ::in
92
     */
93
    public function inFailNotStrict()
94
    {
95
        try {
96
            Arrays::in('boo', ['foo'], false);
97
            $this->fail();
98
        } catch (FilterException $e) {
99
            $this->assertSame("Value 'boo' is not in array array (\n  0 => 'foo',\n)", $e->getMessage());
100
        }
101
    }
102
103
    /**
104
     * @test
105
     * @covers ::in
106
     */
107
    public function inPassNotStrict()
108
    {
109
        $this->assertSame('0', Arrays::in('0', [0], false));
110
    }
111
112
    /**
113
     * Verifies the basic behavior of the flatten filter.
114
     *
115
     * @test
116
     * @covers ::flatten
117
     */
118
    public function flatten()
119
    {
120
        $this->assertSame([1, 2, 3, 4, 5], Arrays::flatten([[1, 2], [[3, [4, 5]]]]));
121
    }
122
}
123