Passed
Pull Request — master (#50)
by Marco
02:46
created

ArrayHelpersTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 76
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidStringArrays() 0 9 1
B stringArrayContainsStringValidValues() 0 37 1
A testInclusion() 0 3 1
A testRejectsArraysWithNonStringValues() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\Support;
6
7
use PHPStan\Testing\TestCase;
8
use Roave\BackwardCompatibility\Support\ArrayHelpers;
9
use stdClass;
10
11
/**
12
 * @covers \Roave\BackwardCompatibility\Support\ArrayHelpers
13
 */
14
final class ArrayHelpersTest extends TestCase
15
{
16
    /**
17
     * @dataProvider stringArrayContainsStringValidValues
18
     *
19
     * @param string[] $array
20
     */
21
    public function testInclusion(string $value, array $array, bool $expected) : void
22
    {
23
        self::assertSame($expected, ArrayHelpers::stringArrayContainsString($value, $array));
24
    }
25
26
    /** @return (string|string[]|bool)[][] */
27
    public function stringArrayContainsStringValidValues() : array
28
    {
29
        return [
30
            [
31
                '',
32
                [],
33
                false,
34
            ],
35
            [
36
                '',
37
                [''],
38
                true,
39
            ],
40
            [
41
                '0',
42
                [''],
43
                false,
44
            ],
45
            [
46
                '',
47
                ['0'],
48
                false,
49
            ],
50
            [
51
                'foo',
52
                ['foo', 'bar', 'baz'],
53
                true,
54
            ],
55
            [
56
                'foo',
57
                ['bar', 'baz'],
58
                false,
59
            ],
60
            [
61
                'foo',
62
                ['foo', 'foo', 'foo'],
63
                true,
64
            ],
65
        ];
66
    }
67
68
    /**
69
     * @dataProvider invalidStringArrays
70
     *
71
     * @param mixed[] $array
72
     */
73
    public function testRejectsArraysWithNonStringValues(array $array) : void
74
    {
75
        $this->expectException(\InvalidArgumentException::class);
76
77
        ArrayHelpers::stringArrayContainsString('', $array);
78
    }
79
80
    /** @return mixed[][] */
81
    public function invalidStringArrays() : array
82
    {
83
        return [
84
            [[null]],
85
            [[true]],
86
            [[123]],
87
            [[123.45]],
88
            [[[]]],
89
            [[new stdClass()]],
90
        ];
91
    }
92
}
93