Skip to content

Commit

Permalink
Enable new shipmonk phpstan rules
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Oct 23, 2022
1 parent 7efef52 commit 31e5ef6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/AutocompleteInput/AutocompleteInputTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ declare(strict_types = 1);

namespace NepadaTests\AutocompleteInput;

use Nepada;
use NepadaTests\AutocompleteInput\Fixtures\TestPresenter;
use NepadaTests\TestCase;
use Nette\Application;
Expand All @@ -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');

Expand All @@ -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);

Expand All @@ -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());
}

Expand All @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions tests/AutocompleteInput/Fixtures/TestPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
9 changes: 9 additions & 0 deletions tests/PHPStan/shipmonk.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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:
-
type: ShipMonk\PHPStan\Visitor\UnusedExceptionVisitor
tags:
- phpstan.parser.richParserNodeVisitor
-
class: ShipMonk\PHPStan\Visitor\UnusedMatchVisitor
tags:
- phpstan.parser.richParserNodeVisitor

0 comments on commit 31e5ef6

Please sign in to comment.