Skip to content

Commit 4c3150f

Browse files
committed
docs: added exception class assertion reminder
1 parent 4f98314 commit 4c3150f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎CODING_STANDARDS.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ rewritten to comply with these rules.
295295
1. Extensions should be well tested using `*.phpt` tests. Read more at
296296
[qa.php.net](https://qa.php.net/write-test.php) documentation.
297297

298+
2. When testing exceptions, assert the error class in the catch block.
299+
300+
```diff
301+
try {
302+
throw new ValueError('foo');
303+
} catch (ValueError $e) {
304+
- echo $e->getMessage(), "\n";
305+
+ echo $e::class, ': ', $e->getMessage(), "\n";
306+
}
307+
308+
--EXPECT--
309+
- foo
310+
+ ValueError: foo
311+
```
312+
298313
## New and experimental functions
299314

300315
To reduce the problems normally associated with the first public implementation

0 commit comments

Comments
 (0)