From c05e3c08afaf1c2682485545e6d5920de54d046a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Feb 2022 18:48:19 +0100 Subject: [PATCH] Update cdn77/coding-standard requirement from ^5.0 to ^6.0 (#27) Updates the requirements on [cdn77/coding-standard](https://github.com/cdn77/coding-standard) to permit the latest version. - [Release notes](https://github.com/cdn77/coding-standard/releases) - [Commits](https://github.com/cdn77/coding-standard/compare/v5.0.0...6.0.0) --- updated-dependencies: - dependency-name: cdn77/coding-standard dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: Simon Podlipsky Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Simon Podlipsky --- composer.json | 2 +- src/Stub.php | 8 ++++---- src/TestCheck/EveryTestHasGroup.php | 14 +++----------- .../EveryTestHasSameNamespaceAsTestedClass.php | 8 ++------ .../EveryTestInheritsFromTestCaseBaseClass.php | 16 ++++------------ src/TestCheck/EveryTestIsFinal.php | 8 ++------ src/TestCheck/TestCheck.php | 2 +- tests/SimpleClass.php | 15 ++++----------- tests/SimpleParentClass.php | 7 ++----- tests/StubTest.php | 10 +++++----- tests/TestCheck/EveryTestHasGroupTest.php | 8 ++++---- ...veryTestHasSameNamespaceAsTestedClassTest.php | 8 ++++---- ...veryTestInheritsFromTestCaseBaseClassTest.php | 10 +++++----- tests/TestCheck/EveryTestIsFinalTest.php | 6 +++--- 14 files changed, 44 insertions(+), 78 deletions(-) diff --git a/composer.json b/composer.json index 3f0ec95..6f72bc2 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "thecodingmachine/safe": "^1.0.2" }, "require-dev": { - "cdn77/coding-standard": "^5.0", + "cdn77/coding-standard": "^6.0", "infection/infection": "^0.26.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1", diff --git a/src/Stub.php b/src/Stub.php index ffafd91..1555eae 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -22,7 +22,7 @@ final class Stub * * @template T of object */ - public static function create(string $class, array $properties = []) : object + public static function create(string $class, array $properties = []): object { $reflection = new ReflectionClass($class); @@ -49,7 +49,7 @@ public static function create(string $class, array $properties = []) : object * * @template T of object */ - public static function extend(object $stub, array $newProperties = []) : object + public static function extend(object $stub, array $newProperties = []): object { // phpstan has problem with analyzing this still // phpcs:ignore SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall @@ -77,7 +77,7 @@ public static function extend(object $stub, array $newProperties = []) : object * * @template T of object */ - private static function getClosestProperty(ReflectionClass $class, string $property) : ?ReflectionProperty + private static function getClosestProperty(ReflectionClass $class, string $property): ReflectionProperty|null { if ($class->hasProperty($property)) { return $class->getProperty($property); @@ -103,7 +103,7 @@ private static function getClosestProperty(ReflectionClass $class, string $prope * * @template T of object */ - private static function getAllProperties(ReflectionClass $reflection, array $properties = []) : array + private static function getAllProperties(ReflectionClass $reflection, array $properties = []): array { $properties = array_merge($reflection->getProperties(), $properties); diff --git a/src/TestCheck/EveryTestHasGroup.php b/src/TestCheck/EveryTestHasGroup.php index 52570f8..1d16d22 100644 --- a/src/TestCheck/EveryTestHasGroup.php +++ b/src/TestCheck/EveryTestHasGroup.php @@ -13,23 +13,15 @@ final class EveryTestHasGroup implements TestCheck { - /** @var list */ - private array $allowedGroups; - - /** @var iterable */ - private iterable $filePathNames; - /** * @param iterable $filePathNames * @param list $allowedGroups */ - public function __construct(iterable $filePathNames, array $allowedGroups) + public function __construct(private iterable $filePathNames, private array $allowedGroups) { - $this->allowedGroups = $allowedGroups; - $this->filePathNames = $filePathNames; } - public function run(TestCase $testCaseContext) : void + public function run(TestCase $testCaseContext): void { foreach ($this->filePathNames as $filePathName) { $classReflection = new ReflectionClass(ClassExtractor::get($filePathName)); @@ -39,7 +31,7 @@ public function run(TestCase $testCaseContext) : void } /** @param ReflectionClass $reflectionClass */ - private function validateDocComment(TestCase $testCaseContext, ReflectionClass $reflectionClass) : void + private function validateDocComment(TestCase $testCaseContext, ReflectionClass $reflectionClass): void { $docComment = $reflectionClass->getDocComment(); if ($docComment === false) { diff --git a/src/TestCheck/EveryTestHasSameNamespaceAsTestedClass.php b/src/TestCheck/EveryTestHasSameNamespaceAsTestedClass.php index 90a5e6a..57eca50 100644 --- a/src/TestCheck/EveryTestHasSameNamespaceAsTestedClass.php +++ b/src/TestCheck/EveryTestHasSameNamespaceAsTestedClass.php @@ -21,19 +21,15 @@ final class EveryTestHasSameNamespaceAsTestedClass implements TestCheck { private const PATTERN = '~\* @testedClass (?.+?)(?:\n| \*/)~'; - /** @var iterable $filePathNames */ - private iterable $filePathNames; - private string $testsNamespaceSuffix; /** @param iterable $filePathNames */ - public function __construct(iterable $filePathNames, string $testsNamespaceSuffix = 'Tests') + public function __construct(private iterable $filePathNames, string $testsNamespaceSuffix = 'Tests') { - $this->filePathNames = $filePathNames; $this->testsNamespaceSuffix = '\\' . $testsNamespaceSuffix . '\\'; } - public function run(TestCase $testCaseContext) : void + public function run(TestCase $testCaseContext): void { $testCaseContext::assertTrue(true); diff --git a/src/TestCheck/EveryTestInheritsFromTestCaseBaseClass.php b/src/TestCheck/EveryTestInheritsFromTestCaseBaseClass.php index d94899e..3e02c06 100644 --- a/src/TestCheck/EveryTestInheritsFromTestCaseBaseClass.php +++ b/src/TestCheck/EveryTestInheritsFromTestCaseBaseClass.php @@ -12,23 +12,15 @@ final class EveryTestInheritsFromTestCaseBaseClass implements TestCheck { - /** @var iterable $filePathNames */ - private iterable $filePathNames; - - /** @var class-string */ - private string $testCaseBaseClass; - /** * @param iterable $filePathNames * @param class-string $testCaseBaseClass */ - public function __construct(iterable $filePathNames, string $testCaseBaseClass) + public function __construct(private iterable $filePathNames, private string $testCaseBaseClass) { - $this->filePathNames = $filePathNames; - $this->testCaseBaseClass = $testCaseBaseClass; } - public function run(TestCase $testCaseContext) : void + public function run(TestCase $testCaseContext): void { $testCaseContext::assertTrue(true); @@ -62,8 +54,8 @@ public function run(TestCase $testCaseContext) : void private function assertParentClass( TestCase $testCaseContext, ReflectionClass $classReflection, - ReflectionClass $parentClassReflection - ) : void { + ReflectionClass $parentClassReflection, + ): void { if ($parentClassReflection->getName() === $this->testCaseBaseClass) { return; } diff --git a/src/TestCheck/EveryTestIsFinal.php b/src/TestCheck/EveryTestIsFinal.php index 9846efa..9730203 100644 --- a/src/TestCheck/EveryTestIsFinal.php +++ b/src/TestCheck/EveryTestIsFinal.php @@ -12,16 +12,12 @@ final class EveryTestIsFinal implements TestCheck { - /** @var iterable $filePathNames */ - private iterable $filePathNames; - /** @param iterable $filePathNames */ - public function __construct(iterable $filePathNames) + public function __construct(private iterable $filePathNames) { - $this->filePathNames = $filePathNames; } - public function run(TestCase $testCaseContext) : void + public function run(TestCase $testCaseContext): void { foreach ($this->filePathNames as $filePathName) { $classReflection = new ReflectionClass(ClassExtractor::get($filePathName)); diff --git a/src/TestCheck/TestCheck.php b/src/TestCheck/TestCheck.php index 196b81b..ea84850 100644 --- a/src/TestCheck/TestCheck.php +++ b/src/TestCheck/TestCheck.php @@ -8,5 +8,5 @@ interface TestCheck { - public function run(TestCase $testCaseContext) : void; + public function run(TestCase $testCaseContext): void; } diff --git a/tests/SimpleClass.php b/tests/SimpleClass.php index 20bf22e..73b9156 100644 --- a/tests/SimpleClass.php +++ b/tests/SimpleClass.php @@ -6,31 +6,24 @@ final class SimpleClass extends SimpleParentClass { - private string $property1; - - private string $property2; - private string $propertyWithDefaultValue = 'default value'; - public function __construct(string $property1, string $property2, string $property3) + public function __construct(private string $property1, private string $property2, string $property3) { - $this->property1 = $property1; - $this->property2 = $property2; - parent::__construct($property3); } - public function getProperty1() : string + public function getProperty1(): string { return $this->property1; } - public function getProperty2() : string + public function getProperty2(): string { return $this->property2; } - public function getPropertyWithDefaultValue() : string + public function getPropertyWithDefaultValue(): string { return $this->propertyWithDefaultValue; } diff --git a/tests/SimpleParentClass.php b/tests/SimpleParentClass.php index efed0c9..3bc0da4 100644 --- a/tests/SimpleParentClass.php +++ b/tests/SimpleParentClass.php @@ -6,14 +6,11 @@ class SimpleParentClass { - private string $parentProperty; - - public function __construct(string $parentProperty) + public function __construct(private string $parentProperty) { - $this->parentProperty = $parentProperty; } - public function getParentProperty() : string + public function getParentProperty(): string { return $this->parentProperty; } diff --git a/tests/StubTest.php b/tests/StubTest.php index b7a41d1..38857ad 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -10,7 +10,7 @@ final class StubTest extends BaseTestCase { - public function testValueIsDefaultWhenNotSet() : void + public function testValueIsDefaultWhenNotSet(): void { $this->expectException(Error::class); $this->expectExceptionMessage('must not be accessed before initialization'); @@ -20,21 +20,21 @@ public function testValueIsDefaultWhenNotSet() : void $stub->getProperty1(); } - public function testPropertyIsSetBypassingConstructor() : void + public function testPropertyIsSetBypassingConstructor(): void { $stub = Stub::create(SimpleClass::class, ['property1' => 'value']); self::assertSame('value', $stub->getProperty1()); } - public function testParentPropertyIsSetBypassingConstructor() : void + public function testParentPropertyIsSetBypassingConstructor(): void { $stub = Stub::create(SimpleClass::class, ['parentProperty' => 'value']); self::assertSame('value', $stub->getParentProperty()); } - public function testSettingNonexistentPropertyThrowsException() : void + public function testSettingNonexistentPropertyThrowsException(): void { $this->expectException(ReflectionException::class); $this->expectExceptionMessage('Property "nonexistentProperty" not found'); @@ -42,7 +42,7 @@ public function testSettingNonexistentPropertyThrowsException() : void Stub::create(SimpleClass::class, ['nonexistentProperty' => 'value']); } - public function testExtend() : void + public function testExtend(): void { $stub = Stub::create(SimpleClass::class, ['property1' => 'value']); diff --git a/tests/TestCheck/EveryTestHasGroupTest.php b/tests/TestCheck/EveryTestHasGroupTest.php index 6b2f74f..e1a7381 100644 --- a/tests/TestCheck/EveryTestHasGroupTest.php +++ b/tests/TestCheck/EveryTestHasGroupTest.php @@ -11,19 +11,19 @@ final class EveryTestHasGroupTest extends BaseTestCase { - public function testSuccess() : void + public function testSuccess(): void { $check = new EveryTestHasGroup([__DIR__ . '/Fixtures/WithGroup.php'], ['unit']); $check->run($this); } /** @dataProvider providerFail */ - public function testFail(string $filePath) : void + public function testFail(string $filePath): void { try { $check = new EveryTestHasGroup([__DIR__ . '/Fixtures/' . $filePath], ['unit']); $check->run($this); - } catch (AssertionFailedError $exception) { + } catch (AssertionFailedError) { return; } @@ -31,7 +31,7 @@ public function testFail(string $filePath) : void } /** @return Generator> */ - public function providerFail() : Generator + public function providerFail(): Generator { yield ['WithoutGroup.php']; yield ['WithUnlistedGroup.php']; diff --git a/tests/TestCheck/EveryTestHasSameNamespaceAsTestedClassTest.php b/tests/TestCheck/EveryTestHasSameNamespaceAsTestedClassTest.php index 6813790..f0da2b1 100644 --- a/tests/TestCheck/EveryTestHasSameNamespaceAsTestedClassTest.php +++ b/tests/TestCheck/EveryTestHasSameNamespaceAsTestedClassTest.php @@ -12,7 +12,7 @@ final class EveryTestHasSameNamespaceAsTestedClassTest extends BaseTestCase { /** @dataProvider providerSuccess */ - public function testSuccess(string $filePath) : void + public function testSuccess(string $filePath): void { $check = new EveryTestHasSameNamespaceAsTestedClass( [__DIR__ . '/Fixtures/EveryTestHasSameNamespaceAsTestedClass/tests/' . $filePath], @@ -22,7 +22,7 @@ public function testSuccess(string $filePath) : void } /** @return Generator> */ - public function providerSuccess() : Generator + public function providerSuccess(): Generator { yield ['SameNamespaceTest.php']; yield ['SameNamespaceLinkedTest.php']; @@ -30,7 +30,7 @@ public function providerSuccess() : Generator } /** @dataProvider providerFail */ - public function testFail(string $filePath, string $error) : void + public function testFail(string $filePath, string $error): void { $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage($error); @@ -43,7 +43,7 @@ public function testFail(string $filePath, string $error) : void } /** @return Generator> */ - public function providerFail() : Generator + public function providerFail(): Generator { yield [ 'MissingAnnotationsTest.php', diff --git a/tests/TestCheck/EveryTestInheritsFromTestCaseBaseClassTest.php b/tests/TestCheck/EveryTestInheritsFromTestCaseBaseClassTest.php index c254da0..0e1b186 100644 --- a/tests/TestCheck/EveryTestInheritsFromTestCaseBaseClassTest.php +++ b/tests/TestCheck/EveryTestInheritsFromTestCaseBaseClassTest.php @@ -12,7 +12,7 @@ final class EveryTestInheritsFromTestCaseBaseClassTest extends BaseTestCase { /** @dataProvider providerSuccess */ - public function testSuccess(string $filePath) : void + public function testSuccess(string $filePath): void { $check = new EveryTestInheritsFromTestCaseBaseClass( [__DIR__ . '/Fixtures/' . $filePath], @@ -22,7 +22,7 @@ public function testSuccess(string $filePath) : void } /** @return Generator> */ - public function providerSuccess() : Generator + public function providerSuccess(): Generator { yield ['ExtendsBase.php']; yield ['ExtendsBaseUsingParent.php']; @@ -30,7 +30,7 @@ public function providerSuccess() : Generator } /** @dataProvider providerFail */ - public function testFail(string $filePath) : void + public function testFail(string $filePath): void { try { $check = new EveryTestInheritsFromTestCaseBaseClass( @@ -38,7 +38,7 @@ public function testFail(string $filePath) : void BaseTestCase::class ); $check->run($this); - } catch (AssertionFailedError $exception) { + } catch (AssertionFailedError) { return; } @@ -46,7 +46,7 @@ public function testFail(string $filePath) : void } /** @return Generator> */ - public function providerFail() : Generator + public function providerFail(): Generator { yield ['DoesNotExtendAnything.php']; yield ['DoesNotExtendBase.php']; diff --git a/tests/TestCheck/EveryTestIsFinalTest.php b/tests/TestCheck/EveryTestIsFinalTest.php index 6e0327a..f9185e0 100644 --- a/tests/TestCheck/EveryTestIsFinalTest.php +++ b/tests/TestCheck/EveryTestIsFinalTest.php @@ -10,18 +10,18 @@ final class EveryTestIsFinalTest extends BaseTestCase { - public function testSuccess() : void + public function testSuccess(): void { $check = new EveryTestIsFinal([__DIR__ . '/Fixtures/FinalClass.php']); $check->run($this); } - public function testFail() : void + public function testFail(): void { try { $check = new EveryTestIsFinal([__DIR__ . '/Fixtures/NotFinalClass.php']); $check->run($this); - } catch (ExpectationFailedException $exception) { + } catch (ExpectationFailedException) { return; }