-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix namespace selector matching similar namespaces
- Loading branch information
Showing
5 changed files
with
67 additions
and
8 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
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,5 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\PHPat\fixtures\Ns\Foo; | ||
|
||
class ClassUnderFooNamespace {} |
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,5 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\PHPat\fixtures\Ns\FooBar; | ||
|
||
class ClassUnderFooBarNamespace {} |
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\ShouldBeNamed; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Declaration\ShouldBeNamed\ClassnameRule; | ||
use PHPat\Rule\Assertion\Declaration\ShouldBeNamed\ShouldBeNamed; | ||
use PHPat\Selector\ClassNamespace; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use PHPStan\Type\FileTypeMapper; | ||
use Tests\PHPat\fixtures\Ns\Foo\ClassUnderFooNamespace; | ||
use Tests\PHPat\unit\FakeTestParser; | ||
|
||
/** | ||
* @extends RuleTestCase<ClassnameRule> | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class ClassnamespaceTest extends RuleTestCase | ||
{ | ||
public const RULE_NAME = 'test_FixtureClassUnderNamespaceShouldBeNamed'; | ||
|
||
public function testRule(): void | ||
{ | ||
// Class under FooBar should not subject to the rule | ||
$this->analyse(['tests/fixtures/Ns/FooBar/ClassUnderFooBarNamespace.php'], []); | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
$testParser = FakeTestParser::create( | ||
self::RULE_NAME, | ||
ShouldBeNamed::class, | ||
[new ClassNamespace('Tests\PHPat\fixtures\Ns\Foo', false)], | ||
[], | ||
[], | ||
['isRegex' => false, 'classname' => ClassUnderFooNamespace::class] | ||
); | ||
|
||
return new ClassnameRule( | ||
new StatementBuilderFactory($testParser), | ||
new Configuration(false, true, false), | ||
$this->createReflectionProvider(), | ||
self::getContainer()->getByType(FileTypeMapper::class) | ||
); | ||
} | ||
} |