Passed
Push — main ( 36bb88...fbfcc4 )
by Alexandra
03:15
created

CombinationsTest::testGetAllCombinations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AHJ\ApprovalTests\Tests\Unit;
6
7
use AHJ\ApprovalTests\Combinations;
8
use Generator;
9
use PHPUnit\Framework\Assert;
10
use PHPUnit\Framework\TestCase;
11
12
final class CombinationsTest extends TestCase
13
{
14
    /**
15
     * @dataProvider provideTestInput
16
     */
17
    public function testGetAllCombinations(array $arguments, array $expected): void
18
    {
19
        $actual = (new Combinations())->getAllCombinations($arguments, []);
20
21
        Assert::assertEquals($expected, $actual);
22
    }
23
24
    public function provideTestInput(): Generator
25
    {
26
        yield 'for name foo and bar' => [
27
            'arguments' => [
28
                'name' => ['foo', 'bar'],
29
                'sellIn' => [3],
30
                'quantity' => [15],
31
            ],
32
            'expected' => [
33
                ['bar', 3, 15],
34
                ['foo', 3, 15],
35
            ],
36
        ];
37
38
        yield 'for sellIn 1 and 3' => [
39
            'arguments' => [
40
                ['foo', 'bar'],
41
                [1, 3],
42
                [15],
43
            ],
44
            'expected' => [
45
                ['bar', 3, 15],
46
                ['bar', 1, 15],
47
                ['foo', 3, 15],
48
                ['foo', 1, 15],
49
            ],
50
        ];
51
52
        yield 'for two lists' => [
53
            'arguments' => [
54
                ['foo', 'bar'],
55
                [1, 3],
56
            ],
57
            'expected' => [
58
                ['bar', 3],
59
                ['bar', 1],
60
                ['foo', 3],
61
                ['foo', 1],
62
            ],
63
        ];
64
65
        yield 'for four flat lists' => [
66
            'arguments' => [
67
                ['foo', 'bar'],
68
                [1, 3],
69
                [0, 1],
70
                [4, 5],
71
            ],
72
            'expected' => [
73
                ['bar', 3, 1, 5],
74
                ['bar', 3, 1, 4],
75
                ['bar', 3, 0, 5],
76
                ['bar', 3, 0, 4],
77
                ['bar', 1, 1, 5],
78
                ['bar', 1, 1, 4],
79
                ['bar', 1, 0, 5],
80
                ['bar', 1, 0, 4],
81
                ['foo', 3, 1, 5],
82
                ['foo', 3, 1, 4],
83
                ['foo', 3, 0, 5],
84
                ['foo', 3, 0, 4],
85
                ['foo', 1, 1, 5],
86
                ['foo', 1, 1, 4],
87
                ['foo', 1, 0, 5],
88
                ['foo', 1, 0, 4],
89
            ],
90
        ];
91
92
        yield 'lots of values' => [
93
            'arguments' => [
94
                ['foo', 'bar', 'awesome'],
95
                [1, 3, 5],
96
                [15, 50, 100, 101],
97
            ],
98
            'expected' => [
99
                ['awesome', 5, 101],
100
                ['awesome', 5, 100],
101
                ['awesome', 5, 50],
102
                ['awesome', 5, 15],
103
                ['awesome', 3, 101],
104
                ['awesome', 3, 100],
105
                ['awesome', 3, 50],
106
                ['awesome', 3, 15],
107
                ['awesome', 1, 101],
108
                ['awesome', 1, 100],
109
                ['awesome', 1, 50],
110
                ['awesome', 1, 15],
111
                ['bar', 5, 101],
112
                ['bar', 5, 100],
113
                ['bar', 5, 50],
114
                ['bar', 5, 15],
115
                ['bar', 3, 101],
116
                ['bar', 3, 100],
117
                ['bar', 3, 50],
118
                ['bar', 3, 15],
119
                ['bar', 1, 101],
120
                ['bar', 1, 100],
121
                ['bar', 1, 50],
122
                ['bar', 1, 15],
123
                ['foo', 5, 101],
124
                ['foo', 5, 100],
125
                ['foo', 5, 50],
126
                ['foo', 5, 15],
127
                ['foo', 3, 101],
128
                ['foo', 3, 100],
129
                ['foo', 3, 50],
130
                ['foo', 3, 15],
131
                ['foo', 1, 101],
132
                ['foo', 1, 100],
133
                ['foo', 1, 50],
134
                ['foo', 1, 15],
135
            ],
136
        ];
137
    }
138
}
139