Skip to content

Commit 260fdf4

Browse files
Merge branch '10.0'
2 parents ec72a7d + 2bc1aea commit 260fdf4

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

ChangeLog-10.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 10.0 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [10.0.12] - 2023-MM-DD
6+
7+
### Changed
8+
9+
* Values of other types than `array` may now be passed to `assertIsList()`
10+
511
## [10.0.11] - 2023-02-20
612

713
### Fixed
@@ -210,6 +216,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
210216
* PHP 7.3, PHP 7.4, and PHP 8.0 are no longer supported
211217
* `phpunit/php-code-coverage` [no longer supports PHPDBG and Xdebug 2](https://github.com/sebastianbergmann/php-code-coverage/blob/10.0.0/ChangeLog.md#1000---2023-02-03)
212218

219+
[10.0.12]: https://github.com/sebastianbergmann/phpunit/compare/10.0.11...10.0
213220
[10.0.11]: https://github.com/sebastianbergmann/phpunit/compare/10.0.10...10.0.11
214221
[10.0.10]: https://github.com/sebastianbergmann/phpunit/compare/10.0.9...10.0.10
215222
[10.0.9]: https://github.com/sebastianbergmann/phpunit/compare/10.0.8...10.0.9

src/Framework/Assert.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ final public static function assertArrayNotHasKey(int|string $key, array|ArrayAc
103103
/**
104104
* @throws ExpectationFailedException
105105
*/
106-
final public static function assertIsList(array $array, string $message = ''): void
106+
final public static function assertIsList(mixed $array, string $message = ''): void
107107
{
108108
static::assertThat(
109109
$array,
@@ -1824,9 +1824,9 @@ final public static function assertThat(mixed $value, Constraint $constraint, st
18241824
*
18251825
* @throws ExpectationFailedException
18261826
*/
1827-
final public static function assertJson(string $actualJson, string $message = ''): void
1827+
final public static function assertJson(string $actual, string $message = ''): void
18281828
{
1829-
static::assertThat($actualJson, static::isJson(), $message);
1829+
static::assertThat($actual, static::isJson(), $message);
18301830
}
18311831

18321832
/**

src/Framework/Assert/Functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string
111111
*
112112
* @see Assert::assertIsList
113113
*/
114-
function assertIsList(array $array, string $message = ''): void
114+
function assertIsList(mixed $array, string $message = ''): void
115115
{
116116
Assert::assertIsList(...func_get_args());
117117
}
@@ -2095,7 +2095,7 @@ function assertThat(mixed $value, Constraint $constraint, string $message = ''):
20952095
*
20962096
* @see Assert::assertJson
20972097
*/
2098-
function assertJson(string $actualJson, string $message = ''): void
2098+
function assertJson(string $actual, string $message = ''): void
20992099
{
21002100
Assert::assertJson(...func_get_args());
21012101
}

src/Framework/Constraint/Traversable/IsList.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
namespace PHPUnit\Framework\Constraint;
1111

1212
use function array_is_list;
13+
use function gettype;
1314
use function is_array;
15+
use function strtolower;
1416

1517
/**
1618
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -22,7 +24,7 @@ final class IsList extends Constraint
2224
*/
2325
public function toString(): string
2426
{
25-
return 'is list';
27+
return 'is a list';
2628
}
2729

2830
/**
@@ -46,6 +48,20 @@ protected function matches(mixed $other): bool
4648
*/
4749
protected function failureDescription(mixed $other): string
4850
{
49-
return 'an array ' . $this->toString();
51+
$type = strtolower(gettype($other));
52+
53+
if ($type === 'double') {
54+
$type = 'float';
55+
}
56+
57+
if ($type === 'resource (closed)') {
58+
$type = 'closed resource';
59+
}
60+
61+
return match ($type) {
62+
'array', 'integer', 'object' => 'an ' . $type . ' ' . $this->toString(),
63+
'boolean', 'float', 'null', 'resource', 'string' => 'a ' . $type . ' ' . $this->toString(),
64+
default => 'a value of ' . $type . ' ' . $this->toString(),
65+
};
5066
}
5167
}

tests/unit/Framework/AssertTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ public function testAssertIsListFailsWithStringKeys(): void
251251
$this->assertIsList(['string' => 0]);
252252
}
253253

254+
public function testAssertIsListFailsForTypesOtherThanArray(): void
255+
{
256+
$this->expectException(AssertionFailedError::class);
257+
258+
$this->assertIsList(null);
259+
}
260+
254261
public function testAssertArrayContainsOnlyIntegers(): void
255262
{
256263
$this->assertContainsOnly('integer', [1, 2, 3]);

tests/unit/Framework/Constraint/IsListTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public function testConstraintIsNotList(): void
3131
$constraint = new IsList;
3232

3333
$this->assertFalse($constraint->evaluate([1 => 1], '', true));
34-
$this->assertEquals('is list', $constraint->toString());
34+
$this->assertEquals('is a list', $constraint->toString());
3535
$this->assertCount(1, $constraint);
3636

3737
try {
3838
$constraint->evaluate([1 => 1]);
3939
} catch (ExpectationFailedException $e) {
4040
$this->assertEquals(
4141
<<<'EOF'
42-
Failed asserting that an array is list.
42+
Failed asserting that an array is a list.
4343

4444
EOF
4545
,
@@ -57,15 +57,15 @@ public function testConstraintIsNotListWithFilteredArray(): void
5757
$constraint = new IsList;
5858

5959
$this->assertFalse($constraint->evaluate([0 => 0, 1 => 1, 3 => 3], '', true));
60-
$this->assertEquals('is list', $constraint->toString());
60+
$this->assertEquals('is a list', $constraint->toString());
6161
$this->assertCount(1, $constraint);
6262

6363
try {
6464
$constraint->evaluate([1 => 1]);
6565
} catch (ExpectationFailedException $e) {
6666
$this->assertEquals(
6767
<<<'EOF'
68-
Failed asserting that an array is list.
68+
Failed asserting that an array is a list.
6969

7070
EOF
7171
,
@@ -88,7 +88,7 @@ public function testConstraintIsNotListWithCustomMessage(): void
8888
$this->assertEquals(
8989
<<<'EOF'
9090
custom message
91-
Failed asserting that an array is list.
91+
Failed asserting that an array is a list.
9292

9393
EOF
9494
,
@@ -110,7 +110,7 @@ public function testConstraintIsNotListWhenNotArray(): void
110110
} catch (ExpectationFailedException $e) {
111111
$this->assertEquals(
112112
<<<'EOF'
113-
Failed asserting that an array is list.
113+
Failed asserting that a string is a list.
114114

115115
EOF
116116
,
@@ -131,7 +131,7 @@ public function testConstraintArrayIsNotList(): void
131131
$this->assertEquals(
132132
<<<'EOF'
133133
custom message
134-
Failed asserting that an array is not list.
134+
Failed asserting that an array is not a list.
135135

136136
EOF
137137
,

0 commit comments

Comments
 (0)