Skip to content

Commit 7d3c0a9

Browse files
committed
Update PHPUnit to 10
1 parent 4453fa1 commit 7d3c0a9

File tree

9 files changed

+40
-75
lines changed

9 files changed

+40
-75
lines changed

.github/workflows/tag_meged_pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
tools: composer:v2
2424

2525
- name: Checkout code
26-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2727
with:
2828
fetch-depth: 0
2929

.github/workflows/test_pull_request.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
tools: composer:v2
1616

1717
- name: Checkout code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
2121

@@ -63,12 +63,12 @@ jobs:
6363
tools: composer:v2
6464

6565
- name: Set up Node
66-
uses: actions/setup-node@v3
66+
uses: actions/setup-node@v4
6767
with:
6868
node-version: '14.x'
6969

7070
- name: Checkout code
71-
uses: actions/checkout@v3
71+
uses: actions/checkout@v4
7272
with:
7373
fetch-depth: 0
7474

@@ -126,20 +126,20 @@ jobs:
126126
tools: composer:v2
127127

128128
- name: Set up Node
129-
uses: actions/setup-node@v3
129+
uses: actions/setup-node@v4
130130
with:
131131
node-version: '14.x'
132132

133133
- name: Checkout code
134-
uses: actions/checkout@v3
134+
uses: actions/checkout@v4
135135
with:
136136
fetch-depth: 0
137137

138138
- name: Run Composer
139139
run: composer install --no-interaction
140140

141141
- name: Update PHPUnit for Code Coverage
142-
run: composer require phpunit/phpunit:^9.6 phploc/phploc:* sebastian/version:* --with-all-dependencies
142+
run: composer require phpunit/phpunit:^10.5 sebastian/version:* --with-all-dependencies
143143

144144
- name: PHP Lint
145145
run: ./vendor/bin/parallel-lint src tests examples

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/vendor/
2+
composer.lock
3+
.php-version

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ There might be 3 factors.
105105

106106
In some cases, `CombinationGenerator` takes several times longer than `Combination`.
107107

108-
But, `Combination` mostly might exceed memory limit (128MB) when using param array with more than 22 elements.
108+
However, using an array with many elements as an argument can cause `Combination` to exceed memory limits.
109109

110-
Use `CombinationGenerator` then.
110+
In that case, use `CombinationGenerator`.
111111

112112
It will never exceeds the memory limit, and certanily complete the task.
113113

@@ -924,6 +924,6 @@ with patterns of `size`, `color` and `amount`.
924924

925925
*Document Created: 2023/11/11*
926926

927-
*Document Updated: 2024/03/17*
927+
*Document Updated: 2024/04/17*
928928

929929
Copyright 2023 - 2024 macocci7

bin/TestAndLint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test_and_lint() {
5555
echo "-----------------------------------------------------------"
5656
echo "[PHP $1][phpunit]"
5757
./vendor/bin/phpunit ./tests/ \
58-
--color auto
58+
--color=auto
5959
echo "-----------------------------------------------------------"
6060
}
6161

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"minimum-stability": "stable",
1919
"require-dev": {
2020
"squizlabs/php_codesniffer": "^3.7",
21-
"phpunit/phpunit": "^10",
21+
"phpunit/phpunit": "^10.5",
2222
"phpmd/phpmd": "^2.15",
2323
"phpstan/phpstan": "^1.10",
2424
"php-parallel-lint/php-parallel-lint": "^1.3"

tests/CombinationGeneratorTest.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require('vendor/autoload.php');
88

9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011
use Macocci7\PhpCombination\Util;
1112
use Macocci7\PhpCombination\CombinationGenerator;
@@ -36,9 +37,7 @@ public static function provide_all_can_return_all_combinations_correctly(): arra
3637
];
3738
}
3839

