Skip to content

Commit dd2bea4

Browse files
committed
Improve documentation for exception handling and method tracing
1 parent 000dc2c commit dd2bea4

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

docs/plugins/assert.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,22 @@ public function throwsOnInvalidInput(): void
374374
You can narrow down the expected exception using chain methods:
375375
376376
<signature compact h="4" name="\Testo\Assert\Api\ExpectedException::fromMethod(string $class, string $method): self">
377-
<short>Specifies that the exception should be thrown from a specific method (the throw point, not the creation point).</short>
377+
<short>Checks that the specified method is present in the exception's call stack.</short>
378+
<description>
379+
Can be called multiple times to require several methods in the call chain.
380+
381+
::: info
382+
The call stack in an exception is captured at the moment of its creation, not when it is thrown. So this checks where the exception was created, not where it was rethrown via `throw`.
383+
:::
384+
</description>
385+
<example>
386+
```php
387+
// Make sure the exception originated in validation,
388+
// not rethrown from somewhere else
389+
Expect::exception(ValidationException::class)
390+
->fromMethod(UserValidator::class, 'validate');
391+
```
392+
</example>
378393
</signature>
379394
380395
<signature compact h="4" name="\Testo\Assert\Api\ExpectedException::withMessage(string $message): self">

docs/writing-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Instead of base classes or magic methods, Testo bets on attributes.
117117
public function sum(int $a, int $b, int $expected): void { /* ... */ }
118118
```
119119

120-
- Instead of `Expect::exception` you can use the `#[ExpectException]` attribute, which is slightly more compact and adds clarity:
120+
- Instead of <func>\Testo\Expect::exception()</func> you can use the `#[ExpectException]` attribute, which is slightly more compact and adds clarity:
121121

122122
```php
123123
#[ExpectException(\InsufficientFundsException::class)]

ru/docs/plugins/assert.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,22 @@ public function throwsOnInvalidInput(): void
373373
С помощью цепочки методов можно уточнить, какое именно исключение ожидается:
374374
375375
<signature compact h="4" name="\Testo\Assert\Api\ExpectedException::fromMethod(string $class, string $method): self">
376-
<short>Указывает, что исключение должно быть выброшено из конкретного метода (точка выброса, а не создания).</short>
376+
<short>Проверяет, что указанный метод присутствует в стеке вызовов исключения.</short>
377+
<description>
378+
Метод можно вызывать несколько раз, добавляя несколько мест для проверки.
379+
380+
::: info
381+
Стек вызовов в исключении заполняется в момент его создания, а не выброса. Таким образом, мы проверяем именно место создания, а не проброс через `throw`.
382+
:::
383+
</description>
384+
<example>
385+
```php
386+
// Убеждаемся, что исключение возникло именно в валидации,
387+
// а не было проброшено откуда-то ещё
388+
Expect::exception(ValidationException::class)
389+
->fromMethod(UserValidator::class, 'validate');
390+
```
391+
</example>
377392
</signature>
378393
379394
<signature compact h="4" name="\Testo\Assert\Api\ExpectedException::withMessage(string $message): self">

ru/docs/writing-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Expect::notLeaks($connection);
116116
public function sum(int $a, int $b, int $expected): void { /* ... */ }
117117
```
118118

119-
- А вместо `Expect::exception` можно использовать атрибут `#[ExpectException]`, который просто немного компактнее и добавляет наглядности:
119+
- А вместо <func>\Testo\Expect::exception()</func> можно использовать атрибут `#[ExpectException]`, который просто немного компактнее и добавляет наглядности:
120120

121121
```php
122122
#[ExpectException(\InsufficientFundsException::class)]

0 commit comments

Comments
 (0)