Skip to content

Commit

Permalink
Update cdn77/coding-standard requirement from ^5.0 to ^6.0 (#27)
Browse files Browse the repository at this point in the history
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](cdn77/coding-standard@v5.0.0...6.0.0)

---
updated-dependencies:
- dependency-name: cdn77/coding-standard
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: Simon Podlipsky <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Simon Podlipsky <[email protected]>
  • Loading branch information
dependabot[bot] and simPod authored Feb 23, 2022
1 parent 49714da commit c05e3c0
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 78 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
14 changes: 3 additions & 11 deletions src/TestCheck/EveryTestHasGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,15 @@

final class EveryTestHasGroup implements TestCheck
{
/** @var list<string> */
private array $allowedGroups;

/** @var iterable<string> */
private iterable $filePathNames;

/**
* @param iterable<string> $filePathNames
* @param list<string> $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));
Expand All @@ -39,7 +31,7 @@ public function run(TestCase $testCaseContext) : void
}

/** @param ReflectionClass<object> $reflectionClass */
private function validateDocComment(TestCase $testCaseContext, ReflectionClass $reflectionClass) : void
private function validateDocComment(TestCase $testCaseContext, ReflectionClass $reflectionClass): void
{
$docComment = $reflectionClass->getDocComment();
if ($docComment === false) {
Expand Down
8 changes: 2 additions & 6 deletions src/TestCheck/EveryTestHasSameNamespaceAsTestedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ final class EveryTestHasSameNamespaceAsTestedClass implements TestCheck
{
private const PATTERN = '~\* @testedClass (?<targetClass>.+?)(?:\n| \*/)~';

/** @var iterable<string> $filePathNames */
private iterable $filePathNames;

private string $testsNamespaceSuffix;

/** @param iterable<string> $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);

Expand Down
16 changes: 4 additions & 12 deletions src/TestCheck/EveryTestInheritsFromTestCaseBaseClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@

final class EveryTestInheritsFromTestCaseBaseClass implements TestCheck
{
/** @var iterable<string> $filePathNames */
private iterable $filePathNames;

/** @var class-string<TestCase> */
private string $testCaseBaseClass;

/**
* @param iterable<string> $filePathNames
* @param class-string<TestCase> $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);

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/TestCheck/EveryTestIsFinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@

final class EveryTestIsFinal implements TestCheck
{
/** @var iterable<string> $filePathNames */
private iterable $filePathNames;

/** @param iterable<string> $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));
Expand Down
2 changes: 1 addition & 1 deletion src/TestCheck/TestCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface TestCheck
{
public function run(TestCase $testCaseContext) : void;
public function run(TestCase $testCaseContext): void;
}
15 changes: 4 additions & 11 deletions tests/SimpleClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions tests/SimpleParentClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -20,29 +20,29 @@ 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');

Stub::create(SimpleClass::class, ['nonexistentProperty' => 'value']);
}

public function testExtend() : void
public function testExtend(): void
{
$stub = Stub::create(SimpleClass::class, ['property1' => 'value']);

Expand Down
8 changes: 4 additions & 4 deletions tests/TestCheck/EveryTestHasGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

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;
}

self::fail('Unexpected check outcome');
}

/** @return Generator<list<string>> */
public function providerFail() : Generator
public function providerFail(): Generator
{
yield ['WithoutGroup.php'];
yield ['WithUnlistedGroup.php'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -22,15 +22,15 @@ public function testSuccess(string $filePath) : void
}

/** @return Generator<array-key, list<string>> */
public function providerSuccess() : Generator
public function providerSuccess(): Generator
{
yield ['SameNamespaceTest.php'];
yield ['SameNamespaceLinkedTest.php'];
yield ['NoLinkTest.php'];
}

/** @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);
Expand All @@ -43,7 +43,7 @@ public function testFail(string $filePath, string $error) : void
}

/** @return Generator<array-key, list<string>> */
public function providerFail() : Generator
public function providerFail(): Generator
{
yield [
'MissingAnnotationsTest.php',
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCheck/EveryTestInheritsFromTestCaseBaseClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -22,31 +22,31 @@ public function testSuccess(string $filePath) : void
}

/** @return Generator<list<string>> */
public function providerSuccess() : Generator
public function providerSuccess(): Generator
{
yield ['ExtendsBase.php'];
yield ['ExtendsBaseUsingParent.php'];
yield ['../../BaseTestCase.php'];
}

/** @dataProvider providerFail */
public function testFail(string $filePath) : void
public function testFail(string $filePath): void
{
try {
$check = new EveryTestInheritsFromTestCaseBaseClass(
[__DIR__ . '/Fixtures/' . $filePath],
BaseTestCase::class
);
$check->run($this);
} catch (AssertionFailedError $exception) {
} catch (AssertionFailedError) {
return;
}

self::fail('Unexpected check outcome');
}

/** @return Generator<list<string>> */
public function providerFail() : Generator
public function providerFail(): Generator
{
yield ['DoesNotExtendAnything.php'];
yield ['DoesNotExtendBase.php'];
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCheck/EveryTestIsFinalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c05e3c0

Please sign in to comment.