39-
/**
40-
* @dataProvider provide_all_can_return_all_combinations_correctly
41-
*/
40+
#[DataProvider('provide_all_can_return_all_combinations_correctly')]
4241
public function test_all_can_return_all_combinations_correctly(array $items, array $expect): void
4342
{
4443
$c = new CombinationGenerator();
@@ -54,9 +53,7 @@ public static function provide_pairs_can_throw_exception_with_invalid_param(): a
5453
];
5554
}
5655

57-
/**
58-
* @dataProvider provide_pairs_can_throw_exception_with_invalid_param
59-
*/
56+
#[DataProvider('provide_pairs_can_throw_exception_with_invalid_param')]
6057
public function test_pairs_can_throw_exception_with_invalid_param(array $items): void
6158
{
6259
$c = new CombinationGenerator();
@@ -76,9 +73,7 @@ public static function provide_pairs_can_return_all_pairs_correctly(): array
7673
];
7774
}
7875

79-
/**
80-
* @dataProvider provide_pairs_can_return_all_pairs_correctly
81-
*/
76+
#[DataProvider('provide_pairs_can_return_all_pairs_correctly')]
8277
public function test_pairs_can_return_all_pairs_correctly(array $items, array $expect): void
8378
{
8479
$c = new CombinationGenerator();
@@ -101,9 +96,7 @@ public static function provide_ofN_can_throw_exception_with_invalid_param(): arr
10196
];
10297
}
10398

104-
/**
105-
* @dataProvider provide_ofN_can_throw_exception_with_invalid_param
106-
*/
99+
#[DataProvider('provide_ofN_can_throw_exception_with_invalid_param')]
107100
public function test_ofN_can_throw_exception_with_invalid_param(array $items, int $n): void
108101
{
109102
$c = new CombinationGenerator();
@@ -126,9 +119,7 @@ public static function provide_ofN_can_return_all_combinations_of_n_elements_cor
126119
];
127120
}
128121

129-
/**
130-
* @dataProvider provide_ofN_can_return_all_combinations_of_n_elements_correctly
131-
*/
122+
#[DataProvider('provide_ofN_can_return_all_combinations_of_n_elements_correctly')]
132123
public function test_ofN_can_return_all_combinations_of_n_elements_correctly(array $items, int $n, array $expect): void
133124
{
134125
$c = new CombinationGenerator();
@@ -152,9 +143,7 @@ public static function provide_ofA2B_can_throw_exception_with_invalid_params():
152143
];
153144
}
154145

155-
/**
156-
* @dataProvider provide_ofA2B_can_throw_exception_with_invalid_params
157-
*/
146+
#[DataProvider('provide_ofA2B_can_throw_exception_with_invalid_params')]
158147
public function test_ofA2B_can_throw_exception_with_invalid_params(array $items, int $a, int $b, string $message): void
159148
{
160149
$c = new CombinationGenerator();
@@ -173,9 +162,7 @@ public static function provide_ofA2B_can_return_all_combinations_of_a_to_b_eleme
173162
];
174163
}
175164

176-
/**
177-
* @dataProvider provide_ofA2B_can_return_all_combinations_of_a_to_b_elements_correctly
178-
*/
165+
#[DataProvider('provide_ofA2B_can_return_all_combinations_of_a_to_b_elements_correctly')]
179166
public function test_ofA2B_can_return_all_combinations_of_a_to_b_elements_correctly(array $items, int $a, int $b, array $expect): void
180167
{
181168
$c = new CombinationGenerator();

tests/CombinationTest.php

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require('vendor/autoload.php');
88

9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011
use Macocci7\PhpCombination\Util;
1112
use Macocci7\PhpCombination\Combination;
@@ -32,9 +33,7 @@ public static function provide_all_can_return_all_combinations_correctly(): arra
3233
];
3334
}
3435

35-
/**
36-
* @dataProvider provide_all_can_return_all_combinations_correctly
37-
*/
36+
#[DataProvider('provide_all_can_return_all_combinations_correctly')]
3837
public function test_all_can_return_all_combinations_correctly(array $items, array $expect): void
3938
{
4039
$c = new Combination();
@@ -50,9 +49,7 @@ public static function provide_all_can_sort_correctly(): array
5049
];
5150
}
5251

