Skip to content

Commit

Permalink
Enabled CS checks for the whole test suite, fixed nullability issues …
Browse files Browse the repository at this point in the history
…around `ReflectionClass#getMethod()`
  • Loading branch information
Ocramius committed Oct 10, 2022
1 parent a961932 commit 12b6aff
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 274 deletions.
14 changes: 3 additions & 11 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@

<file>./bin</file>
<file>./src</file>
<file>./test/e2e</file>
<file>./test/unit</file>

<rule ref="Doctrine">
<exclude-pattern>src/DetectChanges/BCBreak/InterfaceBased/InterfaceBased.php</exclude-pattern>
<exclude-pattern>test/unit/Formatter/ReflectionFunctionAbstractNameTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ParameterByReferenceChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/RequiredParameterAmountIncreasedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeByReferenceChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeCovarianceChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ParameterDefaultValueChangedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantVisibilityReducedTest.php</exclude-pattern>
<exclude-pattern>test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php</exclude-pattern>
<!-- `InterfaceBased` checks have the `Interface` prefix on purpose: that is intentional -->
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousPrefix"/>
</rule>
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

interface InterfaceBased
{
public function __invoke(ReflectionClass $fromInterface, ReflectionClass $toInterface) : Changes;
public function __invoke(ReflectionClass $fromInterface, ReflectionClass $toInterface): Changes;
}
42 changes: 20 additions & 22 deletions test/e2e/Command/AssertBackwardsCompatibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
namespace RoaveE2ETest\BackwardCompatibility\Command;

use PHPUnit\Framework\TestCase;
use Psl\Shell;
use Psl\Filesystem;
use Psl\Env;
use Psl\Filesystem;
use Psl\Shell;
use Psl\Str;

/**
* @coversNothing
*/
/** @coversNothing */
final class AssertBackwardsCompatibleTest extends TestCase
{
private const COMPOSER_MANIFEST = <<<'JSON'
Expand Down Expand Up @@ -51,7 +49,7 @@ public function method(A $a)
}

PHP
,
,
<<<'PHP'
<?php
Expand All @@ -71,7 +69,7 @@ public function method(B $a)
}

PHP
,
,
<<<'PHP'
<?php
Expand All @@ -91,7 +89,7 @@ public function method(C $a)
}

PHP
,
,
// The last version resets the class to its initial state
<<<'PHP'
<?php
Expand All @@ -111,7 +109,7 @@ public function method(A $a)
}
}

PHP
PHP,
];

/** @var string path to the sources that should be checked */
Expand All @@ -120,7 +118,7 @@ public function method(A $a)
/** @var string[] sha1 of the source versions */
private array $versions = [];

protected function setUp() : void
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -154,7 +152,7 @@ protected function setUp() : void
}
}

protected function tearDown() : void
protected function tearDown(): void
{
self::assertNotEmpty($this->sourcesRepository);
self::assertDirectoryExists($this->sourcesRepository);
Expand All @@ -165,7 +163,7 @@ protected function tearDown() : void
parent::tearDown();
}

public function testWillAllowSpecifyingGitRevision() : void
public function testWillAllowSpecifyingGitRevision(): void
{
try {
Shell\execute(__DIR__ . '/../../../bin/roave-backward-compatibility-check', [
Expand All @@ -180,26 +178,26 @@ public function testWillAllowSpecifyingGitRevision() : void

EXPECTED
,
$exception->getErrorOutput() // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
$exception->getErrorOutput(), // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
);
self::assertSame(3, $exception->getCode());
}
}

public function testWillNotRunWithoutTagsNorSpecifiedVersions() : void
public function testWillNotRunWithoutTagsNorSpecifiedVersions(): void
{
try {
Shell\execute(__DIR__ . '/../../../bin/roave-backward-compatibility-check', [], $this->sourcesRepository);
} catch (Shell\Exception\FailedExecutionException $exception) {
self::assertSame(1, $exception->getCode());
self::assertStringContainsString(
'Could not detect any released versions for the given repository',
$exception->getErrorOutput()
$exception->getErrorOutput(),
);
}
}

public function testWillRunSuccessfullyOnNoBcBreaks() : void
public function testWillRunSuccessfullyOnNoBcBreaks(): void
{
$output = Shell\execute(__DIR__ . '/../../../bin/roave-backward-compatibility-check', [
'--from=' . $this->versions[0],
Expand All @@ -210,7 +208,7 @@ public function testWillRunSuccessfullyOnNoBcBreaks() : void
self::assertEmpty($output);
}

public function testWillPickTaggedVersionOnNoGivenFrom() : void
public function testWillPickTaggedVersionOnNoGivenFrom(): void
{
$this->tagOnVersion('1.2.3', 1);

Expand All @@ -231,12 +229,12 @@ public function testWillPickTaggedVersionOnNoGivenFrom() : void

EXPECTED
,
$errorOutput // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
$errorOutput, // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
);
}
}

public function testWillPickLatestTaggedVersionOnNoGivenFrom() : void
public function testWillPickLatestTaggedVersionOnNoGivenFrom(): void
{
$this->tagOnVersion('2.2.3', 1);
$this->tagOnVersion('1.2.3', 3);
Expand All @@ -258,14 +256,14 @@ public function testWillPickLatestTaggedVersionOnNoGivenFrom() : void

EXPECTED
,
$errorOutput // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
$errorOutput, // @TODO https://github.com/Roave/BackwardCompatibilityCheck/issues/79 this looks like a symfony bug - we shouldn't check STDERR, but STDOUT
);
}
}

