Passed
Push — master ( 62401f...daf94f )
by Alec
07:24
created

StringListBasicTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 101
rs 10
c 0
b 0
f 0
wmc 11
1
<?php
2
/**
3
 * User: alec
4
 * Date: 11.11.18
5
 * Time: 15:42
6
 */
7
8
namespace Tests\Unit\StringList;
9
10
use AlecRabbit\StringList\StringList;
11
use PHPUnit\Framework\TestCase;
12
13
class StringListBasicTest extends TestCase
14
{
15
    /** @var StringList */
16
    private $list;
17
18
    public function simpleDataProvider(): array
19
    {
20
        return [
21
//            [$including, $excluding, $hasElement, $expected]
22
            [['par', 'fix'], ['trend', 'fix'], 'fix', false],
23
            [['par', 'lot'], ['trend', 'fix'], 'trend', false],
24
            [['par', 'lot'], ['trend', 'fix'], 'lot', true],
25
            [['par', 'lot'], ['trend', 'fix'], 'par', true],
26
            [['par', 'lot'], ['trend', 'fix'], 'tor', false],
27
            [[], ['trend', 'fix'], 'tor', true],
28
            [[], ['trend', 'fix'], 'fix', false],
29
            [[], [], 'fix', true],
30
            [['par'], [], 'fix', false],
31
            [['fix'], ['fix'], 'fix', false],
32
        ];
33
    }
34
35
    /**
36
     * @test
37
     * @dataProvider simpleDataProvider
38
     * @param $including
39
     * @param $excluding
40
     * @param $hasElement
41
     * @param $expected
42
     */
43
    public function simple($including, $excluding, $hasElement, $expected): void
44
    {
45
        $this->list = new StringList($including, $excluding);
46
        $this->assertEquals($expected, $this->list->has($hasElement));
47
    }
48
49
    /**
50
     * @test
51
     * @dataProvider simpleDataProvider
52
     * @param $including
53
     * @param $excluding
54
     * @param $element
55
     * @param $expected
56
     */
57
    public function usingMethods($including, $excluding, $element, $expected): void
58
    {
59
        foreach ($including as $value) {
60
            $this->list->include($value);
61
        }
62
        foreach ($excluding as $value) {
63
            $this->list->exclude($value);
64
        }
65
        $this->assertEquals($expected, $this->list->has($element));
66
    }
67
68
    /**
69
     * @test
70
     * @dataProvider simpleDataProviderExcludeFirst
71
     * @param $including
72
     * @param $excluding
73
     * @param $element
74
     * @param $expected
75
     */
76
    public function usingMethodsExcludeFirst($including, $excluding, $element, $expected): void
77
    {
78
        foreach ($excluding as $value) {
79
            $this->list->exclude($value);
80
        }
81
        foreach ($including as $value) {
82
            $this->list->include($value);
83
        }
84
        $this->assertEquals($expected, $this->list->has($element));
85
    }
86
87
88
    public function simpleDataProviderExcludeFirst(): array
89
    {
90
        return [
91
//            [$including, $excluding, $hasElement, $expected]
92
            [['par', 'fix'], ['trend', 'fix'], 'fix', true],
93
            [['par', 'trend'], ['trend', 'fix'], 'trend', true],
94
            [['par', 'lot'], ['trend', 'fix'], 'lot', true],
95
            [['lot'], ['par', 'fix'], 'par', false],
96
            [['par', 'lot'], ['trend', 'lot'], 'tor', false],
97
            [[], ['trend', 'fix'], 'tor', true],
98
            [[], ['trend', 'fix'], 'fix', false],
99
            [[], [], 'fix', true],
100
            [['par'], ['fix'], 'fix', false],
101
            [['fix'], ['fix'], 'fix', true],
102
            [['fix'], [], 'fix', true],
103
        ];
104
    }
105
106
    protected function setUp()
107
    {
108
        $this->list = new StringList();
109
    }
110
111
    protected function tearDown()
112
    {
113
        unset($this->list);
114
    }
115
}
116
117