From 6aaef9c4319706f44a55d64ffae14eedcc302e2f Mon Sep 17 00:00:00 2001 From: Dave Liddament Date: Sun, 10 Dec 2023 23:36:09 +0000 Subject: [PATCH 1/2] UPDATE interface for ConstantStringErrorMessageFormatter --- README.md | 14 ++------------ src/ConstantStringErrorMessageFormatter.php | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ef953ac..01228a7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -102,7 +92,7 @@ class CallableFromRuleTest extends AbstractRuleTestCase protected function getErrorFormatter(): ErrorMessageFormatter { - return new CallableFromRuleErrorFormatter(); + return new ConstantStringErrorMessageFormatter("Can not call method"); } } ``` diff --git a/src/ConstantStringErrorMessageFormatter.php b/src/ConstantStringErrorMessageFormatter.php index fb10e0f..e9cfbf8 100644 --- a/src/ConstantStringErrorMessageFormatter.php +++ b/src/ConstantStringErrorMessageFormatter.php @@ -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, ) { } From 06868adb19dff3444ec2689a9ce711f50a2723ce Mon Sep 17 00:00:00 2001 From: Dave Liddament Date: Sun, 10 Dec 2023 23:37:44 +0000 Subject: [PATCH 2/2] ADD composer.lock to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ef0a005..ee9c51f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ vendor/ .idea/ .phpunit.cache/ .php-cs-fixer.cache +composer.lock