53-
/**
54-
* @dataProvider provide_all_can_sort_correctly
55-
*/
52+
#[DataProvider('provide_all_can_sort_correctly')]
5653
public function test_all_can_sort_correctly(array $items, array $expect): void
5754
{
5855
$c = new Combination();
@@ -66,9 +63,7 @@ public static function provide_pairs_can_throw_exception_with_invalid_param(): a
6663
];
6764
}
6865

69-
/**
70-
* @dataProvider provide_pairs_can_throw_exception_with_invalid_param
71-
*/
66+
#[DataProvider('provide_pairs_can_throw_exception_with_invalid_param')]
7267
public function test_pairs_can_throw_exception_with_invalid_param(array $items): void
7368
{
7469
$c = new Combination();
@@ -86,9 +81,7 @@ public static function provide_pairs_can_return_all_pairs_correctly(): array
8681
];
8782
}
8883

89-
/**
90-
* @dataProvider provide_pairs_can_return_all_pairs_correctly
91-
*/
84+
#[DataProvider('provide_pairs_can_return_all_pairs_correctly')]
9285
public function test_pairs_can_return_all_pairs_correctly(array $items, array $expect): void
9386
{
9487
$c = new Combination();
@@ -111,9 +104,7 @@ public static function provide_ofN_can_throw_exception_with_invalid_param(): arr
111104
];
112105
}
113106

114-
/**
115-
* @dataProvider provide_ofN_can_throw_exception_with_invalid_param
116-
*/
107+
#[DataProvider('provide_ofN_can_throw_exception_with_invalid_param')]
117108
public function test_ofN_can_throw_exception_with_invalid_param(array $items, int $n): void
118109
{
119110
$c = new Combination();
@@ -134,9 +125,7 @@ public static function provide_ofN_can_return_all_combinations_of_n_elements_cor
134125
];
135126
}
136127

137-
/**
138-
* @dataProvider provide_ofN_can_return_all_combinations_of_n_elements_correctly
139-
*/
128+
#[DataProvider('provide_ofN_can_return_all_combinations_of_n_elements_correctly')]
140129
public function test_ofN_can_return_all_combinations_of_n_elements_correctly(array $items, int $n, array $expect): void
141130
{
142131
$c = new Combination();
@@ -159,9 +148,7 @@ public static function provide_ofA2B_can_throw_exception_with_invalid_param(): a
159148
];
160149
}
161150

162-
/**
163-
* @dataProvider provide_ofA2B_can_throw_exception_with_invalid_param
164-
*/
151+
#[DataProvider('provide_ofA2B_can_throw_exception_with_invalid_param')]
165152
public function test_ofA2B_can_throw_exception_with_invalid_param(array $items, int $a, int $b, string $message): void
166153
{
167154
$c = new Combination();
@@ -179,9 +166,7 @@ public static function provide_ofA2B_can_return_all_combinations_of_A_2_B_elemen
179166
];
180167
}
181168

