Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit cb9532b

Browse files
committed
fix: update tests for phpunit 11
1 parent ec3e585 commit cb9532b

14 files changed

+594
-539
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"blobfolio\/blob-phone": "*"
3636
},
3737
"require-dev": {
38-
"phpunit\/phpunit": "5.7.*"
38+
"phpunit\/phpunit": "11.*"
3939
},
4040
"config": {
4141
"vendor-dir": "lib\/vendor",

phpunit-phar.xml.dist

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
<?xml version="1.0"?>
12
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24
bootstrap="bin/blob-common.phar"
35
backupGlobals="false"
46
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
7+
beStrictAboutOutputDuringTests="true"
8+
beStrictAboutTestsThatDoNotTestAnything="true"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory="/tmp/phpunit-cache"
10+
>
911
<testsuites>
10-
<testsuite>
11-
<directory prefix="test-" suffix=".php">./tests/</directory>
12+
<testsuite name="unit">
13+
<directory suffix=".php">./tests/</directory>
1214
</testsuite>
1315
</testsuites>
1416
</phpunit>

phpunit.xml.dist

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
<?xml version="1.0"?>
12
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24
bootstrap="lib/vendor/autoload.php"
35
backupGlobals="false"
46
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
7+
beStrictAboutOutputDuringTests="true"
8+
beStrictAboutTestsThatDoNotTestAnything="true"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory="/tmp/phpunit-cache"
10+
>
911
<testsuites>
10-
<testsuite>
11-
<directory prefix="test-" suffix=".php">./tests/</directory>
12+
<testsuite name="unit">
13+
<directory suffix=".php">./tests/</directory>
1214
</testsuite>
1315
</testsuites>
1416
</phpunit>

tests/test-cast.php renamed to tests/cast_tests.php

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,42 @@
88
* @author Blobfolio, LLC <[email protected]>
99
*/
1010

11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use PHPUnit\Framework\Attributes\Test;
13+
use PHPUnit\Framework\TestCase;
1114
use blobfolio\common\cast as v_cast;
1215
use blobfolio\common\ref\cast as r_cast;
1316

1417
/**
1518
* Test Suite
1619
*/
17-
class cast_tests extends \PHPUnit\Framework\TestCase {
20+
class cast_tests extends TestCase {
1821
// -----------------------------------------------------------------
1922
// Tests
2023
// -----------------------------------------------------------------
2124

25+
#[Test]
26+
#[DataProvider('data_array')]
2227
/**
2328
* ::array()
2429
*
25-
* @dataProvider data_array
26-
*
2730
* @param mixed $value Value.
2831
* @param array $expected Expected.
2932
*/
30-
function test_array($value, $expected) {
33+
public function test_array($value, $expected) {
3134
$this->assertEquals($expected, v_cast::to_array($value));
3235
$this->assertEquals('array', \gettype(v_cast::to_array($value)));
3336
}
3437

38+
#[Test]
39+
#[DataProvider('data_array')]
3540
/**
3641
* ::array() alias
3742
*
38-
* @dataProvider data_array
39-
*
4043
* @param mixed $value Value.
4144
* @param array $expected Expected.
4245
*/
43-
function test_array_alias($value, $expected) {
46+
public function test_array_alias($value, $expected) {
4447
if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
4548
$this->markTestSkipped('Aliases are only supported in PHP 7+.');
4649
}
@@ -56,41 +59,41 @@ function test_array_alias($value, $expected) {
5659
$this->assertEquals($expected, $value);
5760
}
5861

62+
#[Test]
63+
#[DataProvider('data_array_type')]
5964
/**
6065
* ::array_type()
6166
*
62-
* @dataProvider data_array_type
63-
*
6467
* @param mixed $value Value.
6568
* @param string $expected Expected.
6669
*/
67-
function test_array_type($value, $expected) {
70+
public function test_array_type($value, $expected) {
6871
$this->assertEquals($expected, v_cast::array_type($value));
6972
}
7073

74+
#[Test]
75+
#[DataProvider('data_bool')]
7176
/**
7277
* ::bool()
7378
*
74-
* @dataProvider data_bool
75-
*
7679
* @param mixed $value Value.
7780
* @param bool $flatten Flatten.
7881
* @param string $expected Expected.
7982
*/
80-
function test_bool($value, $flatten, $expected) {
83+
public function test_bool($value, $flatten, $expected) {
8184
$this->assertSame($expected, v_cast::to_bool($value, $flatten));
8285
}
8386

87+
#[Test]
88+
#[DataProvider('data_bool')]
8489
/**
8590
* ::bool() alias
8691
*
87-
* @dataProvider data_bool
88-
*
8992
* @param mixed $value Value.
9093
* @param bool $flatten Flatten.
9194
* @param string $expected Expected.
9295
*/
93-
function test_bool_alias($value, $flatten, $expected) {
96+
public function test_bool_alias($value, $flatten, $expected) {
9497
if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
9598
$this->markTestSkipped('Aliases are only supported in PHP 7+.');
9699
}
@@ -107,29 +110,29 @@ function test_bool_alias($value, $flatten, $expected) {
107110
$this->assertSame($expected, $value2);
108111
}
109112

113+
#[Test]
114+
#[DataProvider('data_float')]
110115
/**
111116
* ::float()
112117
*
113-
* @dataProvider data_float
114-
*
115118
* @param mixed $value Value.
116119
* @param bool $flatten Flatten.
117120
* @param string $expected Expected.
118121
*/
119-
function test_float($value, $flatten, $expected) {
122+
public function test_float($value, $flatten, $expected) {
120123
$this->assertSame($expected, v_cast::to_float($value, $flatten));
121124
}
122125

126+
#[Test]
127+
#[DataProvider('data_float')]
123128
/**
124129
* ::float() alias
125130
*
126-
* @dataProvider data_float
127-
*
128131
* @param mixed $value Value.
129132
* @param bool $flatten Flatten.
130133
* @param string $expected Expected.
131134
*/
132-
function test_float_alias($value, $flatten, $expected) {
135+
public function test_float_alias($value, $flatten, $expected) {
133136
if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
134137
$this->markTestSkipped('Aliases are only supported in PHP 7+.');
135138
}
@@ -146,24 +149,24 @@ function test_float_alias($value, $flatten, $expected) {
146149
$this->assertSame($expected, $value2);
147150
}
148151

152+
#[Test]
153+
#[DataProvider('data_int')]
149154
/**
150155
* ::int()
151156
*
152-
* @dataProvider data_int
153-
*
154157
* @param mixed $value Value.
155158
* @param bool $flatten Flatten.
156159
* @param string $expected Expected.
157160
*/
158-
function test_int($value, $flatten, $expected) {
161+
public function test_int($value, $flatten, $expected) {
159162
$this->assertSame($expected, v_cast::to_int($value, $flatten));
160163
}
161164

165+
#[Test]
166+
#[DataProvider('data_int')]
162167
/**
163168
* ::int() alias
164169
*
165-
* @dataProvider data_int
166-
*
167170
* @param mixed $value Value.
168171
* @param bool $flatten Flatten.
169172
* @param string $expected Expected.
@@ -185,29 +188,29 @@ function test_int_alias($value, $flatten, $expected) {
185188
$this->assertSame($expected, $value2);
186189
}
187190

191+
#[Test]
192+
#[DataProvider('data_string')]
188193
/**
189194
* ::string()
190195
*
191-
* @dataProvider data_string
192-
*
193196
* @param mixed $value Value.
194197
* @param bool $flatten Flatten.
195198
* @param string $expected Expected.
196199
*/
197-
function test_string($value, $flatten, $expected) {
200+
public function test_string($value, $flatten, $expected) {
198201
$this->assertSame($expected, v_cast::to_string($value, $flatten));
199202
}
200203

204+
#[Test]
205+
#[DataProvider('data_string')]
201206
/**
202207
* ::string() alias
203208
*
204-
* @dataProvider data_string
205-
*
206209
* @param mixed $value Value.
207210
* @param bool $flatten Flatten.
208211
* @param string $expected Expected.
209212
*/
210-
function test_string_alias($value, $flatten, $expected) {
213+
public function test_string_alias($value, $flatten, $expected) {
211214
if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
212215
$this->markTestSkipped('Aliases are only supported in PHP 7+.');
213216
}
@@ -218,12 +221,11 @@ function test_string_alias($value, $flatten, $expected) {
218221
$this->assertSame($expected, $value);
219222
}
220223

221-
224+
#[Test]
225+
#[DataProvider('data_to_type')]
222226
/**
223227
* ::to_type()
224228
*
225-
* @dataProvider data_to_type
226-
*
227229
* @param mixed $value Value.
228230
* @param string $type Type.
229231
* @param bool $flatten Flatten.
@@ -246,7 +248,7 @@ function test_to_type($value, $type, $flatten, $expected) {
246248
*
247249
* @return array Data.
248250
*/
249-
function data_array() {
251+
static function data_array() {
250252
return array(
251253
array(
252254
'string',
@@ -272,7 +274,7 @@ function data_array() {
272274
*
273275
* @return array Data.
274276
*/
275-
function data_array_type() {
277+
static function data_array_type() {
276278
return array(
277279
array(
278280
'string',
@@ -322,7 +324,7 @@ function data_array_type() {
322324
*
323325
* @return array Data.
324326
*/
325-
function data_bool() {
327+
static function data_bool() {
326328
return array(
327329
array(
328330
'string',
@@ -367,7 +369,7 @@ function data_bool() {
367369
*
368370
* @return array Data.
369371
*/
370-
function data_float() {
372+
static function data_float() {
371373
return array(
372374
array(
373375
'string',
@@ -422,7 +424,7 @@ function data_float() {
422424
*
423425
* @return array Data.
424426
*/
425-
function data_int() {
427+
static function data_int() {
426428
return array(
427429
array(
428430
'string',
@@ -472,7 +474,7 @@ function data_int() {
472474
*
473475
* @return array Data.
474476
*/
475-
function data_string() {
477+
static function data_string() {
476478
return array(
477479
array(
478480
"Hello\nWorld",
@@ -517,7 +519,7 @@ function data_string() {
517519
*
518520
* @return array Data.
519521
*/
520-
function data_to_type() {
522+
static function data_to_type() {
521523
return array(
522524
array(
523525
null,

tests/test-cli.php renamed to tests/cli_tests.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,48 @@
88
* @author Blobfolio, LLC <[email protected]>
99
*/
1010

11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use PHPUnit\Framework\Attributes\Test;
13+
use PHPUnit\Framework\TestCase;
1114
use blobfolio\common\cli;
1215

1316
/**
1417
* Test Suite
1518
*/
16-
class cli_tests extends \PHPUnit\Framework\TestCase {
19+
class cli_tests extends TestCase {
1720
// -----------------------------------------------------------------
1821
// Tests
1922
// -----------------------------------------------------------------
2023

24+
#[Test]
25+
#[DataProvider('data_colorize')]
2126
/**
2227
* ::colorize()
2328
*
24-
* @dataProvider data_colorize
25-
*
2629
* @param array $value Value.
2730
* @param array $expected Expected.
2831
*/
29-
function test_colorize($value, $expected) {
32+
public function test_colorize($value, $expected) {
3033
$result = \call_user_func_array(
3134
array('\\blobfolio\\common\\cli', 'colorize'),
3235
$value
3336
);
3437
$this->assertEquals($expected, $result);
3538
}
3639

40+
#[Test]
3741
/**
3842
* ::is_cli()
3943
*/
40-
function test_is_cli() {
44+
public function test_is_cli() {
4145
$this->assertTrue(cli::is_cli());
4246
}
4347

48+
#[Test]
4449
/**
4550
* ::is_root()
4651
*/
47-
function test_is_root() {
52+
public function test_is_root() {
4853
if (! \function_exists('posix_getuid')) {
4954
$this->markTestSkipped('POSIX functions are missing.');
5055
}
@@ -66,7 +71,7 @@ function test_is_root() {
6671
*
6772
* @return array Data.
6873
*/
69-
function data_colorize() {
74+
static function data_colorize() {
7075
return array(
7176
array(
7277
array(

0 commit comments

Comments
 (0)