private function tagOnVersion(string $tagName, int $version) : void
private function tagOnVersion(string $tagName, int $version): void
{
Shell\execute('git', ['checkout', $this->versions[$version]], $this->sourcesRepository);
Shell\execute('git', ['tag', $tagName, '-m', 'A tag for version ' . $version,], $this->sourcesRepository);
Shell\execute('git', ['tag', $tagName, '-m', 'A tag for version ' . $version], $this->sourcesRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
use Roave\BetterReflection\Reflector\DefaultReflector;
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;

use function array_combine;
use function array_keys;
use function array_map;
use function iterator_to_array;
use function array_combine;

/**
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantVisibilityReduced
*/
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantVisibilityReduced */
final class ClassConstantVisibilityReducedTest extends TestCase
{
/**
* @dataProvider constantsToBeTested
*
* @param string[] $expectedMessages
*
* @dataProvider constantsToBeTested
*/
public function testDiffs(
ReflectionClassConstant $fromConstant,
ReflectionClassConstant $toConstant,
array $expectedMessages
) : void {
array $expectedMessages,
): void {
$changes = (new ClassConstantVisibilityReduced())($fromConstant, $toConstant);

self::assertSame(
$expectedMessages,
array_map(function (Change $change) : string {
array_map(static function (Change $change): string {
return $change->__toString();
}, iterator_to_array($changes))
}, iterator_to_array($changes)),
);
}

Expand All @@ -48,7 +48,7 @@ public function testDiffs(
* 2: list<string>
* }>
*/
public function constantsToBeTested() : array
public function constantsToBeTested(): array
{
$astLocator = (new BetterReflection())->astLocator();

Expand All @@ -69,7 +69,7 @@ class TheClass {
}
PHP
,
$astLocator
$astLocator,
);

$toLocator = new StringSourceLocator(
Expand All @@ -89,7 +89,7 @@ class TheClass {
}
PHP
,
$astLocator
$astLocator,
);

$fromClassReflector = new DefaultReflector($fromLocator);
Expand All @@ -100,16 +100,10 @@ class TheClass {
$properties = [

'publicMaintainedPublic' => [],
'publicReducedToProtected' => [
'[BC] CHANGED: Constant TheClass::publicReducedToProtected visibility reduced from public to protected',
],
'publicReducedToPrivate' => [
'[BC] CHANGED: Constant TheClass::publicReducedToPrivate visibility reduced from public to private',
],
'publicReducedToProtected' => ['[BC] CHANGED: Constant TheClass::publicReducedToProtected visibility reduced from public to protected'],
'publicReducedToPrivate' => ['[BC] CHANGED: Constant TheClass::publicReducedToPrivate visibility reduced from public to private'],
'protectedMaintainedProtected' => [],
'protectedReducedToPrivate' => [
'[BC] CHANGED: Constant TheClass::protectedReducedToPrivate visibility reduced from protected to private',
],
'protectedReducedToPrivate' => ['[BC] CHANGED: Constant TheClass::protectedReducedToPrivate visibility reduced from protected to private'],
'protectedIncreasedToPublic' => [],
'privateMaintainedPrivate' => [],
'privateIncreasedToProtected' => [],
Expand All @@ -127,8 +121,8 @@ class TheClass {
$errorMessages,
],
array_keys($properties),
$properties
)
$properties,
),
);
}
}
Loading

0 comments on commit 12b6aff

Please sign in to comment.