From 31e5ef65907d277f434237faacbf940f0b5ed353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mor=C3=A1vek?= Date: Sun, 23 Oct 2022 11:46:15 +0200 Subject: [PATCH] Enable new shipmonk phpstan rules --- .../AutocompleteInput/AutocompleteInputTest.phpt | 15 +++++---------- .../AutocompleteInput/Fixtures/TestPresenter.php | 7 +++++++ tests/PHPStan/shipmonk.neon | 9 +++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/AutocompleteInput/AutocompleteInputTest.phpt b/tests/AutocompleteInput/AutocompleteInputTest.phpt index fd48fd3..29f512d 100644 --- a/tests/AutocompleteInput/AutocompleteInputTest.phpt +++ b/tests/AutocompleteInput/AutocompleteInputTest.phpt @@ -3,7 +3,6 @@ declare(strict_types = 1); namespace NepadaTests\AutocompleteInput; -use Nepada; use NepadaTests\AutocompleteInput\Fixtures\TestPresenter; use NepadaTests\TestCase; use Nette\Application; @@ -25,9 +24,7 @@ class AutocompleteInputTest extends TestCase public function testRendering(): void { - $presenter = TestPresenter::create(); - /** @var Nepada\AutocompleteInput\AutocompleteInput $autocompleteInput */ - $autocompleteInput = $presenter['form']['foo']; + $autocompleteInput = TestPresenter::create()->getAutocompleteInput(); $autocompleteInput->setDefaultValue('bar'); @@ -39,9 +36,7 @@ class AutocompleteInputTest extends TestCase public function testMinLengthSetting(): void { - $presenter = TestPresenter::create(); - /** @var Nepada\AutocompleteInput\AutocompleteInput $autocompleteInput */ - $autocompleteInput = $presenter['form']['foo']; + $autocompleteInput = TestPresenter::create()->getAutocompleteInput(); $autocompleteInput->setAutocompleteMinLength(42); @@ -55,9 +50,9 @@ class AutocompleteInputTest extends TestCase { $presenter = $this->runTestPresenter(str_replace('__QUERY_PLACEHOLDER__', 'someQuery', self::AUTOCOMPLETE_URL)); + Assert::type(Application\Responses\JsonResponse::class, $presenter->response); /** @var Application\Responses\JsonResponse $response */ $response = $presenter->response; - Assert::type(Application\Responses\JsonResponse::class, $response); Assert::same(['Query: someQuery', 'Lorem ipsum'], $response->getPayload()); } @@ -81,9 +76,9 @@ class AutocompleteInputTest extends TestCase ); } - private function runTestPresenter(string $url): TestPresenter + private function runTestPresenter(string $urlString): TestPresenter { - $url = new UrlScript($url); + $url = new UrlScript($urlString); $httpRequest = new Request($url); $presenter = TestPresenter::create($httpRequest); diff --git a/tests/AutocompleteInput/Fixtures/TestPresenter.php b/tests/AutocompleteInput/Fixtures/TestPresenter.php index f8fa9ec..544f0b9 100644 --- a/tests/AutocompleteInput/Fixtures/TestPresenter.php +++ b/tests/AutocompleteInput/Fixtures/TestPresenter.php @@ -58,4 +58,11 @@ private function createHttpResponse(): Nette\Http\IResponse return new Nette\Http\Response(); } + public function getAutocompleteInput(): AutocompleteInput + { + $input = $this['form']['foo']; + assert($input instanceof AutocompleteInput); + return $input; + } + } diff --git a/tests/PHPStan/shipmonk.neon b/tests/PHPStan/shipmonk.neon index 6df72ae..0678b89 100644 --- a/tests/PHPStan/shipmonk.neon +++ b/tests/PHPStan/shipmonk.neon @@ -1,10 +1,15 @@ rules: + - ShipMonk\PHPStan\Rule\BackedEnumGenericsRule + - ShipMonk\PHPStan\Rule\ForbidAssignmentNotMatchingVarDocRule + - ShipMonk\PHPStan\Rule\ForbidEnumInFunctionArgumentsRule - ShipMonk\PHPStan\Rule\ForbidFetchOnMixedRule - ShipMonk\PHPStan\Rule\ForbidMatchDefaultArmForEnumsRule - ShipMonk\PHPStan\Rule\ForbidMethodCallOnMixedRule - ShipMonk\PHPStan\Rule\ForbidReturnInConstructorRule - ShipMonk\PHPStan\Rule\ForbidUnsetClassFieldRule - ShipMonk\PHPStan\Rule\ForbidUnusedExceptionRule + - ShipMonk\PHPStan\Rule\ForbidUnusedMatchResultRule + - ShipMonk\PHPStan\Rule\ForbidVariableTypeOverwritingRule - ShipMonk\PHPStan\Rule\RequirePreviousExceptionPassRule services: @@ -12,3 +17,7 @@ services: type: ShipMonk\PHPStan\Visitor\UnusedExceptionVisitor tags: - phpstan.parser.richParserNodeVisitor + - + class: ShipMonk\PHPStan\Visitor\UnusedMatchVisitor + tags: + - phpstan.parser.richParserNodeVisitor