-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Should rules ignoring classes with empty findings
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\PHPat\unit\rules\ShouldExtend; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Relation\ShouldExtend\ParentClassRule; | ||
use PHPat\Rule\Assertion\Relation\ShouldExtend\ShouldExtend; | ||
use PHPat\Selector\Classname; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use PHPStan\Type\FileTypeMapper; | ||
use Tests\PHPat\fixtures\Simple\SimpleAbstractClass; | ||
use Tests\PHPat\fixtures\Simple\SimpleClass; | ||
use Tests\PHPat\unit\FakeTestParser; | ||
|
||
/** | ||
* @extends RuleTestCase<ParentClassRule> | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class SimpleParentClassTest extends RuleTestCase | ||
{ | ||
public const RULE_NAME = 'test_SimpleClassShouldExtendSimpleAbstractClass'; | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse(['tests/fixtures/Simple/SimpleClass.php'], [ | ||
[sprintf('%s should extend %s', SimpleClass::class, SimpleAbstractClass::class), 5], | ||
]); | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
$testParser = FakeTestParser::create( | ||
self::RULE_NAME, | ||
ShouldExtend::class, | ||
[new Classname(SimpleClass::class, false)], | ||
[new Classname(SimpleAbstractClass::class, false)] | ||
); | ||
|
||
return new ParentClassRule( | ||
new StatementBuilderFactory($testParser), | ||
new Configuration(false, true, false), | ||
$this->createReflectionProvider(), | ||
self::getContainer()->getByType(FileTypeMapper::class) | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/unit/rules/ShouldImplement/SimpleImplementedInterfacesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\PHPat\unit\rules\ShouldImplement; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Relation\ShouldImplement\ImplementedInterfacesRule; | ||
use PHPat\Rule\Assertion\Relation\ShouldImplement\ShouldImplement; | ||
use PHPat\Selector\Classname; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use PHPStan\Type\FileTypeMapper; | ||
use Tests\PHPat\fixtures\Simple\SimpleClass; | ||
use Tests\PHPat\fixtures\Simple\SimpleInterface; | ||
use Tests\PHPat\unit\FakeTestParser; | ||
|
||
/** | ||
* @extends RuleTestCase<ImplementedInterfacesRule> | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class SimpleImplementedInterfacesTest extends RuleTestCase | ||
{ | ||
public const RULE_NAME = 'test_SimpleClassShouldImplementSimpleInterface'; | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse(['tests/fixtures/Simple/SimpleClass.php'], [ | ||
[sprintf('%s should implement %s', SimpleClass::class, SimpleInterface::class), 5], | ||
]); | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
$testParser = FakeTestParser::create( | ||
self::RULE_NAME, | ||
ShouldImplement::class, | ||
[new Classname(SimpleClass::class, false)], | ||
[new Classname(SimpleInterface::class, false)] | ||
); | ||
|
||
return new ImplementedInterfacesRule( | ||
new StatementBuilderFactory($testParser), | ||
new Configuration(false, true, false), | ||
$this->createReflectionProvider(), | ||
self::getContainer()->getByType(FileTypeMapper::class) | ||
); | ||
} | ||
} |