Skip to content

Commit

Permalink
Run rector rules for tests/phpunit folder (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Mar 23, 2024
1 parent 0aa8299 commit bde0f4a
Show file tree
Hide file tree
Showing 67 changed files with 471 additions and 655 deletions.
3 changes: 1 addition & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
// TODO uncomment as a separate PR
// __DIR__ . '/tests/phpunit',
__DIR__ . '/tests/phpunit',
])
->withPhpSets(php81: true)
->withSkip([
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/AutoReview/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public function getContainerFiles(): array
}

self::$containerFiles = array_map(
static function (string $path): string {
return Path::canonicalize($path);
},
static fn (string $path): string => Path::canonicalize($path),
[
__DIR__ . '/ContainerTest.php',
__DIR__ . '/../ContainerTest.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public static function provideEnvTestCaseTuple(): iterable
}

self::$envTestCaseClassesTuple = array_values(array_filter(array_map(
static function (string $className): ?array {
return self::envTestCaseTuple($className);
},
static fn (string $className): ?array => self::envTestCaseTuple($className),
iterator_to_array(ProjectCodeProvider::provideSourceClasses(), true),
)));

Expand Down
7 changes: 2 additions & 5 deletions tests/phpunit/AutoReview/Event/SubscriberProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ public static function provideSubscriberClasses(): iterable

self::$subscriberClasses = array_values(array_filter(
iterator_to_array(ProjectCodeProvider::provideSourceClasses(), true),
static function (string $class): bool {
return $class !== EventSubscriber::class
&& (new ReflectionClass($class))->implementsInterface(EventSubscriber::class)
;
},
static fn (string $class): bool => $class !== EventSubscriber::class
&& (new ReflectionClass($class))->implementsInterface(EventSubscriber::class),
));

yield from self::$subscriberClasses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public static function provideIoTestCaseTuple(): iterable
}

self::$ioTestCaseClassesTuple = array_values(array_filter(array_map(
static function (string $className): ?array {
return self::ioTestCaseTuple($className);
},
static fn (string $className): ?array => self::ioTestCaseTuple($className),
iterator_to_array(ProjectCodeProvider::provideSourceClasses(), true),
)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function test_the_test_cases_requiring_io_operations_belongs_to_the_integ
$this->failWithIntegrationGroupMessage($testCaseClassName, $fileWithIoOperations);
}

private function failWithIntegrationGroupMessage(string $testCaseClassName, string $fileWithIoOperations): void
private function failWithIntegrationGroupMessage(string $testCaseClassName, string $fileWithIoOperations): never
{
$this->fail(sprintf(
<<<'TXT'
Expand Down
5 changes: 3 additions & 2 deletions tests/phpunit/AutoReview/Makefile/MakefileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use PHPUnit\Framework\Attributes\Group;
use function Safe\array_replace;
use function sprintf;
use function str_ends_with;
use function str_starts_with;
use function substr;
use function substr_count;
Expand Down Expand Up @@ -284,8 +285,8 @@ protected function getExpectedHelpOutput(): string
private static function getTestRules(bool $dockerTargets): array
{
$filterDockerTarget = $dockerTargets
? static fn (string $target) => substr($target, -7) === '-docker'
: static fn (string $target) => substr($target, -7) !== '-docker';
? static fn (string $target) => str_ends_with($target, '-docker')
: static fn (string $target) => !str_ends_with($target, '-docker');

return array_values(
array_filter(
Expand Down
8 changes: 2 additions & 6 deletions tests/phpunit/AutoReview/Mutator/MutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,10 @@ class_implements($configClassName),
private function getPublicMethods(ReflectionClass $reflectionClass): array
{
$publicMethods = array_map(
static function (ReflectionMethod $reflectionMethod): string {
return $reflectionMethod->getName();
},
static fn (ReflectionMethod $reflectionMethod): string => $reflectionMethod->getName(),
array_filter(
$reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC),
static function (ReflectionMethod $reflectionMethod): bool {
return !$reflectionMethod->isConstructor();
},
static fn (ReflectionMethod $reflectionMethod): bool => !$reflectionMethod->isConstructor(),
),
);

Expand Down
16 changes: 7 additions & 9 deletions tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,13 @@ public static function provideSourceClasses(): iterable
;

$classes = array_map(
static function (SplFileInfo $file): string {
return sprintf(
'%s\\%s%s%s',
'Infection',
str_replace(DIRECTORY_SEPARATOR, '\\', $file->getRelativePath()),
$file->getRelativePath() !== '' ? '\\' : '',
$file->getBasename('.' . $file->getExtension()),
);
},
static fn (SplFileInfo $file): string => sprintf(
'%s\\%s%s%s',
'Infection',
str_replace(DIRECTORY_SEPARATOR, '\\', $file->getRelativePath()),
$file->getRelativePath() !== '' ? '\\' : '',
$file->getBasename('.' . $file->getExtension()),
),
iterator_to_array($finder, false),
);
sort($classes, SORT_STRING);
Expand Down
16 changes: 6 additions & 10 deletions tests/phpunit/AutoReview/ProjectCode/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,14 @@ public function test_source_classes_do_not_expose_public_properties(string $clas
// we're extending from, e.g. we can't change Symfony\Component\Process\Process to not have
// a public property it has.
$propertyNames = array_map(
static function (ReflectionProperty $reflectionProperty): string {
return sprintf(
'%s#%s',
$reflectionProperty->getDeclaringClass()->getName(),
$reflectionProperty->getName(),
);
},
static fn (ReflectionProperty $reflectionProperty): string => sprintf(
'%s#%s',
$reflectionProperty->getDeclaringClass()->getName(),
$reflectionProperty->getName(),
),
array_filter(
$properties,
static function (ReflectionProperty $property) use ($className): bool {
return $property->class === $className;
},
static fn (ReflectionProperty $property): bool => $property->class === $className,
),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/AutoReview/SourceTestClassNameScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class SourceTestClassNameScheme
public static function getSourceClassName(string $testCaseClassName): string
{
if (preg_match('/(Infection\\\\Tests\\\\.*)Test$/', $testCaseClassName, $matches) === 1) {
return str_replace('Infection\\Tests\\', 'Infection\\', $matches[1]);
return str_replace('Infection\\Tests\\', 'Infection\\', (string) $matches[1]);
}

return $testCaseClassName;
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/Configuration/ConfigurationAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ private function assertConfigurationStateIs(
private static function normalizePaths(array $fileInfos): array
{
return array_map(
static function (SplFileInfo $fileInfo): string {
return $fileInfo->getPathname();
},
static fn (SplFileInfo $fileInfo): string => $fileInfo->getPathname(),
$fileInfos,
);
}
Expand Down
18 changes: 7 additions & 11 deletions tests/phpunit/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,10 @@ public static function valueProvider(): iterable
],
'AssignmentEqual,EqualIdentical',
false,
(static function (): array {
return [
'AssignmentEqual' => new AssignmentEqual(),
'EqualIdentical' => new EqualIdentical(),
];
})(),
(static fn (): array => [
'AssignmentEqual' => new AssignmentEqual(),
'EqualIdentical' => new EqualIdentical(),
])(),
);

yield 'with source files' => [
Expand Down Expand Up @@ -932,11 +930,9 @@ public static function valueProvider(): iterable
'/path/to/config/phpunit-dir',
'config/phpunit',
),
(static function (): array {
return [
'TrueValue' => new TrueValue(new TrueValueConfig([])),
];
})(),
(static fn (): array => [
'TrueValue' => new TrueValue(new TrueValueConfig([])),
])(),
'phpspec',
'config/bootstrap.php',
'-d zend_extension=xdebug.so',
Expand Down

0 comments on commit bde0f4a

Please sign in to comment.