Skip to content

Commit

Permalink
Merge pull request #3 from DaveLiddament/update/constant-string-error…
Browse files Browse the repository at this point in the history
…-formatter

UPDATE interface for ConstantStringErrorMessageFormatter
  • Loading branch information
DaveLiddament authored Dec 10, 2023
2 parents d7ea4a5 + 6aaef9c commit f7e6b96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,7 @@ E.g. in the example the error is `Can not call method`. No additional informatio

Create a class that extends `ConstantErrorFormatter` and pass the error message to the constructor.

```php
class CallableFromRuleErrorFormatter extends ConstantStringErrorMessageFormatter
{
public function __construct()
{
parent::__construct('Can not call method');
}
}
```

The next step is to update the test to tell it to use this formatter.
Update the test to tell it to use a `ConstantStringErrorMessageFormatter`.

```php
class CallableFromRuleTest extends AbstractRuleTestCase
Expand All @@ -102,7 +92,7 @@ class CallableFromRuleTest extends AbstractRuleTestCase

protected function getErrorFormatter(): ErrorMessageFormatter
{
return new CallableFromRuleErrorFormatter();
return new ConstantStringErrorMessageFormatter("Can not call method");
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions src/ConstantStringErrorMessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace DaveLiddament\PhpstanRuleTestHelper;

abstract class ConstantStringErrorMessageFormatter extends ErrorMessageFormatter
class ConstantStringErrorMessageFormatter extends ErrorMessageFormatter
{
protected function __construct(
public function __construct(
private string $errorMessage,
) {
}
Expand Down

0 comments on commit f7e6b96

Please sign in to comment.