diff --git a/ci/phpstan.neon b/ci/phpstan.neon index ca63e370..b174785c 100644 --- a/ci/phpstan.neon +++ b/ci/phpstan.neon @@ -3,3 +3,7 @@ parameters: paths: - ../src - ../tests/unit/rules + ignoreErrors: + - + message: "#no value type specified in iterable type array\\.$#" + path: * diff --git a/extension.neon b/extension.neon index 8919864c..e6a5f63c 100644 --- a/extension.neon +++ b/extension.neon @@ -18,6 +18,12 @@ services: # # # # # DECLARATION RULES # # # # # + # ShouldBeNamed rules + - + class: PHPat\Rule\Assertion\Declaration\ShouldBeNamed\ClassnameRule + tags: + - phpstan.rules.rule + # ShouldBeReadonly rules - class: PHPat\Rule\Assertion\Declaration\ShouldBeReadonly\IsReadonlyRule diff --git a/src/Rule/Assertion/Declaration/DeclarationAssertion.php b/src/Rule/Assertion/Declaration/DeclarationAssertion.php index d1aaaa44..94e90a77 100644 --- a/src/Rule/Assertion/Declaration/DeclarationAssertion.php +++ b/src/Rule/Assertion/Declaration/DeclarationAssertion.php @@ -16,7 +16,7 @@ abstract class DeclarationAssertion implements Assertion { - /** @var array, array}> */ + /** @var array, array, array}> */ protected array $statements; protected Configuration $configuration; protected ReflectionProvider $reflectionProvider; @@ -47,11 +47,17 @@ public function processNode(Node $node, Scope $scope): array return []; } - $meetsDeclaration = $this->meetsDeclaration($node, $scope); + $meetsDeclaration = $this->meetsDeclaration($node, $scope, $this->getParams()); return $this->validateGetErrors($scope, $meetsDeclaration); } + // TODO: This is a temporary hack, the 'statement' concept needs to be reworked + public function getParams(): array + { + return $this->statements[0][4] ?? []; + } + public function prepareMessage(string $ruleName, string $message): string { return $this->configuration->showRuleNames() @@ -59,18 +65,18 @@ public function prepareMessage(string $ruleName, string $message): string : $message; } - abstract protected function meetsDeclaration(Node $node, Scope $scope): bool; + abstract protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool; /** * @param class-string $subject */ - abstract protected function getMessage(string $ruleName, string $subject): string; + abstract protected function getMessage(string $ruleName, string $subject, array $params = []): string; /** * @param array $tips * @return array */ - abstract protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array; + abstract protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array; protected function ruleApplies(Scope $scope): bool { @@ -93,7 +99,7 @@ protected function validateGetErrors(Scope $scope, bool $meetsDeclaration): arra throw new ShouldNotHappenException(); } - foreach ($this->statements as [$ruleName, $selector, $subjectExcludes, $tips]) { + foreach ($this->statements as [$ruleName, $selector, $subjectExcludes, $tips, $params]) { if ($subject->isBuiltin() || !$selector->matches($subject)) { continue; } @@ -103,7 +109,7 @@ protected function validateGetErrors(Scope $scope, bool $meetsDeclaration): arra } } - array_push($errors, ...$this->applyValidation($ruleName, $subject, $meetsDeclaration, $tips)); + array_push($errors, ...$this->applyValidation($ruleName, $subject, $meetsDeclaration, $tips, $params)); } return $errors; diff --git a/src/Rule/Assertion/Declaration/ShouldBeAbstract/ShouldBeAbstract.php b/src/Rule/Assertion/Declaration/ShouldBeAbstract/ShouldBeAbstract.php index c0866388..7a41cc5e 100644 --- a/src/Rule/Assertion/Declaration/ShouldBeAbstract/ShouldBeAbstract.php +++ b/src/Rule/Assertion/Declaration/ShouldBeAbstract/ShouldBeAbstract.php @@ -29,12 +29,12 @@ public function __construct( ); } - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ShouldBeFinal/ShouldBeFinal.php b/src/Rule/Assertion/Declaration/ShouldBeFinal/ShouldBeFinal.php index f8149a2d..1aaa44e9 100644 --- a/src/Rule/Assertion/Declaration/ShouldBeFinal/ShouldBeFinal.php +++ b/src/Rule/Assertion/Declaration/ShouldBeFinal/ShouldBeFinal.php @@ -34,12 +34,12 @@ public function __construct( * @param array $tips * @return array */ - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ShouldBeInterface/ShouldBeInterface.php b/src/Rule/Assertion/Declaration/ShouldBeInterface/ShouldBeInterface.php index 9782aca3..19456541 100644 --- a/src/Rule/Assertion/Declaration/ShouldBeInterface/ShouldBeInterface.php +++ b/src/Rule/Assertion/Declaration/ShouldBeInterface/ShouldBeInterface.php @@ -34,12 +34,12 @@ public function __construct( * @param array $tips * @return array */ - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ShouldBeNamed/ClassnameRule.php b/src/Rule/Assertion/Declaration/ShouldBeNamed/ClassnameRule.php new file mode 100644 index 00000000..a62591d5 --- /dev/null +++ b/src/Rule/Assertion/Declaration/ShouldBeNamed/ClassnameRule.php @@ -0,0 +1,15 @@ + + */ +final class ClassnameRule extends ShouldBeNamed implements Rule +{ + use ClassnameExtractor; +} diff --git a/src/Rule/Assertion/Declaration/ShouldBeNamed/ShouldBeNamed.php b/src/Rule/Assertion/Declaration/ShouldBeNamed/ShouldBeNamed.php new file mode 100644 index 00000000..d15c7dd5 --- /dev/null +++ b/src/Rule/Assertion/Declaration/ShouldBeNamed/ShouldBeNamed.php @@ -0,0 +1,45 @@ +applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); + } + + protected function getMessage(string $ruleName, string $subject, array $params = []): string + { + $message = $params['isRegex'] === true + ? sprintf('%s should be named matching the regex %s', $subject, $params['classname']) + : sprintf('%s should be named %s', $subject, $params['classname']); + + return $this->prepareMessage($ruleName, $message); + } +} diff --git a/src/Rule/Assertion/Declaration/ShouldBeReadonly/ShouldBeReadonly.php b/src/Rule/Assertion/Declaration/ShouldBeReadonly/ShouldBeReadonly.php index 1f2b717e..a786f07f 100644 --- a/src/Rule/Assertion/Declaration/ShouldBeReadonly/ShouldBeReadonly.php +++ b/src/Rule/Assertion/Declaration/ShouldBeReadonly/ShouldBeReadonly.php @@ -34,12 +34,12 @@ public function __construct( * @param array $tips * @return array */ - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ShouldHaveOnlyOnePublicMethod/ShouldHaveOnlyOnePublicMethod.php b/src/Rule/Assertion/Declaration/ShouldHaveOnlyOnePublicMethod/ShouldHaveOnlyOnePublicMethod.php index 834544dd..cd705a1b 100644 --- a/src/Rule/Assertion/Declaration/ShouldHaveOnlyOnePublicMethod/ShouldHaveOnlyOnePublicMethod.php +++ b/src/Rule/Assertion/Declaration/ShouldHaveOnlyOnePublicMethod/ShouldHaveOnlyOnePublicMethod.php @@ -29,12 +29,12 @@ public function __construct( ); } - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShould($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage($ruleName, sprintf('%s should have only one public method', $subject)); } diff --git a/src/Rule/Assertion/Declaration/ShouldNotBeAbstract/ShouldNotBeAbstract.php b/src/Rule/Assertion/Declaration/ShouldNotBeAbstract/ShouldNotBeAbstract.php index 454f6508..aa1b9370 100644 --- a/src/Rule/Assertion/Declaration/ShouldNotBeAbstract/ShouldNotBeAbstract.php +++ b/src/Rule/Assertion/Declaration/ShouldNotBeAbstract/ShouldNotBeAbstract.php @@ -29,12 +29,12 @@ public function __construct( ); } - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShouldNot($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShouldNot($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ShouldNotBeFinal/ShouldNotBeFinal.php b/src/Rule/Assertion/Declaration/ShouldNotBeFinal/ShouldNotBeFinal.php index e31d54ab..130d6c4b 100644 --- a/src/Rule/Assertion/Declaration/ShouldNotBeFinal/ShouldNotBeFinal.php +++ b/src/Rule/Assertion/Declaration/ShouldNotBeFinal/ShouldNotBeFinal.php @@ -29,12 +29,12 @@ public function __construct( ); } - protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array { - return $this->applyShouldNot($ruleName, $subject, $meetsDeclaration, $tips); + return $this->applyShouldNot($ruleName, $subject, $meetsDeclaration, $tips, $params); } - protected function getMessage(string $ruleName, string $subject): string + protected function getMessage(string $ruleName, string $subject, array $params = []): string { return $this->prepareMessage( $ruleName, diff --git a/src/Rule/Assertion/Declaration/ValidationTrait.php b/src/Rule/Assertion/Declaration/ValidationTrait.php index ffc852b5..afef0cdb 100644 --- a/src/Rule/Assertion/Declaration/ValidationTrait.php +++ b/src/Rule/Assertion/Declaration/ValidationTrait.php @@ -12,16 +12,17 @@ trait ValidationTrait { /** * @param array $tips + * @param array $params * @return array * @throws ShouldNotHappenException */ - protected function applyShould(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyShould(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params): array { $errors = []; if (!$meetsDeclaration) { $ruleError = RuleErrorBuilder::message( - $this->getMessage($ruleName, $subject->getName()) + $this->getMessage($ruleName, $subject->getName(), $params) ); foreach ($tips as $tip) { @@ -35,16 +36,17 @@ protected function applyShould(string $ruleName, ClassReflection $subject, bool /** * @param array $tips + * @param array $params * @return array * @throws ShouldNotHappenException */ - protected function applyShouldNot(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips): array + protected function applyShouldNot(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params): array { $errors = []; if ($meetsDeclaration) { $ruleError = RuleErrorBuilder::message( - $this->getMessage($ruleName, $subject->getName()) + $this->getMessage($ruleName, $subject->getName(), $params) ); foreach ($tips as $tip) { diff --git a/src/Rule/Extractor/Declaration/AbstractExtractor.php b/src/Rule/Extractor/Declaration/AbstractExtractor.php index 17e217de..cb3cda4a 100644 --- a/src/Rule/Extractor/Declaration/AbstractExtractor.php +++ b/src/Rule/Extractor/Declaration/AbstractExtractor.php @@ -16,7 +16,7 @@ public function getNodeType(): string /** * @param InClassNode $node */ - protected function meetsDeclaration(Node $node, Scope $scope): bool + protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool { return $node->getClassReflection()->isAbstract(); } diff --git a/src/Rule/Extractor/Declaration/ClassnameExtractor.php b/src/Rule/Extractor/Declaration/ClassnameExtractor.php new file mode 100644 index 00000000..6acd61c7 --- /dev/null +++ b/src/Rule/Extractor/Declaration/ClassnameExtractor.php @@ -0,0 +1,32 @@ +getClassReflection()->getName(), '\\'); + $classname = $pos === false + ? $node->getClassReflection()->getName() + : mb_substr($node->getClassReflection()->getName(), $pos + 1); + + if ($params['isRegex'] === true) { + return preg_match($params['classname'], $classname) === 1; + } + + return $classname === $params['classname']; + } +} diff --git a/src/Rule/Extractor/Declaration/FinalExtractor.php b/src/Rule/Extractor/Declaration/FinalExtractor.php index e8d4fa07..bf966210 100644 --- a/src/Rule/Extractor/Declaration/FinalExtractor.php +++ b/src/Rule/Extractor/Declaration/FinalExtractor.php @@ -16,7 +16,7 @@ public function getNodeType(): string /** * @param InClassNode $node */ - protected function meetsDeclaration(Node $node, Scope $scope): bool + protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool { return $node->getClassReflection()->isFinal(); } diff --git a/src/Rule/Extractor/Declaration/InterfaceExtractor.php b/src/Rule/Extractor/Declaration/InterfaceExtractor.php index c46c3a5a..883aec3b 100644 --- a/src/Rule/Extractor/Declaration/InterfaceExtractor.php +++ b/src/Rule/Extractor/Declaration/InterfaceExtractor.php @@ -16,7 +16,7 @@ public function getNodeType(): string /** * @param InClassNode $node */ - protected function meetsDeclaration(Node $node, Scope $scope): bool + protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool { return $node->getClassReflection()->isInterface(); } diff --git a/src/Rule/Extractor/Declaration/OnePublicMethodExtractor.php b/src/Rule/Extractor/Declaration/OnePublicMethodExtractor.php index f854267c..d562aac6 100644 --- a/src/Rule/Extractor/Declaration/OnePublicMethodExtractor.php +++ b/src/Rule/Extractor/Declaration/OnePublicMethodExtractor.php @@ -16,7 +16,7 @@ public function getNodeType(): string /** * @param InClassNode $node */ - protected function meetsDeclaration(Node $node, Scope $scope): bool + protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool { $reflectionClass = $node->getClassReflection()->getNativeReflection(); $methods = $reflectionClass->getMethods(1); diff --git a/src/Rule/Extractor/Declaration/ReadonlyExtractor.php b/src/Rule/Extractor/Declaration/ReadonlyExtractor.php index c5fc93b5..3c3b3f8d 100644 --- a/src/Rule/Extractor/Declaration/ReadonlyExtractor.php +++ b/src/Rule/Extractor/Declaration/ReadonlyExtractor.php @@ -16,7 +16,7 @@ public function getNodeType(): string /** * @param InClassNode $node */ - protected function meetsDeclaration(Node $node, Scope $scope): bool + protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool { return $node->getClassReflection()->isReadOnly(); } diff --git a/src/Statement/Builder/DeclarationStatementBuilder.php b/src/Statement/Builder/DeclarationStatementBuilder.php index f902a9c9..d8c2982b 100644 --- a/src/Statement/Builder/DeclarationStatementBuilder.php +++ b/src/Statement/Builder/DeclarationStatementBuilder.php @@ -10,7 +10,7 @@ final class DeclarationStatementBuilder implements StatementBuilder { - /** @var array, array}> */ + /** @var array, array, array}> */ private array $statements = []; /** @var array */ @@ -30,14 +30,14 @@ public function __construct(string $assertion, array $rules) } /** - * @return array, array}> + * @return array, array, array}> */ public function build(): array { $params = $this->extractCurrentAssertion($this->rules); foreach ($params as $param) { - $this->addStatement($param[0], $param[1], $param[2], $param[3]); + $this->addStatement($param[0], $param[1], $param[2], $param[3], $param[4]); } return $this->statements; @@ -46,19 +46,21 @@ public function build(): array /** * @param array $subjectExcludes * @param array $tips + * @param array $params */ private function addStatement( string $ruleName, SelectorInterface $subject, array $subjectExcludes, - array $tips + array $tips, + array $params ): void { - $this->statements[] = [$ruleName, $subject, $subjectExcludes, $tips]; + $this->statements[] = [$ruleName, $subject, $subjectExcludes, $tips, $params]; } /** - * @param array $rules - * @return array, array}> + * @param array $rules + * @return array, array, array}> */ private function extractCurrentAssertion(array $rules): array { @@ -67,7 +69,7 @@ private function extractCurrentAssertion(array $rules): array if ($rule->getAssertion() === $this->assertion) { $ruleName = $this->extractRuleName($rule->getRuleName()); foreach ($rule->getSubjects() as $selector) { - $result[] = [$ruleName, $selector, $rule->getSubjectExcludes(), $rule->getTips()]; + $result[] = [$ruleName, $selector, $rule->getSubjectExcludes(), $rule->getTips(), $rule->getParams()]; } } } diff --git a/src/Test/Builder/AssertionStep.php b/src/Test/Builder/AssertionStep.php index f75cdaec..28166c07 100644 --- a/src/Test/Builder/AssertionStep.php +++ b/src/Test/Builder/AssertionStep.php @@ -4,6 +4,7 @@ use PHPat\Rule\Assertion\Declaration\ShouldBeAbstract\ShouldBeAbstract; use PHPat\Rule\Assertion\Declaration\ShouldBeFinal\ShouldBeFinal; +use PHPat\Rule\Assertion\Declaration\ShouldBeNamed\ShouldBeNamed; use PHPat\Rule\Assertion\Declaration\ShouldBeInterface\ShouldBeInterface; use PHPat\Rule\Assertion\Declaration\ShouldBeReadonly\ShouldBeReadonly; use PHPat\Rule\Assertion\Declaration\ShouldHaveOnlyOnePublicMethod\ShouldHaveOnlyOnePublicMethod; @@ -20,6 +21,14 @@ class AssertionStep extends AbstractStep { + public function shouldBeNamed(string $classname, bool $regex = false): Rule + { + $this->rule->assertion = ShouldBeNamed::class; + $this->rule->params = ['isRegex' => $regex, 'classname' => $classname]; + + return new BuildStep($this->rule); + } + public function shouldBeAbstract(): Rule { $this->rule->assertion = ShouldBeAbstract::class; diff --git a/src/Test/DeclarationRule.php b/src/Test/DeclarationRule.php index 06027d54..70c6529c 100644 --- a/src/Test/DeclarationRule.php +++ b/src/Test/DeclarationRule.php @@ -55,4 +55,9 @@ public function getTips(): array { return []; } + + public function getParams(): array + { + return []; + } } diff --git a/src/Test/RelationRule.php b/src/Test/RelationRule.php index 7d9e1130..e74b7bef 100644 --- a/src/Test/RelationRule.php +++ b/src/Test/RelationRule.php @@ -28,6 +28,9 @@ final class RelationRule implements Rule /** @var array */ public array $tips = []; + /** @var array */ + public array $params = []; + /** * @return null|class-string|class-string */ @@ -65,4 +68,9 @@ public function getTips(): array { return $this->tips; } + + public function getParams(): array + { + return $this->params; + } } diff --git a/src/Test/Rule.php b/src/Test/Rule.php index 4c15ce8d..e90e2279 100644 --- a/src/Test/Rule.php +++ b/src/Test/Rule.php @@ -38,4 +38,9 @@ public function getRuleName(): string; * @return array */ public function getTips(): array; + + /** + * @return array + */ + public function getParams(): array; } diff --git a/tests/unit/FakeTestParser.php b/tests/unit/FakeTestParser.php index d65abcd0..451f4906 100644 --- a/tests/unit/FakeTestParser.php +++ b/tests/unit/FakeTestParser.php @@ -23,6 +23,9 @@ class FakeTestParser extends TestParser /** @var array */ public array $tips = []; + /** @var array */ + public array $params = []; + public function __invoke(): array { $rule = new RelationRule(); @@ -31,6 +34,7 @@ public function __invoke(): array $rule->subjects = $this->subjects; $rule->targets = $this->targets; $rule->tips = $this->tips; + $rule->params = $this->params; return [$rule]; } @@ -40,8 +44,9 @@ public function __invoke(): array * @param array $subjects * @param array $targets * @param array $tips + * @param array $params */ - public static function create(string $ruleName, string $assertion, array $subjects, array $targets, array $tips = []): self + public static function create(string $ruleName, string $assertion, array $subjects, array $targets, array $tips = [], array $params = []): self { /** @var self $self */ $self = (new \ReflectionClass(self::class))->newInstanceWithoutConstructor(); @@ -50,6 +55,7 @@ public static function create(string $ruleName, string $assertion, array $subjec $self->subjects = $subjects; $self->targets = $targets; $self->tips = $tips; + $self->params = $params; return $self; } diff --git a/tests/unit/rules/ShouldBeNamed/ClassnameTest.php b/tests/unit/rules/ShouldBeNamed/ClassnameTest.php new file mode 100644 index 00000000..24a04378 --- /dev/null +++ b/tests/unit/rules/ShouldBeNamed/ClassnameTest.php @@ -0,0 +1,50 @@ + + * @internal + * @coversNothing + */ +class ClassnameTest extends RuleTestCase +{ + public const RULE_NAME = 'test_FixtureClassShouldBeNamed'; + + public function testRule(): void + { + $this->analyse(['tests/fixtures/FixtureClass.php'], [ + [sprintf('%s should be named SuperCoolClass', FixtureClass::class), 29], + ]); + } + + protected function getRule(): Rule + { + $testParser = FakeTestParser::create( + self::RULE_NAME, + ShouldBeNamed::class, + [new Classname(FixtureClass::class, false)], + [], + [], + ['isRegex' => false, 'classname' => 'SuperCoolClass'] + ); + + return new ClassnameRule( + new StatementBuilderFactory($testParser), + new Configuration(false, true, false), + $this->createReflectionProvider(), + self::getContainer()->getByType(FileTypeMapper::class) + ); + } +} diff --git a/tests/unit/tips/Relation/MultipleTipTest.php b/tests/unit/tips/Relation/MultipleTipTest.php index fcf687d3..600b95ea 100644 --- a/tests/unit/tips/Relation/MultipleTipTest.php +++ b/tests/unit/tips/Relation/MultipleTipTest.php @@ -30,8 +30,8 @@ public function testRule(): void \sprintf('%s should not depend on %s', FixtureClass::class, SimpleAttribute::class), 29, <<<'TIPS' - • #tip 1 - • #tip 2 + • tip #1 + • tip #2 TIPS, ], ]); @@ -44,7 +44,7 @@ protected function getRule(): Rule CanOnlyDepend::class, [new Classname(FixtureClass::class, false)], [new Classname(\Attribute::class, false)], - ['#tip 1', '#tip 2'] + ['tip #1', 'tip #2'] ); return new ClassAttributeRule(