diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index cec91069..5ea44f9d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,6 +9,7 @@ ->setFinder($finder) ->setRiskyAllowed(true) ->setRules([ + '@PER-CS' => true, '@Symfony' => true, '@Symfony:risky' => true, '@PHP71Migration:risky' => true, @@ -39,5 +40,8 @@ 'list_syntax' => ['syntax' => 'short'], 'phpdoc_to_comment' => false, 'php_unit_method_casing' => ['case' => 'snake_case'], - 'function_to_constant' => false + 'function_to_constant' => false, + 'php_unit_data_provider_static' => true , + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], + 'phpdoc_array_type' => true ]); diff --git a/composer.json b/composer.json index 14690e11..46ef4116 100644 --- a/composer.json +++ b/composer.json @@ -34,13 +34,13 @@ "ondram/ci-detector": "^4.1" }, "require-dev": { - "roave/security-advisories": "dev-master", - "symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0", - "phpunit/phpunit": "^7.5|^9.0|^10.0", + "friendsofphp/php-cs-fixer": "^3.75", "mikey179/vfsstream": "^1.6", "phpspec/prophecy": "^1.10", - "friendsofphp/php-cs-fixer": "3.4.0", - "phpspec/prophecy-phpunit": "^2.3" + "phpspec/prophecy-phpunit": "^2.3", + "phpunit/phpunit": "^7.5|^9.0|^10.0", + "roave/security-advisories": "dev-master", + "symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0" }, "autoload": { "psr-4": { diff --git a/src/Analyzer/FileParser.php b/src/Analyzer/FileParser.php index 4fe16652..6b18202c 100644 --- a/src/Analyzer/FileParser.php +++ b/src/Analyzer/FileParser.php @@ -19,7 +19,7 @@ class FileParser implements Parser private FileVisitor $fileVisitor; - /** @var ParsingError[] */ + /** @var array */ private array $parsingErrors; public function __construct( @@ -38,7 +38,7 @@ public function __construct( } /** - * @return ClassDescription[] + * @return array */ public function getClassDescriptions(): array { diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php index c2db3019..75889843 100644 --- a/src/Analyzer/FileVisitor.php +++ b/src/Analyzer/FileVisitor.php @@ -13,7 +13,7 @@ class FileVisitor extends NodeVisitorAbstract { private ClassDescriptionBuilder $classDescriptionBuilder; - /** @var ClassDescription[] */ + /** @var array */ private array $classDescriptions = []; public function __construct(ClassDescriptionBuilder $classDescriptionBuilder) diff --git a/src/Analyzer/NameResolver.php b/src/Analyzer/NameResolver.php index 642c773d..295b6bac 100644 --- a/src/Analyzer/NameResolver.php +++ b/src/Analyzer/NameResolver.php @@ -329,7 +329,6 @@ protected function resolveAttrGroups(Node $node): void /** * @param Stmt\Use_::TYPE_* $type - * @param ?Name $prefix * * @psalm-suppress PossiblyNullArgument */ diff --git a/src/CLI/Command/Check.php b/src/CLI/Command/Check.php index 845eb87f..43c2652e 100644 --- a/src/CLI/Command/Check.php +++ b/src/CLI/Command/Check.php @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $rulesFilename = $this->getConfigFilename($input); if (!$onlyErrors) { - $output->writeln(sprintf("Config file: %s\n", $rulesFilename)); + $output->writeln(\sprintf("Config file: %s\n", $rulesFilename)); } $config = new Config(); @@ -267,9 +267,9 @@ private function printViolations(Violations $violations, OutputInterface $output $output->writeln('ERRORS!'); } - $output->writeln(sprintf('%s', $violations->toString($format))); + $output->writeln(\sprintf('%s', $violations->toString($format))); if (!$onlyErrors) { - $output->writeln(sprintf('%s VIOLATIONS DETECTED!', \count($violations))); + $output->writeln(\sprintf('%s VIOLATIONS DETECTED!', \count($violations))); } } @@ -278,7 +278,7 @@ private function printParsedErrors(ParsingErrors $parsingErrors, OutputInterface if (!$onlyErrors) { $output->writeln('ERROR ON PARSING THESE FILES:'); } - $output->writeln(sprintf('%s', $parsingErrors->toString())); + $output->writeln(\sprintf('%s', $parsingErrors->toString())); } private function printNoViolationsDetectedMessage(OutputInterface $output, bool $onlyErrors = false, string $format = Printer::FORMAT_TEXT): void diff --git a/src/CLI/PhpArkitectApplication.php b/src/CLI/PhpArkitectApplication.php index 76b69786..0047cf50 100644 --- a/src/CLI/PhpArkitectApplication.php +++ b/src/CLI/PhpArkitectApplication.php @@ -10,14 +10,13 @@ class PhpArkitectApplication extends \Symfony\Component\Console\Application { - /** @var string */ - private static $logo = <<< 'EOD' - ____ _ _ ____ _ _ _ _ _ - | _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_ - | |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __| - | __/| _ | __/ ___ \| | | <| | || __/ (__| |_ - |_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__| -EOD; + private static string $logo = <<< 'EOD' + ____ _ _ ____ _ _ _ _ _ + | _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_ + | |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __| + | __/| _ | __/ ___ \| | | <| | || __/ (__| |_ + |_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__| + EOD; public function __construct() { @@ -29,6 +28,6 @@ public function __construct() public function getLongVersion(): string { - return sprintf("%s\n\n%s version %s", self::$logo, $this->getName(), $this->getVersion()); + return \sprintf("%s\n\n%s version %s", self::$logo, $this->getName(), $this->getVersion()); } } diff --git a/src/CLI/Printer/GitlabPrinter.php b/src/CLI/Printer/GitlabPrinter.php index 35dc486f..c1aee892 100644 --- a/src/CLI/Printer/GitlabPrinter.php +++ b/src/CLI/Printer/GitlabPrinter.php @@ -12,8 +12,8 @@ public function print(array $violationsCollection): string $allErrors = []; /** - * @var string $key - * @var Violation[] $violationsByFqcn + * @var string $key + * @var array $violationsByFqcn */ foreach ($violationsCollection as $class => $violationsByFqcn) { foreach ($violationsByFqcn as $violation) { diff --git a/src/CLI/Printer/JsonPrinter.php b/src/CLI/Printer/JsonPrinter.php index d5cb9cbd..57772ca9 100644 --- a/src/CLI/Printer/JsonPrinter.php +++ b/src/CLI/Printer/JsonPrinter.php @@ -13,8 +13,8 @@ public function print(array $violationsCollection): string $details = []; /** - * @var string $key - * @var Violation[] $violationsByFqcn + * @var string $key + * @var array $violationsByFqcn */ foreach ($violationsCollection as $class => $violationsByFqcn) { $violationForThisFqcn = \count($violationsByFqcn); diff --git a/src/CLI/Printer/TextPrinter.php b/src/CLI/Printer/TextPrinter.php index dd47e874..e0059f7e 100644 --- a/src/CLI/Printer/TextPrinter.php +++ b/src/CLI/Printer/TextPrinter.php @@ -12,8 +12,8 @@ public function print(array $violationsCollection): string $errors = ''; /** - * @var string $key - * @var Violation[] $violationsByFqcn + * @var string $key + * @var array $violationsByFqcn */ foreach ($violationsCollection as $key => $violationsByFqcn) { $violationForThisFqcn = \count($violationsByFqcn); diff --git a/src/ClassSet.php b/src/ClassSet.php index a6f091f4..42d0873c 100644 --- a/src/ClassSet.php +++ b/src/ClassSet.php @@ -11,7 +11,7 @@ */ class ClassSet implements \IteratorAggregate { - /** @var string[] */ + /** @var array */ private array $directoryList; private array $exclude; diff --git a/src/ClassSetRules.php b/src/ClassSetRules.php index 12e67b8c..9c72e704 100644 --- a/src/ClassSetRules.php +++ b/src/ClassSetRules.php @@ -10,7 +10,7 @@ class ClassSetRules { private ClassSet $classSet; - /** @var ArchRule[] */ + /** @var array */ private array $rules; private function __construct(ClassSet $classSet, ArchRule ...$rules) diff --git a/src/Exceptions/IndexNotFoundException.php b/src/Exceptions/IndexNotFoundException.php index e7b0e927..0a643a41 100644 --- a/src/Exceptions/IndexNotFoundException.php +++ b/src/Exceptions/IndexNotFoundException.php @@ -7,6 +7,6 @@ class IndexNotFoundException extends \Exception { public function __construct(int $index) { - parent::__construct(sprintf('Index not found %d', $index)); + parent::__construct(\sprintf('Index not found %d', $index)); } } diff --git a/src/Exceptions/PhpVersionNotValidException.php b/src/Exceptions/PhpVersionNotValidException.php index bdbefbc3..4f3f7348 100644 --- a/src/Exceptions/PhpVersionNotValidException.php +++ b/src/Exceptions/PhpVersionNotValidException.php @@ -7,6 +7,6 @@ class PhpVersionNotValidException extends \Exception { public function __construct(string $phpVersion) { - parent::__construct(sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion)); + parent::__construct(\sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion)); } } diff --git a/src/Expression/Expression.php b/src/Expression/Expression.php index bd727dde..6a7bb98f 100644 --- a/src/Expression/Expression.php +++ b/src/Expression/Expression.php @@ -29,7 +29,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti * * Not included directly in the interface to allow incremental implementation of it in the rules. */ - //public function appliesTo(ClassDescription $theClass): bool; + // public function appliesTo(ClassDescription $theClass): bool; /** * Evaluates the expression for the class passed as parameter. diff --git a/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php b/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php index 8cc05808..4b647254 100644 --- a/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php +++ b/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php @@ -14,7 +14,7 @@ class DependsOnlyOnTheseNamespaces implements Expression { - /** @var string[] */ + /** @var array */ private array $namespaces; public function __construct(string ...$namespace) diff --git a/src/Expression/ForClasses/Extend.php b/src/Expression/ForClasses/Extend.php index 9256924a..f3aaba09 100644 --- a/src/Expression/ForClasses/Extend.php +++ b/src/Expression/ForClasses/Extend.php @@ -13,7 +13,7 @@ class Extend implements Expression { - /** @var string[] */ + /** @var array */ private array $classNames; public function __construct(string ...$classNames) diff --git a/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php b/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php index 474315d1..e9ee5b48 100644 --- a/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php +++ b/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php @@ -14,7 +14,7 @@ class NotDependsOnTheseNamespaces implements Expression { - /** @var string[] */ + /** @var array */ private array $namespaces; public function __construct(string ...$namespace) diff --git a/src/Expression/ForClasses/NotExtend.php b/src/Expression/ForClasses/NotExtend.php index 7ff922ea..81ea0b1d 100644 --- a/src/Expression/ForClasses/NotExtend.php +++ b/src/Expression/ForClasses/NotExtend.php @@ -13,7 +13,7 @@ class NotExtend implements Expression { - /** @var string[] */ + /** @var array */ private array $classNames; public function __construct(string ...$classNames) diff --git a/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php b/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php index dcaddd35..4501d6e1 100644 --- a/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php +++ b/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php @@ -16,7 +16,7 @@ class NotHaveDependencyOutsideNamespace implements Expression { private string $namespace; - /** @var string[] */ + /** @var array */ private array $externalDependenciesToExclude; private bool $excludeCoreNamespace; diff --git a/src/Expression/ForClasses/NotResideInTheseNamespaces.php b/src/Expression/ForClasses/NotResideInTheseNamespaces.php index fbee628e..732e831d 100644 --- a/src/Expression/ForClasses/NotResideInTheseNamespaces.php +++ b/src/Expression/ForClasses/NotResideInTheseNamespaces.php @@ -13,7 +13,7 @@ class NotResideInTheseNamespaces implements Expression { - /** @var string[] */ + /** @var array */ private $namespaces; public function __construct(string ...$namespaces) diff --git a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php index fd6a54b7..38babbf2 100644 --- a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php +++ b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php @@ -13,7 +13,7 @@ class ResideInOneOfTheseNamespaces implements Expression { - /** @var string[] */ + /** @var array */ private $namespaces; public function __construct(string ...$namespaces) diff --git a/src/RuleBuilders/Architecture/Architecture.php b/src/RuleBuilders/Architecture/Architecture.php index 4a0714c2..22a95d6e 100644 --- a/src/RuleBuilders/Architecture/Architecture.php +++ b/src/RuleBuilders/Architecture/Architecture.php @@ -14,9 +14,9 @@ class Architecture implements Component, DefinedBy, Where, MayDependOnComponents private $componentName; /** @var array */ private $componentSelectors; - /** @var array */ + /** @var array> */ private $allowedDependencies; - /** @var array */ + /** @var array> */ private $componentDependsOnlyOnTheseNamespaces; private function __construct() diff --git a/src/RuleBuilders/Architecture/MayDependOnComponents.php b/src/RuleBuilders/Architecture/MayDependOnComponents.php index 70f004bf..a7149759 100644 --- a/src/RuleBuilders/Architecture/MayDependOnComponents.php +++ b/src/RuleBuilders/Architecture/MayDependOnComponents.php @@ -8,7 +8,7 @@ interface MayDependOnComponents /** * May depend on the specified components, plus itself. * - * @param string[] $componentNames + * @param array $componentNames * * @return Where&Rules */ diff --git a/src/RuleBuilders/Architecture/ShouldOnlyDependOnComponents.php b/src/RuleBuilders/Architecture/ShouldOnlyDependOnComponents.php index f1f2a625..b2372993 100644 --- a/src/RuleBuilders/Architecture/ShouldOnlyDependOnComponents.php +++ b/src/RuleBuilders/Architecture/ShouldOnlyDependOnComponents.php @@ -8,7 +8,7 @@ interface ShouldOnlyDependOnComponents /** * May depend ONLY on the specified components, thus it can only depend on itself if itself is specified. * - * @param string[] $componentNames + * @param array $componentNames * * @return Where&Rules */ diff --git a/src/Rules/ParsingErrors.php b/src/Rules/ParsingErrors.php index bc475037..2716e5c0 100644 --- a/src/Rules/ParsingErrors.php +++ b/src/Rules/ParsingErrors.php @@ -12,7 +12,7 @@ class ParsingErrors implements \IteratorAggregate, \Countable { /** - * @var ParsingError[] + * @var array */ private $parsingErrors; diff --git a/src/Rules/Violations.php b/src/Rules/Violations.php index 6289565f..8256afa0 100644 --- a/src/Rules/Violations.php +++ b/src/Rules/Violations.php @@ -13,7 +13,7 @@ class Violations implements \IteratorAggregate, \Countable, \JsonSerializable { /** - * @var Violation[] + * @var array */ private array $violations; diff --git a/tests/E2E/Cli/CheckCommandTest.php b/tests/E2E/Cli/CheckCommandTest.php index 7ca155af..7f3f1f3d 100644 --- a/tests/E2E/Cli/CheckCommandTest.php +++ b/tests/E2E/Cli/CheckCommandTest.php @@ -176,7 +176,7 @@ public function test_json_format_output(): void $display = $cmdTester->getDisplay(); - $this->assertJson($display); + self::assertJson($display); } public function test_json_format_output_no_errors(): void @@ -189,10 +189,10 @@ public function test_json_format_output_no_errors(): void $display = $cmdTester->getDisplay(); - $this->assertJson($display); + self::assertJson($display); $json = json_decode($display, true); - $this->assertCount(0, $json); + self::assertCount(0, $json); } public function test_gitlab_format_output(): void @@ -205,7 +205,7 @@ public function test_gitlab_format_output(): void $display = $cmdTester->getDisplay(); - $this->assertJson($display); + self::assertJson($display); self::assertSame(<<getDisplay(); - $this->assertJson($display); + self::assertJson($display); $json = json_decode($display, true); - $this->assertCount(0, $json); + self::assertCount(0, $json); } protected function runCheck( @@ -274,27 +274,27 @@ protected function runCheck( protected function assertCheckHasErrors(ApplicationTester $applicationTester, ?string $expectedOutput = null): void { - $this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode()); + self::assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode()); if (null != $expectedOutput) { $actualOutput = str_replace(["\r", "\n"], '', $applicationTester->getDisplay()); $expectedOutput = str_replace(["\r", "\n"], '', $expectedOutput); - $this->assertStringContainsString($expectedOutput, $actualOutput); + self::assertStringContainsString($expectedOutput, $actualOutput); } } protected function assertCheckHasNoErrorsLike(ApplicationTester $applicationTester, ?string $expectedOutput = null): void { - $this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode()); + self::assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode()); if (null != $expectedOutput) { $actualOutput = str_replace(["\r", "\n"], '', $applicationTester->getDisplay()); $expectedOutput = str_replace(["\r", "\n"], '', $expectedOutput); - $this->assertStringNotContainsString($expectedOutput, $actualOutput); + self::assertStringNotContainsString($expectedOutput, $actualOutput); } } protected function assertCheckHasSuccess(ApplicationTester $applicationTester): void { - $this->assertEquals(self::SUCCESS_CODE, $applicationTester->getStatusCode(), 'Command failed: '.$applicationTester->getDisplay()); - $this->assertStringNotContainsString('ERRORS!', $applicationTester->getDisplay(), 'Error message not expected in successful execution'); + self::assertEquals(self::SUCCESS_CODE, $applicationTester->getStatusCode(), 'Command failed: '.$applicationTester->getDisplay()); + self::assertStringNotContainsString('ERRORS!', $applicationTester->getDisplay(), 'Error message not expected in successful execution'); } } diff --git a/tests/E2E/Cli/DebugExpressionCommandTest.php b/tests/E2E/Cli/DebugExpressionCommandTest.php index 4fa0aee0..1eb73fd6 100644 --- a/tests/E2E/Cli/DebugExpressionCommandTest.php +++ b/tests/E2E/Cli/DebugExpressionCommandTest.php @@ -14,55 +14,55 @@ public function test_you_need_to_specify_the_expression(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression']); - $this->assertEquals(1, $appTester->getStatusCode()); + self::assertEquals(1, $appTester->getStatusCode()); } public function test_zero_results(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'Extend', 'arguments' => ['NotFound'], '--from-dir' => __DIR__]); - $this->assertEquals('', $appTester->getDisplay()); - $this->assertEquals(0, $appTester->getStatusCode()); + self::assertEquals('', $appTester->getDisplay()); + self::assertEquals(0, $appTester->getStatusCode()); } public function test_some_classes_found(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'NotExtend', 'arguments' => ['NotFound'], '--from-dir' => __DIR__.'/../_fixtures/mvc/Domain']); - $this->assertEquals("App\Domain\Model\n", $appTester->getDisplay()); - $this->assertEquals(0, $appTester->getStatusCode()); + self::assertEquals("App\Domain\Model\n", $appTester->getDisplay()); + self::assertEquals(0, $appTester->getStatusCode()); } public function test_meaningful_errors_for_too_few_arguments_for_the_expression(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'NotImplement', 'arguments' => [], '--from-dir' => __DIR__.'/../_fixtures/mvc/Domain']); - $this->assertEquals("Error: Too few arguments for 'NotImplement'.\n", $appTester->getDisplay()); - $this->assertEquals(2, $appTester->getStatusCode()); + self::assertEquals("Error: Too few arguments for 'NotImplement'.\n", $appTester->getDisplay()); + self::assertEquals(2, $appTester->getStatusCode()); } public function test_meaningful_errors_for_too_many_arguments_for_the_expression(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'NotImplement', 'arguments' => ['First', 'Second'], '--from-dir' => __DIR__.'/../_fixtures/mvc/Domain']); - $this->assertEquals("Error: Too many arguments for 'NotImplement'.\n", $appTester->getDisplay()); - $this->assertEquals(2, $appTester->getStatusCode()); + self::assertEquals("Error: Too many arguments for 'NotImplement'.\n", $appTester->getDisplay()); + self::assertEquals(2, $appTester->getStatusCode()); } public function test_optional_argument_for_expression_can_be_avoided(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'NotHaveDependencyOutsideNamespace', 'arguments' => ['NotFound'], '--from-dir' => __DIR__]); - $this->assertEquals('', $appTester->getDisplay()); - $this->assertEquals(0, $appTester->getStatusCode()); + self::assertEquals('', $appTester->getDisplay()); + self::assertEquals(0, $appTester->getStatusCode()); } public function test_expression_not_found(): void { $appTester = $this->createAppTester(); $appTester->run(['debug:expression', 'expression' => 'blabla', 'arguments' => ['NotFound'], '--from-dir' => __DIR__]); - $this->assertEquals("Error: Expression 'blabla' not found.\n", $appTester->getDisplay()); - $this->assertEquals(2, $appTester->getStatusCode()); + self::assertEquals("Error: Expression 'blabla' not found.\n", $appTester->getDisplay()); + self::assertEquals(2, $appTester->getStatusCode()); } public function test_parse_error_dont_stop_execution(): void @@ -77,8 +77,8 @@ public function test_parse_error_dont_stop_execution(): void App\Services\UserService END; - $this->assertEquals($errorMessage, $appTester->getDisplay()); - $this->assertEquals(0, $appTester->getStatusCode()); + self::assertEquals($errorMessage, $appTester->getDisplay()); + self::assertEquals(0, $appTester->getStatusCode()); } private function createAppTester(): ApplicationTester diff --git a/tests/E2E/Cli/InitCommandTest.php b/tests/E2E/Cli/InitCommandTest.php index 947c5e75..823c305c 100644 --- a/tests/E2E/Cli/InitCommandTest.php +++ b/tests/E2E/Cli/InitCommandTest.php @@ -19,9 +19,9 @@ public function test_it_creates_a_file_in_default_dir(): void $output = $appTester->getDisplay(); - $this->assertFileExists($fs.'/phparkitect.php'); - $this->assertStringContainsString('Creating phparkitect.php file...', $output); - $this->assertStringContainsString('customize it and run with php bin/phparkitect check', $output); + self::assertFileExists($fs.'/phparkitect.php'); + self::assertStringContainsString('Creating phparkitect.php file...', $output); + self::assertStringContainsString('customize it and run with php bin/phparkitect check', $output); } public function test_it_creates_a_file_in_a_custom_dir(): void @@ -38,9 +38,9 @@ public function test_it_creates_a_file_in_a_custom_dir(): void $output = $appTester->getDisplay(); - $this->assertFileExists($fs.'/nested/path/phparkitect.php'); - $this->assertStringContainsString('Creating phparkitect.php file...', $output); - $this->assertStringContainsString('customize it and run with php bin/phparkitect check', $output); + self::assertFileExists($fs.'/nested/path/phparkitect.php'); + self::assertStringContainsString('Creating phparkitect.php file...', $output); + self::assertStringContainsString('customize it and run with php bin/phparkitect check', $output); } public function test_do_nothing_if_file_exists(): void @@ -57,7 +57,7 @@ public function test_do_nothing_if_file_exists(): void $appTester = $this->runInit($fs.'/nested/path'); - $this->assertStringContainsString( + self::assertStringContainsString( 'File phparkitect.php found in current directory, nothing to do', $appTester->getDisplay() ); @@ -69,7 +69,7 @@ public function test_returns_error_if_directory_is_not_writable(): void $appTester = $this->runInit($fs); - $this->assertStringContainsString( + self::assertStringContainsString( 'Ops, it seems I cannot create the file in vfs://root', $appTester->getDisplay() ); diff --git a/tests/E2E/Cli/VersionCommandTest.php b/tests/E2E/Cli/VersionCommandTest.php new file mode 100644 index 00000000..3e76be6f --- /dev/null +++ b/tests/E2E/Cli/VersionCommandTest.php @@ -0,0 +1,28 @@ +setAutoExit(false); + + $appTester = new ApplicationTester($app); + $appTester->run($input); + + self::assertStringContainsString('PHPArkitect version', $appTester->getDisplay()); + } +} diff --git a/tests/E2E/PHPUnit/ArchRuleTestCase.php b/tests/E2E/PHPUnit/ArchRuleTestCase.php index bb25113d..7c68276a 100644 --- a/tests/E2E/PHPUnit/ArchRuleTestCase.php +++ b/tests/E2E/PHPUnit/ArchRuleTestCase.php @@ -15,6 +15,6 @@ public static function assertArchRule(ArchRule $rule, ClassSet $set): void { $constraint = new ArchRuleCheckerConstraintAdapter($set); - static::assertThat($rule, $constraint); + self::assertThat($rule, $constraint); } } diff --git a/tests/E2E/Smoke/RunArkitectBinTest.php b/tests/E2E/Smoke/RunArkitectBinTest.php index a72f364a..209e18ad 100644 --- a/tests/E2E/Smoke/RunArkitectBinTest.php +++ b/tests/E2E/Smoke/RunArkitectBinTest.php @@ -39,8 +39,8 @@ public function test_returns_error_with_multiple_violations(): void depends on App\Services\UserService, but should not depend on classes outside namespace App\Domain because we want protect our domain (on line 14) depends on App\Services\CartService, but should not depend on classes outside namespace App\Domain because we want protect our domain (on line 15)'; - $this->assertEquals(self::ERROR_CODE, $process->getExitCode()); - $this->assertStringContainsString($expectedErrors, $process->getOutput()); + self::assertEquals(self::ERROR_CODE, $process->getExitCode()); + self::assertStringContainsString($expectedErrors, $process->getOutput()); } public function test_returns_error_with_multiple_violations_without_passing_config_file(): void @@ -66,23 +66,23 @@ public function test_returns_error_with_multiple_violations_without_passing_conf depends on App\Services\UserService, but should not depend on classes outside namespace App\Domain because we want protect our domain (on line 14) depends on App\Services\CartService, but should not depend on classes outside namespace App\Domain because we want protect our domain (on line 15)'; - $this->assertStringContainsString($expectedErrors, $process->getOutput()); - $this->assertEquals(self::ERROR_CODE, $process->getExitCode()); + self::assertStringContainsString($expectedErrors, $process->getOutput()); + self::assertEquals(self::ERROR_CODE, $process->getExitCode()); } public function test_does_not_explode_if_an_exception_is_thrown(): void { $process = $this->runArkitectPassingConfigFilePath(__DIR__.'/../_fixtures/configThrowsException.php'); - $this->assertEquals(self::ERROR_CODE, $process->getExitCode()); + self::assertEquals(self::ERROR_CODE, $process->getExitCode()); } public function test_run_command_with_success(): void { $process = $this->runArkitectPassingConfigFilePath(__DIR__.'/../_fixtures/configMvcWithoutErrors.php'); - $this->assertEquals(self::SUCCESS_CODE, $process->getExitCode()); - $this->assertStringNotContainsString('ERRORS!', $process->getOutput()); + self::assertEquals(self::SUCCESS_CODE, $process->getExitCode()); + self::assertStringNotContainsString('ERRORS!', $process->getOutput()); } public function test_bug_yield(): void @@ -94,8 +94,8 @@ public function test_bug_yield(): void App\Controller\Foo has 1 violations should have a name that matches *Controller'; - $this->assertEquals(self::ERROR_CODE, $process->getExitCode()); - $this->assertStringContainsString($expectedErrors, $process->getOutput()); + self::assertEquals(self::ERROR_CODE, $process->getExitCode()); + self::assertStringContainsString($expectedErrors, $process->getOutput()); } protected function runArkitectPassingConfigFilePath($configFilePath): Process diff --git a/tests/Integration/CheckAttributeDependencyTest.php b/tests/Integration/CheckAttributeDependencyTest.php index 440cd1c1..4b57395b 100644 --- a/tests/Integration/CheckAttributeDependencyTest.php +++ b/tests/Integration/CheckAttributeDependencyTest.php @@ -26,10 +26,10 @@ public function test_assertion_should_fail_on_invalid_dependency(): void $runner->run($dir, $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertStringContainsString('depends on App\Invalid\Attr, but should not depend on these namespaces: App\Invalid', $runner->getViolations()->get(0)->getError()); + self::assertStringContainsString('depends on App\Invalid\Attr, but should not depend on these namespaces: App\Invalid', $runner->getViolations()->get(0)->getError()); } public function createDirStructureWithAttributes(): array diff --git a/tests/Integration/CheckClassHaveAttributeTest.php b/tests/Integration/CheckClassHaveAttributeTest.php index f64a8fba..9a1e903e 100644 --- a/tests/Integration/CheckClassHaveAttributeTest.php +++ b/tests/Integration/CheckClassHaveAttributeTest.php @@ -27,8 +27,8 @@ public function test_models_should_reside_in_app_model(): void $runner->run($dir, $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function test_controllers_should_have_name_ending_in_controller(): void @@ -44,10 +44,10 @@ public function test_controllers_should_have_name_ending_in_controller(): void $runner->run($dir, $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\Controller\Foo', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\Controller\Foo', $runner->getViolations()->get(0)->getFqcn()); } public function test_controllers_should_have_controller_attribute(): void @@ -63,8 +63,8 @@ public function test_controllers_should_have_controller_attribute(): void $runner->run($dir, $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function createDirStructure(): array diff --git a/tests/Integration/CheckClassNamingTest.php b/tests/Integration/CheckClassNamingTest.php index c913f323..c7a3aa24 100644 --- a/tests/Integration/CheckClassNamingTest.php +++ b/tests/Integration/CheckClassNamingTest.php @@ -25,8 +25,8 @@ public function test_code_in_happy_island_should_have_name_matching_prefix(): vo $runner->run($dir, $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function createDummyProject(): array @@ -47,7 +47,7 @@ public function __construct(HappyClass $happy) $this->happy = $happy; } } - EOF + EOF, ], 'OtherBadCode' => [ 'OtherBadCode.php' => <<<'EOF' @@ -64,7 +64,7 @@ public function __construct(HappyClass $happy) $this->happy = $happy; } } - EOF + EOF, ], 'HappyIsland' => [ diff --git a/tests/Integration/CheckEnumTest.php b/tests/Integration/CheckEnumTest.php index d0385f5e..8bec33e4 100644 --- a/tests/Integration/CheckEnumTest.php +++ b/tests/Integration/CheckEnumTest.php @@ -34,11 +34,11 @@ public function test_naming_is_enforced(): void $runner->run($dir, ...$rules); - $this->assertCount(2, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(2, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertStringContainsString('should have a name that matches *Enum because', $runner->getViolations()->get(0)->getError()); - $this->assertStringContainsString('Aclass should be an enum because Enums should be enums', $runner->getViolations()->get(1)->getError()); + self::assertStringContainsString('should have a name that matches *Enum because', $runner->getViolations()->get(0)->getError()); + self::assertStringContainsString('Aclass should be an enum because Enums should be enums', $runner->getViolations()->get(1)->getError()); } public function createDirStructure(): array diff --git a/tests/Integration/ExtendsThrowableTest.php b/tests/Integration/ExtendsThrowableTest.php index ac7d430d..8eb8a6d4 100644 --- a/tests/Integration/ExtendsThrowableTest.php +++ b/tests/Integration/ExtendsThrowableTest.php @@ -26,10 +26,10 @@ public function test_naming_is_enforced(): void $runner->run($dir, $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertStringContainsString('should have a name that matches *Exception because', $runner->getViolations()->get(0)->getError()); + self::assertStringContainsString('should have a name that matches *Exception because', $runner->getViolations()->get(0)->getError()); } public function createDirStructure(): array diff --git a/tests/Integration/ImplementsTest.php b/tests/Integration/ImplementsTest.php index 4de18219..46c90d48 100644 --- a/tests/Integration/ImplementsTest.php +++ b/tests/Integration/ImplementsTest.php @@ -26,14 +26,14 @@ public function test_naming_is_enforced(): void $runner->run($dir, $rule); - $this->assertCount(0, $runner->getParsingErrors()); - $this->assertCount(2, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); + self::assertCount(2, $runner->getViolations()); - $this->assertEquals('App\AClass', $runner->getViolations()->get(0)->getFqcn()); - $this->assertStringContainsString('should have a name that matches An* because reasons', $runner->getViolations()->get(0)->getError()); + self::assertEquals('App\AClass', $runner->getViolations()->get(0)->getFqcn()); + self::assertStringContainsString('should have a name that matches An* because reasons', $runner->getViolations()->get(0)->getError()); - $this->assertEquals('App\AEnum', $runner->getViolations()->get(1)->getFqcn()); - $this->assertStringContainsString('should have a name that matches An* because reasons', $runner->getViolations()->get(1)->getError()); + self::assertEquals('App\AEnum', $runner->getViolations()->get(1)->getFqcn()); + self::assertStringContainsString('should have a name that matches An* because reasons', $runner->getViolations()->get(1)->getError()); } public function createDirStructure(): array diff --git a/tests/Integration/IsAbstractTest.php b/tests/Integration/IsAbstractTest.php index ae13d5c4..7a5c6652 100644 --- a/tests/Integration/IsAbstractTest.php +++ b/tests/Integration/IsAbstractTest.php @@ -31,8 +31,8 @@ public function test_is_abstract_in_that_should_not_consider_final_traits_enums_ $runner->run($this->createClasses(), $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function test_is_abstract_in_should_should_consider_final_traits_enums_interfaces(): void @@ -46,13 +46,13 @@ public function test_is_abstract_in_should_should_consider_final_traits_enums_in $runner->run($this->createClasses(), $rule); - $this->assertCount(4, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(4, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyEnum', $runner->getViolations()->get(0)->getFqcn()); - $this->assertEquals('App\MyFinal', $runner->getViolations()->get(1)->getFqcn()); - $this->assertEquals('App\MyInterface', $runner->getViolations()->get(2)->getFqcn()); - $this->assertEquals('App\MyTrait', $runner->getViolations()->get(3)->getFqcn()); + self::assertEquals('App\MyEnum', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyFinal', $runner->getViolations()->get(1)->getFqcn()); + self::assertEquals('App\MyInterface', $runner->getViolations()->get(2)->getFqcn()); + self::assertEquals('App\MyTrait', $runner->getViolations()->get(3)->getFqcn()); } public function test_is_not_abstract_in_should_should_consider_final_traits_enums_interfaces(): void @@ -66,10 +66,10 @@ public function test_is_not_abstract_in_should_should_consider_final_traits_enum $runner->run($this->createClasses(), $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyAbstract', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyAbstract', $runner->getViolations()->get(0)->getFqcn()); } public function test_it_can_check_multiple_class_properties(): void @@ -152,8 +152,8 @@ public function __construct(HappyClass $happy) $runner->run(vfsStream::setup('root', null, $structure)->url(), $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } protected function createClasses(): string diff --git a/tests/Integration/IsFinalTest.php b/tests/Integration/IsFinalTest.php index 7aa173a6..f22ddcf1 100644 --- a/tests/Integration/IsFinalTest.php +++ b/tests/Integration/IsFinalTest.php @@ -25,8 +25,8 @@ public function test_is_final_in_that_should_not_consider_abstract_traits_enums_ $runner->run($this->createClasses(), $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function test_is_final_in_should_should_consider_final_traits_enums_interfaces(): void @@ -40,13 +40,13 @@ public function test_is_final_in_should_should_consider_final_traits_enums_inter $runner->run($this->createClasses(), $rule); - $this->assertCount(4, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(4, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyAbstract', $runner->getViolations()->get(0)->getFqcn()); - $this->assertEquals('App\MyEnum', $runner->getViolations()->get(1)->getFqcn()); - $this->assertEquals('App\MyInterface', $runner->getViolations()->get(2)->getFqcn()); - $this->assertEquals('App\MyTrait', $runner->getViolations()->get(3)->getFqcn()); + self::assertEquals('App\MyAbstract', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyEnum', $runner->getViolations()->get(1)->getFqcn()); + self::assertEquals('App\MyInterface', $runner->getViolations()->get(2)->getFqcn()); + self::assertEquals('App\MyTrait', $runner->getViolations()->get(3)->getFqcn()); } public function test_is_not_final_in_should_should_consider_final_traits_enums_interfaces(): void @@ -60,10 +60,10 @@ public function test_is_not_final_in_should_should_consider_final_traits_enums_i $runner->run($this->createClasses(), $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyFinal', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyFinal', $runner->getViolations()->get(0)->getFqcn()); } protected function createClasses(): string diff --git a/tests/Integration/IsReadonlyTest.php b/tests/Integration/IsReadonlyTest.php index eefc82fb..97fb2866 100644 --- a/tests/Integration/IsReadonlyTest.php +++ b/tests/Integration/IsReadonlyTest.php @@ -25,8 +25,8 @@ public function test_is_readonly_in_that_should_not_consider_traits_enums_interf $runner->run($this->createClasses(), $rule); - $this->assertCount(0, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(0, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); } public function test_is_readonly_in_should_should_consider_traits_enums_interfaces(): void @@ -40,12 +40,12 @@ public function test_is_readonly_in_should_should_consider_traits_enums_interfac $runner->run($this->createClasses(), $rule); - $this->assertCount(3, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(3, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyEnum', $runner->getViolations()->get(0)->getFqcn()); - $this->assertEquals('App\MyInterface', $runner->getViolations()->get(1)->getFqcn()); - $this->assertEquals('App\MyTrait', $runner->getViolations()->get(2)->getFqcn()); + self::assertEquals('App\MyEnum', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyInterface', $runner->getViolations()->get(1)->getFqcn()); + self::assertEquals('App\MyTrait', $runner->getViolations()->get(2)->getFqcn()); } public function test_is_not_readonly_in_should_should_consider_traits_enums_interfaces(): void @@ -59,10 +59,10 @@ public function test_is_not_readonly_in_should_should_consider_traits_enums_inte $runner->run($this->createClasses(), $rule); - $this->assertCount(1, $runner->getViolations()); - $this->assertCount(0, $runner->getParsingErrors()); + self::assertCount(1, $runner->getViolations()); + self::assertCount(0, $runner->getParsingErrors()); - $this->assertEquals('App\MyReadonly', $runner->getViolations()->get(0)->getFqcn()); + self::assertEquals('App\MyReadonly', $runner->getViolations()->get(0)->getFqcn()); } protected function createClasses(): string diff --git a/tests/Unit/Analyzer/ClassDependencyTest.php b/tests/Unit/Analyzer/ClassDependencyTest.php index e9ae03e9..25ac273b 100644 --- a/tests/Unit/Analyzer/ClassDependencyTest.php +++ b/tests/Unit/Analyzer/ClassDependencyTest.php @@ -24,27 +24,27 @@ protected function setUp(): void public function test_it_should_create_class_dependency(): void { - $this->assertEquals(FullyQualifiedClassName::fromString($this->FQCN), $this->classDependency->getFQCN()); - $this->assertEquals($this->line, $this->classDependency->getLine()); + self::assertEquals(FullyQualifiedClassName::fromString($this->FQCN), $this->classDependency->getFQCN()); + self::assertEquals($this->line, $this->classDependency->getLine()); } public function test_it_should_match(): void { - $this->assertTrue($this->classDependency->matches('HappyIsland')); + self::assertTrue($this->classDependency->matches('HappyIsland')); } public function test_it_should_not_match(): void { - $this->assertFalse($this->classDependency->matches('Happy')); + self::assertFalse($this->classDependency->matches('Happy')); } public function test_it_should_match_one_of(): void { - $this->assertTrue($this->classDependency->matchesOneOf('HappyIsland', 'Foo', 'Bar')); + self::assertTrue($this->classDependency->matchesOneOf('HappyIsland', 'Foo', 'Bar')); } public function test_it_should_not_match_one_of(): void { - $this->assertFalse($this->classDependency->matchesOneOf('Baz', 'Foo', 'Bar')); + self::assertFalse($this->classDependency->matchesOneOf('Baz', 'Foo', 'Bar')); } } diff --git a/tests/Unit/Analyzer/ClassDescriptionBuilderTest.php b/tests/Unit/Analyzer/ClassDescriptionBuilderTest.php index a86d1c1f..21a55e40 100644 --- a/tests/Unit/Analyzer/ClassDescriptionBuilderTest.php +++ b/tests/Unit/Analyzer/ClassDescriptionBuilderTest.php @@ -23,10 +23,10 @@ public function test_it_should_create_builder_with_dependency_and_interface(): v ->addInterface('InterfaceClass', 10) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); + self::assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertEquals($FQCN, $classDescription->getName()); - $this->assertEquals($FQCN, $classDescription->getFQCN()); + self::assertEquals($FQCN, $classDescription->getName()); + self::assertEquals($FQCN, $classDescription->getFQCN()); } public function test_it_should_create_final_class(): void @@ -39,9 +39,9 @@ public function test_it_should_create_final_class(): void ->setFinal(true) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); + self::assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertTrue($classDescription->isFinal()); + self::assertTrue($classDescription->isFinal()); } public function test_it_should_create_not_final_class(): void @@ -54,9 +54,9 @@ public function test_it_should_create_not_final_class(): void ->setFinal(false) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); + self::assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertFalse($classDescription->isFinal()); + self::assertFalse($classDescription->isFinal()); } public function test_it_should_create_abstract_class(): void @@ -69,9 +69,9 @@ public function test_it_should_create_abstract_class(): void ->setAbstract(true) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); + self::assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertTrue($classDescription->isAbstract()); + self::assertTrue($classDescription->isAbstract()); } public function test_it_should_create_not_abstract_class(): void @@ -84,9 +84,9 @@ public function test_it_should_create_not_abstract_class(): void ->setAbstract(false) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); + self::assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertFalse($classDescription->isAbstract()); + self::assertFalse($classDescription->isAbstract()); } public function test_it_should_create_annotated_class(): void @@ -105,8 +105,8 @@ public function test_it_should_create_annotated_class(): void ->addDocBlock($docBlock) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertEquals([$docBlock], $classDescription->getDocBlock()); + self::assertInstanceOf(ClassDescription::class, $classDescription); + self::assertEquals([$docBlock], $classDescription->getDocBlock()); } public function test_it_should_add_attributes(): void @@ -135,8 +135,8 @@ public function test_it_should_create_interface(): void ->setInterface(true) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertTrue($classDescription->isInterface()); + self::assertInstanceOf(ClassDescription::class, $classDescription); + self::assertTrue($classDescription->isInterface()); } public function test_it_should_create_not_interface(): void @@ -149,8 +149,8 @@ public function test_it_should_create_not_interface(): void ->setInterface(false) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertFalse($classDescription->isInterface()); + self::assertInstanceOf(ClassDescription::class, $classDescription); + self::assertFalse($classDescription->isInterface()); } public function test_it_should_create_trait(): void @@ -163,8 +163,8 @@ public function test_it_should_create_trait(): void ->setTrait(true) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertTrue($classDescription->isTrait()); + self::assertInstanceOf(ClassDescription::class, $classDescription); + self::assertTrue($classDescription->isTrait()); } public function test_it_should_create_not_trait(): void @@ -177,7 +177,7 @@ public function test_it_should_create_not_trait(): void ->setTrait(false) ->build(); - $this->assertInstanceOf(ClassDescription::class, $classDescription); - $this->assertFalse($classDescription->isTrait()); + self::assertInstanceOf(ClassDescription::class, $classDescription); + self::assertFalse($classDescription->isTrait()); } } diff --git a/tests/Unit/Analyzer/ClassDescriptionTest.php b/tests/Unit/Analyzer/ClassDescriptionTest.php index de9300da..5a87a274 100644 --- a/tests/Unit/Analyzer/ClassDescriptionTest.php +++ b/tests/Unit/Analyzer/ClassDescriptionTest.php @@ -21,28 +21,28 @@ public function test_should_return_file_path(): void { $cd = $this->builder->build(); - $this->assertEquals('src/Foo.php', $cd->getFilePath()); + self::assertEquals('src/Foo.php', $cd->getFilePath()); } public function test_should_return_true_if_there_class_is_in_namespace(): void { $cd = $this->builder->build(); - $this->assertTrue($cd->namespaceMatches('Fruit')); + self::assertTrue($cd->namespaceMatches('Fruit')); } public function test_should_return_name(): void { $cd = $this->builder->build(); - $this->assertEquals('Banana', $cd->getName()); + self::assertEquals('Banana', $cd->getName()); } public function test_should_return_true_if_there_class_is_in_namespace_array(): void { $cd = $this->builder->build(); - $this->assertTrue($cd->namespaceMatchesOneOfTheseNamespaces(['Fruit'])); + self::assertTrue($cd->namespaceMatchesOneOfTheseNamespaces(['Fruit'])); } public function test_should_return_true_if_is_annotated_with(): void @@ -53,7 +53,7 @@ public function test_should_return_true_if_is_annotated_with(): void */') ->build(); - $this->assertTrue($cd->containsDocBlock('@psalm-immutable')); + self::assertTrue($cd->containsDocBlock('@psalm-immutable')); } public function test_should_return_false_if_not_annotated_with(): void @@ -64,7 +64,7 @@ public function test_should_return_false_if_not_annotated_with(): void */') ->build(); - $this->assertFalse($cd->containsDocBlock('@another-annotation')); + self::assertFalse($cd->containsDocBlock('@another-annotation')); } public function test_should_return_true_if_has_attribute(): void diff --git a/tests/Unit/Analyzer/FilePathTest.php b/tests/Unit/Analyzer/FilePathTest.php index cfd4b0e7..1981bfef 100644 --- a/tests/Unit/Analyzer/FilePathTest.php +++ b/tests/Unit/Analyzer/FilePathTest.php @@ -14,6 +14,6 @@ public function test_it_should_set_and_get_path(): void $filePath = new FilePath(); $filePath->set('thePath'); - $this->assertEquals('thePath', $filePath->toString()); + self::assertEquals('thePath', $filePath->toString()); } } diff --git a/tests/Unit/Analyzer/FileVisitorTest.php b/tests/Unit/Analyzer/FileVisitorTest.php index 7209eefb..7f60ff62 100644 --- a/tests/Unit/Analyzer/FileVisitorTest.php +++ b/tests/Unit/Analyzer/FileVisitorTest.php @@ -30,7 +30,7 @@ public function test_should_parse_empty_file(): void $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.4')); $fp->parse($code, 'path/to/class.php'); - $this->assertEmpty($fp->getClassDescriptions()); + self::assertEmpty($fp->getClassDescriptions()); } public function test_violation_should_have_ref_to_filepath(): void @@ -60,9 +60,9 @@ public function __construct(Request $request) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo'); $dependsOnTheseNamespaces->evaluate($fp->getClassDescriptions()[0], $violations, 'because'); - $this->assertCount(2, $violations); - $this->assertEquals('path/to/class.php', $violations->get(0)->getFilePath()); - $this->assertEquals('path/to/class.php', $violations->get(1)->getFilePath()); + self::assertCount(2, $violations); + self::assertEquals('path/to/class.php', $violations->get(0)->getFilePath()); + self::assertEquals('path/to/class.php', $violations->get(1)->getFilePath()); } public function test_should_create_a_class_description(): void @@ -145,7 +145,7 @@ class Cat implements AnInterface new ClassDependency('Root\Namespace1\Proj', 23), ]; - $this->assertEquals($expectedInterfaces, $cd[0]->getDependencies()); + self::assertEquals($expectedInterfaces, $cd[0]->getDependencies()); } public function test_it_should_parse_extends_class(): void @@ -171,7 +171,7 @@ class Cat extends Animal $cd = $fp->getClassDescriptions()[1]; - $this->assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString()); + self::assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString()); } public function test_it_should_not_parse_extends_from_insider_anonymousclass(): void @@ -200,7 +200,7 @@ public function methodWithAnonymous(): void $cd = $fp->getClassDescriptions()[1]; - $this->assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString()); + self::assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString()); } public function test_should_depends_on_these_namespaces(): void @@ -232,7 +232,7 @@ public function __construct(Request $request) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo', 'Symfony', 'Doctrine'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_should_returns_all_dependencies(): void @@ -270,7 +270,7 @@ public function __construct(Request $request, ?Nullable $nullable) new ClassDependency('Foo\Baz\StaticClass', 15), ]; - $this->assertEquals($expectedDependencies, $cd[0]->getDependencies()); + self::assertEquals($expectedDependencies, $cd[0]->getDependencies()); } public function test_it_should_parse_arrow_function(): void @@ -301,7 +301,7 @@ public function __construct() $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo', 'Symfony', 'Doctrine'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_should_catch_parsing_errors(): void @@ -325,7 +325,7 @@ public function __construct() $fp->parse($code, 'relativePathName'); $parsingErrors = $fp->getParsingErrors(); - $this->assertEquals([ + self::assertEquals([ ParsingError::create('relativePathName', 'Syntax error, unexpected \'}\' on line 10'), ], $parsingErrors); } @@ -356,7 +356,7 @@ public function save(Quote $quote): void; $violations = new Violations(); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_should_parse_self_correctly(): void @@ -394,7 +394,7 @@ public function doSomething(self $self, static $static) $notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('Root\Animals'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_should_return_errors_for_class_outside_namespace(): void @@ -427,7 +427,7 @@ public function foo() $dependsOnlyOnTheseNamespaces = new DependsOnlyOnTheseNamespaces(); $dependsOnlyOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_should_parse_class_attributes(): void @@ -491,7 +491,7 @@ public function getStatic(): self $notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('Root\Cars'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_can_parse_enum(): void @@ -519,7 +519,7 @@ enum Enum $notHaveDependencyOutsideNamespace = new Implement('MyInterface'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_should_parse_enum_attributes(): void @@ -647,12 +647,12 @@ public function getFoo(): int $notHaveDependencyOutsideNamespace = new NotContainDocBlockLike('ItemNotFound'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); $notHaveDependencyOutsideNamespace = new NotContainDocBlockLike('Exception'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(2, $violations); + self::assertCount(2, $violations); } public function test_it_parse_typed_property(): void @@ -680,7 +680,7 @@ class ApplicationLevelDto $notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_typed_nullable_property(): void @@ -708,7 +708,7 @@ class ApplicationLevelDto $notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_scalar_typed_property(): void @@ -736,7 +736,7 @@ class ApplicationLevelDto $notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_parse_nullable_scalar_typed_property(): void @@ -768,7 +768,7 @@ public function __construct( $notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_parse_dependencies_in_docblocks_customs(): void @@ -802,7 +802,7 @@ class ApplicationLevelDto $notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_custom_tags_in_docblocks(): void @@ -832,7 +832,7 @@ class ApplicationLevelDto $notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_should_implement_exact_classname(): void @@ -865,7 +865,7 @@ class Test implements Order $implement = new Implement('Foo\Order'); $implement->evaluate($cd, $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations, $violations->toString(Printer::FORMAT_TEXT)); + self::assertCount(0, $violations, $violations->toString(Printer::FORMAT_TEXT)); } public function test_it_parse_dependencies_in_docblocks_with_alias(): void @@ -895,7 +895,7 @@ class ApplicationLevelDto $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_interfaces(): void @@ -921,7 +921,7 @@ public function getBookList(): QueryBuilder; $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_interface_extends(): void @@ -953,9 +953,9 @@ public function foobar(); $cd = $fp->getClassDescriptions(); - $this->assertCount(3, $cd); - $this->assertEquals('MyProject\AppBundle\Application\FooAble', $cd[2]->getExtends()[0]->toString()); - $this->assertEquals('MyProject\AppBundle\Application\BarAble', $cd[2]->getExtends()[1]->toString()); + self::assertCount(3, $cd); + self::assertEquals('MyProject\AppBundle\Application\FooAble', $cd[2]->getExtends()[0]->toString()); + self::assertEquals('MyProject\AppBundle\Application\BarAble', $cd[2]->getExtends()[1]->toString()); } public function test_it_handles_return_types(): void @@ -992,7 +992,7 @@ public function getRequest(): Request //the violations is reported here $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo', 'Symfony', 'Doctrine'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_skip_custom_annotations_in_docblocks_if_the_option_parse_custom_annotation_is_false(): void @@ -1021,7 +1021,7 @@ class ApplicationLevelDto $dependsOnlyOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $dependsOnlyOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_parse_arrays_as_scalar_types(): void @@ -1050,7 +1050,7 @@ public function __construct(array $field1) $notHaveDependenciesOutside = new NotHaveDependencyOutsideNamespace('App\Domain'); $notHaveDependenciesOutside->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_handles_typed_arrays_in_properties_with_generics_syntax(): void @@ -1080,7 +1080,7 @@ class MyClass $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_properties_with_list_syntax(): void @@ -1110,7 +1110,7 @@ class MyClass $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_properties_with_legacy_syntax(): void @@ -1140,7 +1140,7 @@ class MyClass $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_method_params_with_generics_syntax(): void @@ -1172,7 +1172,7 @@ public function __construct(array $dtoList) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_method_params_with_list_syntax(): void @@ -1204,7 +1204,7 @@ public function __construct(array $dtoList) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_method_params_with_legacy_syntax(): void @@ -1236,7 +1236,7 @@ public function __construct(array $dtoList) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_method_params_with_multiple_params(): void @@ -1271,7 +1271,7 @@ public function __construct(string $var1, array $dtoList, $var2, array $voList) $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_return_type_with_generics_syntax(): void @@ -1304,7 +1304,7 @@ public function getList(): array $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_return_type_with_list_syntax(): void @@ -1337,7 +1337,7 @@ public function getList(): array $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_handles_typed_arrays_in_return_type_with_legacy_syntax(): void @@ -1370,7 +1370,7 @@ public function getList(): array $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Domain'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } public function test_it_parse_traits(): void @@ -1399,7 +1399,7 @@ public function getBookList(): QueryBuilder $dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application'); $dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software'); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } /** @@ -1412,7 +1412,7 @@ public function test_it_parse_enums(string $code): void $fp->parse($code, 'relativePathName'); foreach ($fp->getClassDescriptions() as $classDescription) { - $this->assertTrue($classDescription->isEnum()); + self::assertTrue($classDescription->isEnum()); } } @@ -1427,7 +1427,7 @@ enum DefaultEnum { case FOO; } - EOF + EOF, ]; yield 'string enum' => [ @@ -1439,7 +1439,7 @@ enum StringEnum: string { case BAR: 'bar'; } - EOF + EOF, ]; yield 'integer enum' => [ @@ -1451,7 +1451,7 @@ enum IntEnum: int { case BAZ: 42; } - EOF + EOF, ]; yield 'multiple enums' => [ @@ -1473,7 +1473,7 @@ enum IntEnum: int { case BAZ: 42; } - EOF + EOF, ]; } @@ -1505,6 +1505,6 @@ public function __construct(string $firstName, string $lastName) { $cd = $fp->getClassDescriptions(); - $this->assertInstanceOf(ClassDescription::class, $cd[0]); + self::assertInstanceOf(ClassDescription::class, $cd[0]); } } diff --git a/tests/Unit/Analyzer/FullyQualifiedClassNameTest.php b/tests/Unit/Analyzer/FullyQualifiedClassNameTest.php index 14f30c9c..83f7a685 100644 --- a/tests/Unit/Analyzer/FullyQualifiedClassNameTest.php +++ b/tests/Unit/Analyzer/FullyQualifiedClassNameTest.php @@ -29,7 +29,7 @@ public function test_should_match_namespaces_with_wildcards(string $fqcn, string { $fqcn = FullyQualifiedClassName::fromString($fqcn); - $this->assertEquals($shouldMatch, $fqcn->matches($pattern), "{$fqcn->toString()} should ".($shouldMatch ? '' : 'not ')."match $pattern"); + self::assertEquals($shouldMatch, $fqcn->matches($pattern), "{$fqcn->toString()} should ".($shouldMatch ? '' : 'not ')."match $pattern"); } public function test_should_throw_if_invalid_namespace_is_passed(): void @@ -43,29 +43,29 @@ public function test_should_throw_if_invalid_namespace_is_passed(): void public function test_single_letter_class_is_valid(): void { $fqcn = FullyQualifiedClassName::fromString('A'); - $this->assertEquals('A', $fqcn->className()); + self::assertEquals('A', $fqcn->className()); } public function test_should_return_class_name(): void { $fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana'); - $this->assertEquals('Banana', $fqcn->className()); + self::assertEquals('Banana', $fqcn->className()); } public function test_should_have_root_ns_preserved(): void { $fqcn = FullyQualifiedClassName::fromString('\Banana'); - $this->assertEquals('Banana', $fqcn->className()); - $this->assertEquals('', $fqcn->namespace()); + self::assertEquals('Banana', $fqcn->className()); + self::assertEquals('', $fqcn->namespace()); } public function test_should_have_ns_normalized(): void { $fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana'); - $this->assertEquals('Banana', $fqcn->className()); - $this->assertEquals('Food\Vegetables\Fruits', $fqcn->namespace()); - $this->assertEquals('Food\Vegetables\Fruits\Banana', $fqcn->toString()); + self::assertEquals('Banana', $fqcn->className()); + self::assertEquals('Food\Vegetables\Fruits', $fqcn->namespace()); + self::assertEquals('Food\Vegetables\Fruits\Banana', $fqcn->toString()); } } diff --git a/tests/Unit/Analyzer/PatternStringTest.php b/tests/Unit/Analyzer/PatternStringTest.php index a608d38e..fea549fb 100644 --- a/tests/Unit/Analyzer/PatternStringTest.php +++ b/tests/Unit/Analyzer/PatternStringTest.php @@ -11,8 +11,8 @@ class PatternStringTest extends TestCase public function test_it_works_for_simple_strings(): void { $pattern = new PatternString('Example'); - $this->assertTrue($pattern->matches('Example')); - $this->assertFalse($pattern->matches('Something else')); + self::assertTrue($pattern->matches('Example')); + self::assertFalse($pattern->matches('Something else')); } /** @@ -20,7 +20,7 @@ public function test_it_works_for_simple_strings(): void */ public function test_wildcard_is_for_alphanumeric(string $string, string $pattern, bool $expectedResult): void { - $this->assertEquals($expectedResult, (new PatternString($string))->matches($pattern)); + self::assertEquals($expectedResult, (new PatternString($string))->matches($pattern)); } public static function providePatterns(): array diff --git a/tests/Unit/CLI/ConfigTest.php b/tests/Unit/CLI/ConfigTest.php index 93887379..68e446dc 100644 --- a/tests/Unit/CLI/ConfigTest.php +++ b/tests/Unit/CLI/ConfigTest.php @@ -26,10 +26,10 @@ public function test_it_should_create_config(): void $config = new Config(); $config->add($classSet, ...[$rule]); - $this->assertInstanceOf(Config::class, $config); + self::assertInstanceOf(Config::class, $config); $classSetRulesExpected[] = ClassSetRules::create($classSet, ...[$rule]); - $this->assertEquals($classSetRulesExpected, $config->getClassSetRules()); + self::assertEquals($classSetRulesExpected, $config->getClassSetRules()); } public function test_it_should_create_config_with_only_one_rule_to_run(): void @@ -50,18 +50,18 @@ public function test_it_should_create_config_with_only_one_rule_to_run(): void $config = new Config(); $config->add($classSet, ...[$rule1, $rule2]); - $this->assertInstanceOf(Config::class, $config); + self::assertInstanceOf(Config::class, $config); $classSetRulesExpected[] = ClassSetRules::create($classSet, ...[$rule2]); - $this->assertEquals($classSetRulesExpected, $config->getClassSetRules()); + self::assertEquals($classSetRulesExpected, $config->getClassSetRules()); } public function test_it_should_allow_to_change_the_default_value_for_parsing_custom_annotations(): void { $config = new Config(); - $this->assertTrue($config->isParseCustomAnnotationsEnabled()); + self::assertTrue($config->isParseCustomAnnotationsEnabled()); $config->skipParsingCustomAnnotations(); - $this->assertFalse($config->isParseCustomAnnotationsEnabled()); + self::assertFalse($config->isParseCustomAnnotationsEnabled()); } } diff --git a/tests/Unit/CLI/Printer/GitlabPrinterTest.php b/tests/Unit/CLI/Printer/GitlabPrinterTest.php index 864de7c2..abf10243 100644 --- a/tests/Unit/CLI/Printer/GitlabPrinterTest.php +++ b/tests/Unit/CLI/Printer/GitlabPrinterTest.php @@ -44,10 +44,10 @@ public function test_print_with_no_violations(): void $result = $printer->print($violationsCollection); - $this->assertIsString($result, 'Result should be a string'); - $this->assertJson($result, 'Result should be a valid JSON string'); + self::assertIsString($result, 'Result should be a string'); + self::assertJson($result, 'Result should be a valid JSON string'); $decodedResult = json_decode($result, true); - $this->assertEmpty($decodedResult, 'Result should be an empty array'); + self::assertEmpty($decodedResult, 'Result should be an empty array'); } } diff --git a/tests/Unit/CLI/Printer/JsonPrinterTest.php b/tests/Unit/CLI/Printer/JsonPrinterTest.php index cfb73adc..e3e0b852 100644 --- a/tests/Unit/CLI/Printer/JsonPrinterTest.php +++ b/tests/Unit/CLI/Printer/JsonPrinterTest.php @@ -22,7 +22,7 @@ public function test_print_returns_correct_json_for_empty_violations(): void 'details' => [], ]); - $this->assertSame($expected, $result); + self::assertSame($expected, $result); } /** @@ -53,7 +53,7 @@ public function test_print_returns_correct_json_for_single_violation(): void ], ]); - $this->assertSame($expected, $result); + self::assertSame($expected, $result); } /** @@ -93,6 +93,6 @@ public function test_print_returns_correct_json_for_multiple_violations(): void ], ]); - $this->assertSame($expected, $result); + self::assertSame($expected, $result); } } diff --git a/tests/Unit/CLI/Printer/PrinterFactoryTest.php b/tests/Unit/CLI/Printer/PrinterFactoryTest.php index 350efe09..82c6f8f6 100644 --- a/tests/Unit/CLI/Printer/PrinterFactoryTest.php +++ b/tests/Unit/CLI/Printer/PrinterFactoryTest.php @@ -19,7 +19,7 @@ public function test_create_returns_json_printer_for_json_format(): void $printer = $factory->create('json'); - $this->assertInstanceOf(JsonPrinter::class, $printer); + self::assertInstanceOf(JsonPrinter::class, $printer); } /** @@ -31,6 +31,6 @@ public function test_create_returns_text_printer_for_non_json_format(): void $printer = $factory->create('text'); - $this->assertInstanceOf(TextPrinter::class, $printer); + self::assertInstanceOf(TextPrinter::class, $printer); } } diff --git a/tests/Unit/CLI/Printer/TextPrinterTest.php b/tests/Unit/CLI/Printer/TextPrinterTest.php index 983456f6..5874e422 100644 --- a/tests/Unit/CLI/Printer/TextPrinterTest.php +++ b/tests/Unit/CLI/Printer/TextPrinterTest.php @@ -25,7 +25,7 @@ public function test_prints_violation_without_line(): void $expectedOutput = "\nExampleClass has 1 violations\n Error message\n"; - $this->assertSame($expectedOutput, $result); + self::assertSame($expectedOutput, $result); } public function test_prints_violation_with_line(): void @@ -41,7 +41,7 @@ public function test_prints_violation_with_line(): void $expectedOutput = "\nExampleClass has 1 violations\n Error message (on line 42)\n"; - $this->assertSame($expectedOutput, $result); + self::assertSame($expectedOutput, $result); } public function test_prints_multiple_violations_grouped_by_fqcn(): void @@ -61,6 +61,6 @@ public function test_prints_multiple_violations_grouped_by_fqcn(): void $expectedOutput = "\nExampleClass has 2 violations\n First error\n Second error (on line 10)\n\nAnotherClass has 1 violations\n Another error (on line 15)\n"; - $this->assertSame($expectedOutput, $result); + self::assertSame($expectedOutput, $result); } } diff --git a/tests/Unit/CLI/TargetPhpVersionTest.php b/tests/Unit/CLI/TargetPhpVersionTest.php index edd2d50c..e041f499 100644 --- a/tests/Unit/CLI/TargetPhpVersionTest.php +++ b/tests/Unit/CLI/TargetPhpVersionTest.php @@ -14,21 +14,21 @@ public function test_it_should_return_passed_php_version(): void { $targetPhpVersion = TargetPhpVersion::create('8.3'); - $this->assertEquals('8.3', $targetPhpVersion->get()); + self::assertEquals('8.3', $targetPhpVersion->get()); } public function test_it_should_ignore_the_patch_number(): void { $targetPhpVersion = TargetPhpVersion::create('8.3.2'); - $this->assertEquals('8.3', $targetPhpVersion->get()); + self::assertEquals('8.3', $targetPhpVersion->get()); } public function test_it_should_ignore_extra_informations(): void { $targetPhpVersion = TargetPhpVersion::create('7.4.10-14+ubuntu22.04.1+deb.sury.org+1'); - $this->assertEquals('7.4', $targetPhpVersion->get()); + self::assertEquals('7.4', $targetPhpVersion->get()); } public function test_it_should_throw_exception_if_not_valid_php_version(): void diff --git a/tests/Unit/ClassSetRulesTest.php b/tests/Unit/ClassSetRulesTest.php index 108a2575..63268479 100644 --- a/tests/Unit/ClassSetRulesTest.php +++ b/tests/Unit/ClassSetRulesTest.php @@ -32,7 +32,7 @@ public function test_create_class_set_rules_correctly(): void $classSetRules = ClassSetRules::create($classSet, ...$rules); - $this->assertEquals($classSet, $classSetRules->getClassSet()); - $this->assertEquals($rules, $classSetRules->getRules()); + self::assertEquals($classSet, $classSetRules->getClassSet()); + self::assertEquals($rules, $classSetRules->getRules()); } } diff --git a/tests/Unit/Expressions/ForClasses/HaveNameMatchingTest.php b/tests/Unit/Expressions/ForClasses/HaveNameMatchingTest.php index 8ec3b06c..abb7eec0 100644 --- a/tests/Unit/Expressions/ForClasses/HaveNameMatchingTest.php +++ b/tests/Unit/Expressions/ForClasses/HaveNameMatchingTest.php @@ -32,7 +32,7 @@ public function test_show_violation_when_class_name_does_not_match(): void $violations = new Violations(); $expression->evaluate($badClass, $violations, $because); self::assertNotEquals(0, $violations->count()); - $this->assertEquals( + self::assertEquals( 'should have a name that matches *GoodName* because we want to add this rule for our software', $expression->describe($badClass, $because)->toString() ); diff --git a/tests/Unit/Expressions/ForClasses/IsReadonlyTest.php b/tests/Unit/Expressions/ForClasses/IsReadonlyTest.php index d44d1d1d..dc981ef3 100644 --- a/tests/Unit/Expressions/ForClasses/IsReadonlyTest.php +++ b/tests/Unit/Expressions/ForClasses/IsReadonlyTest.php @@ -24,7 +24,7 @@ public function test_it_should_return_error_description(): void $because = 'we want to add this rule for our software'; $violationError = $isReadonly->describe($classDescription, $because)->toString(); - $this->assertEquals('HappyIsland should be readonly because we want to add this rule for our software', $violationError); + self::assertEquals('HappyIsland should be readonly because we want to add this rule for our software', $violationError); } public function test_it_should_return_true_if_is_readonly(): void diff --git a/tests/Unit/GlobTest.php b/tests/Unit/GlobTest.php index e2eccb91..ce11fb45 100644 --- a/tests/Unit/GlobTest.php +++ b/tests/Unit/GlobTest.php @@ -11,18 +11,18 @@ class GlobTest extends TestCase public function test_can_exclude_using_glob_pattern(): void { // * - Matches zero or more characters. - $this->assertEquals('/.*Catalog.*/', Glob::toRegex('*Catalog*')); + self::assertEquals('/.*Catalog.*/', Glob::toRegex('*Catalog*')); // * - Matches zero or more characters. - $this->assertEquals('/Cata\.log/', Glob::toRegex('Cata.log')); + self::assertEquals('/Cata\.log/', Glob::toRegex('Cata.log')); // ? - Matches exactly one character (any character). - $this->assertEquals('/C.talog/', Glob::toRegex('C?talog')); + self::assertEquals('/C.talog/', Glob::toRegex('C?talog')); // [...] - Matches one character from a group of characters. If the first character is !, matches any character not in the group. - $this->assertEquals('/prova[123]/', Glob::toRegex('prova[123]')); + self::assertEquals('/prova[123]/', Glob::toRegex('prova[123]')); // [...] - Matches one character from a group of characters. If the first character is !, matches any character not in the group. - $this->assertEquals('/prova[ˆ123]/', Glob::toRegex('prova[!123]')); + self::assertEquals('/prova[ˆ123]/', Glob::toRegex('prova[!123]')); } } diff --git a/tests/Unit/Rules/ConstraintsTest.php b/tests/Unit/Rules/ConstraintsTest.php index 5dc86bc2..fef29776 100644 --- a/tests/Unit/Rules/ConstraintsTest.php +++ b/tests/Unit/Rules/ConstraintsTest.php @@ -18,7 +18,7 @@ class ConstraintsTest extends TestCase { public function test_it_should_not_add_to_violation_if_constraint_is_not_violated(): void { - $trueExpression = new class() implements Expression { + $trueExpression = new class implements Expression { public function describe(ClassDescription $theClass, string $because): Description { return new Description('', ''); @@ -44,12 +44,12 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str $because ); - $this->assertCount(0, $violations); + self::assertCount(0, $violations); } public function test_it_should_add_to_violation_store_if_constraint_is_violated(): void { - $falseExpression = new class() implements Expression { + $falseExpression = new class implements Expression { public function describe(ClassDescription $theClass, string $because): Description { return new Description('bar', 'we want to add this rule'); @@ -82,6 +82,6 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str $because ); - $this->assertCount(1, $violations); + self::assertCount(1, $violations); } } diff --git a/tests/Unit/Rules/ParsingErrorsTest.php b/tests/Unit/Rules/ParsingErrorsTest.php index 7ae384ad..39597e8c 100644 --- a/tests/Unit/Rules/ParsingErrorsTest.php +++ b/tests/Unit/Rules/ParsingErrorsTest.php @@ -30,14 +30,14 @@ protected function setUp(): void public function test_add_elements_to_store_and_get_it(): void { - $this->assertEquals($this->parsingError, $this->parsingStore->get(0)); + self::assertEquals($this->parsingError, $this->parsingStore->get(0)); } public function test_add_elements_to_store_and_cant_get_it_if_index_not_valid(): void { $this->expectException(IndexNotFoundException::class); $this->expectExceptionMessage('Index not found 1111'); - $this->assertEquals('', $this->parsingStore->get(1111)); + self::assertEquals('', $this->parsingStore->get(1111)); } public function test_count(): void @@ -48,7 +48,7 @@ public function test_count(): void 2 ); $this->parsingStore->add($parsingError); - $this->assertEquals(2, $this->parsingStore->count()); + self::assertEquals(2, $this->parsingStore->count()); } public function test_to_string(): void @@ -65,12 +65,12 @@ public function test_to_string(): void Syntax error, unexpected T_STRING on line 8 in file: App\Controller\Foo '; - $this->assertEquals($expected, $this->parsingStore->toString()); + self::assertEquals($expected, $this->parsingStore->toString()); } public function test_calling_iterator(): void { - $this->assertInstanceOf(\Generator::class, $this->parsingStore->getIterator()); + self::assertInstanceOf(\Generator::class, $this->parsingStore->getIterator()); } public function test_convert_to_array(): void @@ -79,7 +79,7 @@ public function test_convert_to_array(): void $this->parsingError, ]; - $this->assertEquals($expected, $this->parsingStore->toArray()); + self::assertEquals($expected, $this->parsingStore->toArray()); } public function test_get_iterable(): void @@ -92,6 +92,6 @@ public function test_get_iterable(): void $this->parsingStore->add($parsingError); $iterable = $this->parsingStore->getIterator(); - $this->assertEquals([$this->parsingError, $parsingError], iterator_to_array($iterable)); + self::assertEquals([$this->parsingError, $parsingError], iterator_to_array($iterable)); } } diff --git a/tests/Unit/Rules/SpecsTest.php b/tests/Unit/Rules/SpecsTest.php index 15e49aea..61df5c1b 100644 --- a/tests/Unit/Rules/SpecsTest.php +++ b/tests/Unit/Rules/SpecsTest.php @@ -20,7 +20,7 @@ public function test_return_false_if_not_all_specs_are_matched(): void $classDescription = ClassDescription::getBuilder('MyNamespace\HappyIsland', 'src/Foo.php')->build(); $because = 'we want to add this rule for our software'; - $this->assertFalse($specStore->allSpecsAreMatchedBy($classDescription, $because)); + self::assertFalse($specStore->allSpecsAreMatchedBy($classDescription, $because)); } public function test_return_true_if_all_specs_are_matched(): void @@ -33,6 +33,6 @@ public function test_return_true_if_all_specs_are_matched(): void ->build(); $because = 'we want to add this rule for our software'; - $this->assertTrue($specStore->allSpecsAreMatchedBy($classDescription, $because)); + self::assertTrue($specStore->allSpecsAreMatchedBy($classDescription, $because)); } } diff --git a/tests/Unit/Rules/ViolationsTest.php b/tests/Unit/Rules/ViolationsTest.php index 7b6f433a..815eee42 100644 --- a/tests/Unit/Rules/ViolationsTest.php +++ b/tests/Unit/Rules/ViolationsTest.php @@ -30,14 +30,14 @@ protected function setUp(): void public function test_add_elements_to_store_and_get_it(): void { - $this->assertEquals($this->violation, $this->violationStore->get(0)); + self::assertEquals($this->violation, $this->violationStore->get(0)); } public function test_add_elements_to_store_and_cant_get_it_if_index_not_valid(): void { $this->expectException(IndexNotFoundException::class); $this->expectExceptionMessage('Index not found 1111'); - $this->assertEquals('', $this->violationStore->get(1111)); + self::assertEquals('', $this->violationStore->get(1111)); } public function test_count(): void @@ -47,7 +47,7 @@ public function test_count(): void 'should have name end with Controller' ); $this->violationStore->add($violation); - $this->assertEquals(2, $this->violationStore->count()); + self::assertEquals(2, $this->violationStore->count()); } public function test_to_string(): void @@ -66,7 +66,7 @@ public function test_to_string(): void should have name end with Controller '; - $this->assertEquals($expected, $this->violationStore->toString(Printer::FORMAT_TEXT)); + self::assertEquals($expected, $this->violationStore->toString(Printer::FORMAT_TEXT)); } public function test_get_iterable(): void @@ -78,7 +78,7 @@ public function test_get_iterable(): void $this->violationStore->add($violation); $iterable = $this->violationStore->getIterator(); - $this->assertEquals([ + self::assertEquals([ $this->violation, $violation, ], iterator_to_array($iterable)); @@ -97,7 +97,7 @@ public function test_get_array(): void $this->violationStore->add($violation1); $this->violationStore->add($violation2); - $this->assertEquals([ + self::assertEquals([ $this->violation, $violation1, $violation2, @@ -118,15 +118,15 @@ public function test_remove_violations_from_violations(): void ); $this->violationStore->add($violation2); - $this->assertCount(3, $this->violationStore->toArray()); + self::assertCount(3, $this->violationStore->toArray()); $violationsBaseline = new Violations(); $violationsBaseline->add($this->violation); $this->violationStore->remove($violationsBaseline); - $this->assertCount(2, $this->violationStore->toArray()); - $this->assertEquals([ + self::assertCount(2, $this->violationStore->toArray()); + self::assertEquals([ $violation1, $violation2, ], $this->violationStore->toArray()); @@ -160,7 +160,7 @@ public function test_sort(): void $violationStore->add($violation3); $violationStore->add($violation4); - $this->assertEquals([ + self::assertEquals([ $violation1, $violation2, $violation3, @@ -169,7 +169,7 @@ public function test_sort(): void $violationStore->sort(); - $this->assertSame([ + self::assertSame([ $violation4, // fqcn is most important $violation3, // then line number $violation2, // then error message @@ -200,7 +200,7 @@ public function test_remove_violations_from_violations_ignore_linenumber(): void ); $this->violationStore->add($violation3); - $this->assertCount(4, $this->violationStore->toArray()); + self::assertCount(4, $this->violationStore->toArray()); $violationsBaseline = new Violations(); $violationsBaseline->add(new Violation( @@ -211,8 +211,8 @@ public function test_remove_violations_from_violations_ignore_linenumber(): void $this->violationStore->remove($violationsBaseline, true); - $this->assertCount(3, $this->violationStore->toArray()); - $this->assertEquals([ + self::assertCount(3, $this->violationStore->toArray()); + self::assertEquals([ $this->violation, $violation2, $violation3, diff --git a/tests/Utils/TestRunner.php b/tests/Utils/TestRunner.php index 5eea5e18..f166d6c3 100644 --- a/tests/Utils/TestRunner.php +++ b/tests/Utils/TestRunner.php @@ -23,14 +23,14 @@ class TestRunner private FileParser $fileParser; - private function __construct(string $version = null) + private function __construct(?string $version = null) { $this->violations = new Violations(); $this->parsingErrors = new ParsingErrors(); $this->fileParser = FileParserFactory::createFileParser(TargetPhpVersion::create($version)); } - public static function create(string $version = null): self + public static function create(?string $version = null): self { if (null === self::$instance) { self::$instance = new self($version);