182-
/**
183-
* @dataProvider provide_ofA2B_can_return_all_combinations_of_A_2_B_elements
184-
*/
169+
#[DataProvider('provide_ofA2B_can_return_all_combinations_of_A_2_B_elements')]
185170
public function test_ofA2B_can_return_all_combinations_of_A_2_B_elements(array $items, int $a, int $b, array $expect): void
186171
{
187172
$c = new Combination();
@@ -193,15 +178,13 @@ public static function provide_fromArrays_can_return_combinations_correctly(): a
193178
return [
194179
"1 element" => ['arrays' => [[1]], 'expect' => [[1]], ],
195180
"1 element, 1 element" => ['arrays' => [[1], [2], ], 'expect' => [[1, 2, ]], ],
196-
"1 element, 2 elements" => ['array' => [[1], [2, 3, ], ], 'expect' => [[1, 2, ], [1, 3, ], ], ],
197-
"2 elements, 2 elements" => ['array' => [[1, 2, ], [3, 4, ], ], 'expect' => [[1, 3, ], [1, 4, ], [2, 3, ], [2, 4, ], ], ],
198-
"2 elements, 2 elements, 2 elements" => ['array' => [[1, 2, ], [3, 4, ], [5, 6, ], ], 'expect' => [[1, 3, 5, ], [1, 3, 6, ], [1, 4, 5, ], [1, 4, 6, ], [2, 3, 5, ], [2, 3, 6, ], [2, 4, 5, ], [2, 4, 6, ], ], ],
181+
"1 element, 2 elements" => ['arrays' => [[1], [2, 3, ], ], 'expect' => [[1, 2, ], [1, 3, ], ], ],
182+
"2 elements, 2 elements" => ['arrays' => [[1, 2, ], [3, 4, ], ], 'expect' => [[1, 3, ], [1, 4, ], [2, 3, ], [2, 4, ], ], ],
183+
"2 elements, 2 elements, 2 elements" => ['arrays' => [[1, 2, ], [3, 4, ], [5, 6, ], ], 'expect' => [[1, 3, 5, ], [1, 3, 6, ], [1, 4, 5, ], [1, 4, 6, ], [2, 3, 5, ], [2, 3, 6, ], [2, 4, 5, ], [2, 4, 6, ], ], ],
199184
];
200185
}
201186

202-
/**
203-
* @dataProvider provide_fromArrays_can_return_combinations_correctly
204-
*/
187+
#[DataProvider('provide_fromArrays_can_return_combinations_correctly')]
205188
public function test_fromArrays_can_return_combinations_correctly(array $arrays, array $expect): void
206189
{
207190
$c = new Combination();

tests/UtilTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require('vendor/autoload.php');
88

9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011
use Macocci7\PhpCombination\Util;
1112

@@ -28,9 +29,7 @@ public static function provide_validateArray_can_throw_exception_with_invalid_pa
2829
];
2930
}
3031

31-
/**
32-
* @dataProvider provide_validateArray_can_throw_exception_with_invalid_param
33-
*/
32+
#[DataProvider('provide_validateArray_can_throw_exception_with_invalid_param')]
3433
public function test_validateArray_can_throw_exception_with_invalid_param(array $array, string $message): void
3534
{
3635
$this->expectException(\Exception::class);
@@ -54,9 +53,7 @@ public static function provide_validateArray_can_validate_array_correctly(): arr
5453
];
5554
}
5655

57-
/**
58-
* @dataProvider provide_validateArray_can_validate_array_correctly
59-
*/
56+
#[DataProvider('provide_validateArray_can_validate_array_correctly')]
6057
public function test_validateArray_can_validate_array_correctly(array $array): void
6158
{
6259
$this->assertTrue(Util::validateArray($array));
@@ -71,9 +68,7 @@ public static function provide_validateArrays_can_throw_exception_with_invalid_p
7168
];
7269
}
7370

74-
/**
75-
* @dataProvider provide_validateArrays_can_throw_exception_with_invalid_param
76-
*/
71+
#[DataProvider('provide_validateArrays_can_throw_exception_with_invalid_param')]
7772
public function test_validateArrays_can_throw_exception_with_invalid_param(array $arrays, string $message): void
7873
{
7974
$this->expectException(\Exception::class);
@@ -92,9 +87,7 @@ public static function provide_validateArrays_can_return_true_correctly(): array
9287
];
9388
}
9489

95-
/**
96-
* @dataProvider provide_validateArrays_can_return_true_correctly
97-
*/
90+
#[DataProvider('provide_validateArrays_can_return_true_correctly')]
9891
public function test_validateArrays_can_return_true_correctly(array $arrays): void
9992
{
10093
$this->assertTrue(Util::validateArrays($arrays));

0 commit comments

Comments
 (0)