Skip to content

Commit 863cce9

Browse files
committed
test: improve phpunit message for assertInstanceOf
1 parent eba4a3e commit 863cce9

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"require-dev": {
5959
"buggregator/trap": "^1.13.0",
6060
"composer/composer": "^2.8.4",
61+
"cweagans/composer-patches": "^2.0",
6162
"dereuromark/composer-prefer-lowest": "^0.1.10",
6263
"doctrine/annotations": "^1.14.4 || ^2.0.2",
6364
"internal/dload": "^1.2.0",
@@ -103,7 +104,17 @@
103104
"test:accept": "phpunit --testsuite=Acceptance --color=always --testdox"
104105
},
105106
"config": {
106-
"sort-packages": true
107+
"sort-packages": true,
108+
"allow-plugins": {
109+
"cweagans/composer-patches": true
110+
}
111+
},
112+
"extra": {
113+
"patches": {
114+
"phpunit/phpunit": {
115+
"Improve assertInstanceOf error message": "patches/phpunit-instance-of.patch"
116+
}
117+
}
107118
},
108119
"minimum-stability": "dev",
109120
"prefer-stable": true

patches.lock.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"_hash": "a019c9b721919a9a16ed12424d63d5316cb7d0baf6749363b7aabfa962758213",
3+
"patches": {
4+
"phpunit/phpunit": [
5+
{
6+
"package": "phpunit/phpunit",
7+
"description": "Improve assertInstanceOf error message",
8+
"url": "patches/phpunit-instance-of.patch",
9+
"sha256": "4c42249225a057ca528837c8d2642a9fdb7f483991459c9422437b68f0597a70",
10+
"depth": 1,
11+
"extra": {
12+
"provenance": "root"
13+
}
14+
}
15+
]
16+
}
17+
}

patches/phpunit-instance-of.patch

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/src/Framework/Constraint/Type/IsInstanceOf.php
2+
+++ b/src/Framework/Constraint/Type/IsInstanceOf.php
3+
@@ -74,5 +74,14 @@
4+
*/
5+
protected function failureDescription(mixed $other): string
6+
{
7+
- return $this->valueToTypeStringFragment($other) . $this->toString(true);
8+
+ $description = $this->valueToTypeStringFragment($other);
9+
+
10+
+ if (\is_object($other)) {
11+
+ $description = \sprintf(
12+
+ 'an instance of class %s ',
13+
+ \get_class($other),
14+
+ );
15+
+ }
16+
+
17+
+ return $description . $this->toString();
18+
}

0 commit comments

Comments
 (0)