Skip to content

Commit 611e2ce

Browse files
committed
Update to PHPUnit ^11
1 parent 83875d9 commit 611e2ce

33 files changed

+585
-701
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"mikey179/vfsstream": "^1.6.11",
27-
"phpunit/phpunit": "^10.0",
27+
"phpunit/phpunit": "^11.0",
2828
"ergebnis/phpunit-slow-test-detector": "^2.15"
2929
},
3030
"support": {

test/unit/ArrayHelpers/AssociativeArrayUtilsTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99

1010
use Ingenerator\PHPUtils\ArrayHelpers\AssociativeArrayUtils;
11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use PHPUnit\Framework\Attributes\TestWith;
1113
use PHPUnit\Framework\TestCase;
1214

1315
class AssociativeArrayUtilsTest extends TestCase
1416
{
1517

16-
/**
17-
* @testWith [["one", "two", "three"], false]
18-
* [{"1": "mixed indices", "5": "also mixed"}, true]
19-
* [{"one": "o clock", "two": "o clock", "three": "o clock"}, true]
20-
*/
18+
#[TestWith([['one', 'two', 'three'], false])]
19+
#[TestWith([[1 => 'mixed indices', 5 => 'also mixed'], true])]
20+
#[TestWith([['one' => 'o clock', 'two' => 'o clock', 'three' => 'o clock'], true])]
2121
public function test_is_associative(array $array, $expected)
2222
{
2323
$this->assertSame(
@@ -52,9 +52,7 @@ public static function provider_paths_to_nested(): array
5252
];
5353
}
5454

55-
/**
56-
* @dataProvider provider_paths_to_nested
57-
*/
55+
#[DataProvider('provider_paths_to_nested')]
5856
public function test_it_converts_pathed_hash_to_nested_arrays($input, $expect)
5957
{
6058
$this->assertSame($expect, AssociativeArrayUtils::pathsToNested($input));
@@ -91,9 +89,7 @@ public static function provider_pop_keys(): array
9189
];
9290
}
9391

94-
/**
95-
* @dataProvider provider_pop_keys
96-
*/
92+
#[DataProvider('provider_pop_keys')]
9793
public function test_it_can_pop_keys_from_a_source_array($source, $pop_keys, $expect)
9894
{
9995
$result = AssociativeArrayUtils::popKeys($source, $pop_keys);
@@ -126,9 +122,7 @@ public static function provider_set_path(): array
126122
];
127123
}
128124

129-
/**
130-
* @dataProvider provider_set_path
131-
*/
125+
#[DataProvider('provider_set_path')]
132126
public function test_set_path($expected, $array, ...$args)
133127
{
134128
AssociativeArrayUtils::setPath($array, ...$args);
@@ -267,9 +261,7 @@ public static function provider_merge(): array
267261
];
268262
}
269263

