|
15 | 15 |
|
16 | 16 | use CodeIgniter\Test\CIUnitTestCase; |
17 | 17 | use InvalidArgumentException; |
| 18 | +use PHPUnit\Framework\Attributes\DataProvider; |
18 | 19 | use PHPUnit\Framework\Attributes\Group; |
19 | 20 |
|
20 | 21 | /** |
@@ -82,24 +83,42 @@ public function testReduceDoubleSlashes(): void |
82 | 83 | } |
83 | 84 | } |
84 | 85 |
|
85 | | - public function testReduceMultiples(): void |
| 86 | + #[DataProvider('provideReduceMultiples')] |
| 87 | + public function testReduceMultiples(string $str, string $expected): void |
86 | 88 | { |
87 | | - $strs = [ |
88 | | - 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', |
89 | | - 'Ringo, John, Paul,,' => 'Ringo, John, Paul,', |
90 | | - ]; |
| 89 | + $this->assertSame($expected, reduce_multiples($str)); |
| 90 | + } |
91 | 91 |
|
92 | | - foreach ($strs as $str => $expect) { |
93 | | - $this->assertSame($expect, reduce_multiples($str)); |
94 | | - } |
95 | | - $strs = [ |
96 | | - 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', |
97 | | - 'Ringo, John, Paul,,' => 'Ringo, John, Paul', |
| 92 | + /** |
| 93 | + * @return iterable<string, list<string>> |
| 94 | + */ |
| 95 | + public static function provideReduceMultiples(): iterable |
| 96 | + { |
| 97 | + yield from [ |
| 98 | + // string, expected |
| 99 | + 'double commas' => ['Fred, Bill,, Joe, Jimmy', 'Fred, Bill, Joe, Jimmy'], |
| 100 | + 'double commas at last' => ['Ringo, John, Paul,,', 'Ringo, John, Paul,'], |
| 101 | + 'commas at first and last' => [',Fred, Bill,, Joe, Jimmy,', ',Fred, Bill, Joe, Jimmy,'], |
98 | 102 | ]; |
| 103 | + } |
99 | 104 |
|
100 | | - foreach ($strs as $str => $expect) { |
101 | | - $this->assertSame($expect, reduce_multiples($str, ',', true)); |
102 | | - } |
| 105 | + #[DataProvider('provideReduceMultiplesWithTrim')] |
| 106 | + public function testReduceMultiplesWithTrim(string $str, string $expected): void |
| 107 | + { |
| 108 | + $this->assertSame($expected, reduce_multiples($str, ',', true)); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @return iterable<string, list<string>> |
| 113 | + */ |
| 114 | + public static function provideReduceMultiplesWithTrim(): iterable |
| 115 | + { |
| 116 | + yield from [ |
| 117 | + // string, expected |
| 118 | + 'double commas' => ['Fred, Bill,, Joe, Jimmy', 'Fred, Bill, Joe, Jimmy'], |
| 119 | + 'double commas at last' => ['Ringo, John, Paul,,', 'Ringo, John, Paul'], |
| 120 | + 'commas at first and last' => [',Fred, Bill,, Joe, Jimmy,', 'Fred, Bill, Joe, Jimmy'], |
| 121 | + ]; |
103 | 122 | } |
104 | 123 |
|
105 | 124 | public function testRandomString(): void |
|
0 commit comments