270-
/**
271-
* @dataProvider provider_merge
272-
*/
264+
#[DataProvider('provider_merge')]
273265
public function test_deep_merge($expected, ...$args)
274266
{
275267
$this->assertSame(

test/unit/Assets/StaticAssetUrlProviderTest.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
namespace test\unit\Ingenerator\PHPUtils\Assets;
55

66

7+
use InvalidArgumentException;
78
use org\bovigo\vfs\vfsStream;
89
use org\bovigo\vfs\vfsStreamDirectory;
10+
use PHPUnit\Framework\Attributes\TestWith;
911
use PHPUnit\Framework\TestCase;
1012
use Ingenerator\PHPUtils\Assets\StaticAssetUrlProvider;
13+
use RuntimeException;
1114

1215
class StaticAssetUrlProviderTest extends TestCase
1316
{
@@ -31,21 +34,19 @@ public function test_it_is_initialisable()
3134
public function test_it_throws_in_invalid_mode()
3235
{
3336
$this->options['mode'] = 'some-junk';
34-
$this->expectException(\InvalidArgumentException::class);
37+
$this->expectException(InvalidArgumentException::class);
3538
$this->newSubject();
3639
}
3740

3841
public function test_in_local_mode_get_url_throws_if_file_does_not_exist()
3942
{
4043
$subject = $this->newSubject();
41-
$this->expectException(\RuntimeException::class);
44+
$this->expectException(RuntimeException::class);
4245
$subject->getUrl('assets/some-file.css');
4346
}
4447

45-
/**
46-
* @testWith ["assets/my-file.css"]
47-
* ["/assets/my-file.css"]
48-
*/
48+
#[TestWith(['assets/my-file.css'])]
49+
#[TestWith(['/assets/my-file.css'])]
4950
public function test_in_local_mode_get_url_returns_absolute_url_with_mtime_suffix($rel_path)
5051
{
5152
vfsStream::create(
@@ -67,17 +68,15 @@ public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_n
6768
{
6869
$this->options['asset_base_url_file'] = $this->vfs->url().'/no-such-file.php';
6970
$this->options['mode'] = StaticAssetUrlProvider::MODE_REMOTE;
70-
$this->expectException(\InvalidArgumentException::class);
71+
$this->expectException(InvalidArgumentException::class);
7172
$this->expectExceptionMessage('no-such-file.php');
7273
$this->newSubject();
7374
}
7475

75-
/**
76-
* @testWith [""]
77-
* ["some content that is not php"]
78-
* ["<?php $a = 1;"]
79-
* ["<?php return '';"]
80-
*/
76+
#[TestWith([''])]
77+
#[TestWith(['some content that is not php'])]
78+
#[TestWith(['<?php $a = 1;'])]
79+
#[TestWith(["<?php return '';"])]
8180
public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_not_return_string($file_content)
8281
{
8382
vfsStream::create(
@@ -87,15 +86,13 @@ public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_n
8786

8887
$this->options['asset_base_url_file'] = $this->vfs->getChild('asset-base-url.php')->url();
8988
$this->options['mode'] = StaticAssetUrlProvider::MODE_REMOTE;
90-
$this->expectException(\RuntimeException::class);
89+
$this->expectException(RuntimeException::class);
9190
$this->expectExceptionMessage('Invalid content in asset base url');
9291
$this->newSubject();
9392
}
9493

95-
/**
96-
* @testWith ["assets/my-file.css"]
97-
* ["/assets/my-file.css"]
98-
*/
94+
#[TestWith(['assets/my-file.css'])]
95+
#[TestWith(['/assets/my-file.css'])]
9996
public function test_it_remote_mode_get_url_returns_url_prefixed_with_base_url($rel_path)
10097
{
10198
vfsStream::create(

test/unit/CSV/CSVWriterTest.php

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@
77
namespace test\unit\Ingenerator\PHPUtils\CSV;
88

99

10+
use ErrorException;
1011
use Ingenerator\PHPUtils\CSV\CSVWriter;
1112
use Ingenerator\PHPUtils\CSV\MismatchedSchemaException;
13+
use LogicException;
14+
use PHPUnit\Framework\Attributes\TestWith;
1215
use PHPUnit\Framework\TestCase;
16+
use function fclose;
17+
use function fgetcsv;
18+
use function file_get_contents;
19+
use function fopen;
20+
use function fread;
21+
use function is_resource;
22+
use function rewind;
23+
use function stream_get_contents;
24+
use function strlen;
25+
use function sys_get_temp_dir;
26+
use function tempnam;
27+
use function unlink;
1328

1429
class CSVWriterTest extends TestCase
1530
{
@@ -22,14 +37,14 @@ public function test_it_is_initialisable()
2237
public function test_it_throws_if_file_cannot_be_opened()
2338
{
2439
$subject = $this->newSubject();
25-
$this->expectException(\ErrorException::class);
40+
$this->expectException(ErrorException::class);
2641
$subject->open('/invalid_csv_file');
2742
}
2843

2944
public function test_it_throws_if_writing_before_opening_file()
3045
{
3146
$subject = $this->newSubject();
32-
$this->expectException(\LogicException::class);
47+
$this->expectException(LogicException::class);
3348
$subject->write(['any' => 'junk']);
3449
}
3550

@@ -38,56 +53,56 @@ public function test_it_throws_if_writing_after_closing_file()
3853
$subj = $this->newSubject();
3954
$subj->open('php://temp');
4055
$subj->close();
41-
$this->expectException(\LogicException::class);
56+
$this->expectException(LogicException::class);
4257
$subj->write(['any' => 'content']);
4358
}
4459

4560
public function test_open_accepts_and_allows_writing_to_existing_stream_resource()
4661
{
47-
$file = \fopen('php://memory', 'w');
62+
$file = fopen('php://memory', 'w');
4863
try {
4964
$subj = $this->newSubject();
5065
$subj->open($file);
5166
$subj->write(['some' => 'csv']);
52-
\rewind($file);
53-
$this->assertNotEmpty(\stream_get_contents($file));
67+
rewind($file);
68+
$this->assertNotEmpty(stream_get_contents($file));
5469
} finally {
55-
\fclose($file);
70+
fclose($file);
5671
}
5772
}
5873

5974
public function test_it_throws_if_writing_to_externally_closed_resource()
6075
{
61-
$file = \fopen('php://memory', 'w');
76+
$file = fopen('php://memory', 'w');
6277
try {
6378
$subj = $this->newSubject();
6479
$subj->open($file);
6580
} finally {
66-
\fclose($file);
81+
fclose($file);
6782
}
6883

69-
$this->expectException(\LogicException::class);
84+
$this->expectException(LogicException::class);
7085
$subj->write(['some' => 'csv']);
7186
}
7287

7388
public function test_it_can_open_and_write_to_filename()
7489
{
75-
$name = \tempnam(\sys_get_temp_dir(), 'csv-test.csv');
90+
$name = tempnam(sys_get_temp_dir(), 'csv-test.csv');
7691
try {
7792
$subj = $this->newSubject();
7893
$subj->open($name, []);
7994
$subj->write(['a' => 'b', '1' => 2]);
8095
$subj->write(['a' => 'c', '1' => 3]);
8196
$subj->close();
82-
$this->assertEquals("a,1\nb,2\nc,3\n", \file_get_contents($name));
97+
$this->assertEquals("a,1\nb,2\nc,3\n", file_get_contents($name));
8398
} finally {
84-
\unlink($name);
99+
unlink($name);
85100
}
86101
}
87102

88103
public function test_it_writes_column_headers_before_first_row()
89104
{
90-
$file = \fopen('php://memory', 'w');
105+
$file = fopen('php://memory', 'w');
91106
$subj = $this->newSubject();
92107
$subj->open($file);
93108
$subj->write(['our' => 'data', 'is' => 'here']);
@@ -98,12 +113,12 @@ public function test_it_writes_column_headers_before_first_row()
98113
],
99114
$file
100115
);
101-
\fclose($file);
116+
fclose($file);
102117
}
103118

104119
public function test_it_does_not_write_column_headers_before_subsequent_rows()
105120
{
106-
$file = \fopen('php://memory', 'w');
121+
$file = fopen('php://memory', 'w');
107122
$subj = $this->newSubject();
108123
$subj->open($file);
109124
$subj->write(['our' => 'data', 'is' => 'here']);
@@ -116,62 +131,58 @@ public function test_it_does_not_write_column_headers_before_subsequent_rows()
116131
],
117132
$file
118133
);
119-
\fclose($file);
134+
fclose($file);
120135
}
121136

122-
/**
123-
* @testWith [true]
124-
* [false]
125-
*/
137+
#[TestWith([true])]
138+
#[TestWith([false])]
126139
public function test_it_optionally_writes_byte_order_mark_at_start_of_file($write_bom)
127140
{
128-
$file = \fopen('php://memory', 'w');
141+
$file = fopen('php://memory', 'w');
129142
$subj = $this->newSubject();
130143
$subj->open($file, ['write_utf8_bom' => $write_bom]);
131144
$subj->write(['first' => 'row']);
132-
\rewind($file);
145+
rewind($file);
133146
if ($write_bom) {
134-
$this->assertSame(CSVWriter::UTF8_BOM, \fread($file, \strlen(CSVWriter::UTF8_BOM)));
147+
$this->assertSame(CSVWriter::UTF8_BOM, fread($file, strlen(CSVWriter::UTF8_BOM)));
135148
}
136-
$this->assertSame(['first'], \fgetcsv($file));
149+
$this->assertSame(['first'], fgetcsv($file));
137150
}
138151

139-
/**
140-
* @testWith [{"is": "jumbled", "our": "up"}]
141-
* [{"our": "things", "went": "bad"}]
142-
*/
152+
#[TestWith([['is' => 'jumbled', 'our' => 'up']])]
153+
#[TestWith([['our' => 'things', 'went' => 'bad']])]
143154
public function test_it_throws_if_subsequent_row_headers_do_not_match($second_row)
144155
{
145-
$file = \fopen('php://memory', 'w');
156+
$file = fopen('php://memory', 'w');
146157
try {
147158
$subj = $this->newSubject();
148159
$subj->open($file);
149160
$subj->write(['our' => 'data', 'is' => 'here']);
150161
$this->expectException(MismatchedSchemaException::class);
151162
$subj->write($second_row);
152163
} finally {
153-
\fclose($file);
164+
fclose($file);
154165
}
155166
}
156167

157168
public function test_it_does_not_close_externally_provided_stream()
158169
{
159-
$file = \fopen('php://memory', 'w');
170+
$file = fopen('php://memory', 'w');
160171
try {
161172
$subj = $this->newSubject();
162173
$subj->open($file);
163174
$subj->close();
164-
$this->assertTrue(\is_resource($file));
175+
$this->assertTrue(is_resource($file));
165176
} finally {
166-
\fclose($file);
177+
fclose($file);
167178
}
168179
}
169180

170181
protected function assertCSVContent(array $expect, $file)
171182
{
172-
\rewind($file);
183+
rewind($file);
173184
$actual = [];
174-
while ($row = \fgetcsv($file)) {
185+
while ($row = fgetcsv($file)) {
175186
$actual[] = $row;
176187
}
177188

test/unit/Cookie/ArrayCookieWrapperStubTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
namespace test\unit\Ingenerator\PHPUtils\Cookie;
55

66

7+
use DateTimeImmutable;
78
use Ingenerator\PHPUtils\Cookie\ArrayCookieWrapperStub;
9+
use PHPUnit\Framework\Attributes\TestWith;
810
use PHPUnit\Framework\TestCase;
911

1012
class ArrayCookieWrapperStubTest extends TestCase
1113
{
12-
/**
13-
* @testWith ["my", true, "cookie"]
14-
* ["has", true, "values"]
15-
* ["anything", false, null]
16-
*/
14+
#[TestWith(['my', true, 'cookie'])]
15+
#[TestWith(['has', true, 'values'])]
16+
#[TestWith(['anything', false, null])]
1717
public function test_it_has_cookies_from_constructor_ignoring_superglobal(
1818
$name,
1919
$expect_has,
@@ -40,7 +40,7 @@ public function test_it_has_cookies_from_constructor_ignoring_superglobal(
4040

4141
public function test_it_can_simulate_set_cookie_and_capture_args()
4242
{
43-
$exp = new \DateTimeImmutable('tomorrow');
43+
$exp = new DateTimeImmutable('tomorrow');
4444
$subject = $this->newSubject();
4545
$subject->set('any', 'thing', ['expires' => $exp]);
4646
$this->assertSame(

0 commit comments

Comments
 (0)