diff --git a/src/Configuration/OutputPath.php b/src/Configuration/OutputPath.php index fc01421d..e2b4d217 100644 --- a/src/Configuration/OutputPath.php +++ b/src/Configuration/OutputPath.php @@ -17,9 +17,6 @@ public function __construct(string $path) $this->path = $path; } - /** - * @throws \RuntimeException - */ public function getPath(): string { return $this->path; diff --git a/src/Logs/ValueObject/LogData.php b/src/Logs/ValueObject/LogData.php index 2b0a0db6..f791cd73 100644 --- a/src/Logs/ValueObject/LogData.php +++ b/src/Logs/ValueObject/LogData.php @@ -13,7 +13,7 @@ public function __construct( ) {} /** - * @psalm-assert array{status: string, test: string|array, message?: string|null} $log + * @psalm-assert array{status: string, test: string|array, message?: string|null} $log */ private static function validateLogFormat(mixed $log): void { diff --git a/src/Logs/ValueObject/TestMethod.php b/src/Logs/ValueObject/TestMethod.php index a0636867..b259b76b 100644 --- a/src/Logs/ValueObject/TestMethod.php +++ b/src/Logs/ValueObject/TestMethod.php @@ -55,22 +55,17 @@ private static function validate(mixed $data): void throw self::invalidDeserializeInput($data); } - self::assertPropertyIsString(self::CLASS_NAME, $data); - self::assertPropertyIsString(self::METHOD_NAME, $data); - self::assertPropertyIsString(self::FULL_NAME, $data); - } + $properties = [ + self::CLASS_NAME, + self::METHOD_NAME, + self::FULL_NAME, + ]; + + foreach ($properties as $property) { + if (is_string($data[$property] ?? null)) { + continue; + } - /** - * @template T of string - * - * @param T $property - * @param mixed[] $data - * - * @psalm-assert array{T: string, ...} $data - */ - private static function assertPropertyIsString(string $property, array $data): void - { - if (! is_string($data[$property] ?? false)) { throw new \InvalidArgumentException($property . ' field missing or invalid'); } } diff --git a/tests/BaseIntegrationTestCase.php b/tests/BaseIntegrationTestCase.php index 516cec4f..19a6a698 100644 --- a/tests/BaseIntegrationTestCase.php +++ b/tests/BaseIntegrationTestCase.php @@ -83,7 +83,6 @@ protected function assertOutputOrder(UnformattedOutputStub $output, array $strin $previousPosition = 0; $previousString = ''; foreach ($strings as $string) { - /** @var int $position */ $position = strpos($output->getOutput(), $string, $previousPosition); $this->assertNotFalse($position, $output->getOutput() . PHP_EOL . 'String not found: ' . $string); $this->assertGreaterThan( diff --git a/tests/Functional/Command/CoverageCommandTest.php b/tests/Functional/Command/CoverageCommandTest.php index 7a50c46b..7a63715e 100644 --- a/tests/Functional/Command/CoverageCommandTest.php +++ b/tests/Functional/Command/CoverageCommandTest.php @@ -140,7 +140,6 @@ public function testExecutionWithTextSummaryToConsole(): void private function getTempCoverageFilename(): string { - /** @var string $filename */ $filename = tempnam(sys_get_temp_dir(), 'coverage.txt'); $this->assertNotFalse($filename); diff --git a/tests/Functional/Printer/FilesRecapPrinterTest.php b/tests/Functional/Printer/FilesRecapPrinterTest.php index 7ae14e4c..f5ca34bf 100644 --- a/tests/Functional/Printer/FilesRecapPrinterTest.php +++ b/tests/Functional/Printer/FilesRecapPrinterTest.php @@ -16,7 +16,6 @@ public function testOnEngineEndPrintsInTheRightOrder(): void $this->populateTestResultContainerWithAllPossibleStatuses(); $printer = $this->getService(FilesRecapPrinter::class); - $this->assertInstanceOf(FilesRecapPrinter::class, $printer); $printer->onEngineEnd(); @@ -47,7 +46,6 @@ public function testRegressionDuplicateFilesDueToMethodNames(): void $output = $this->getConsoleOutput(); $runner = $this->getService(Runner::class); - $this->assertInstanceOf(Runner::class, $runner); $this->assertNotEquals(0, $runner->run()); $this->assertOutputOrder($output, [ diff --git a/tests/Unit/Configuration/CoverageConfigurationTest.php b/tests/Unit/Configuration/CoverageConfigurationTest.php index 9608911d..c521e39c 100644 --- a/tests/Unit/Configuration/CoverageConfigurationTest.php +++ b/tests/Unit/Configuration/CoverageConfigurationTest.php @@ -32,7 +32,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Tests\BaseUnitTestCase; class CoverageConfigurationTest extends BaseUnitTestCase @@ -110,9 +109,7 @@ public function testBuildContainerWithDebug(): void $container = $paraunit->buildContainer($input->reveal(), $output->reveal()); - $service = $this->getService($container, DebugPrinter::class); // test instantiation, to prevent misconfiguration - $this->assertInstanceOf(DebugPrinter::class, $service); - $this->assertInstanceOf(EventSubscriberInterface::class, $service); + $this->getService($container, DebugPrinter::class); // test instantiation, to prevent misconfiguration } #[DataProvider('cliOptionsProvider')] @@ -257,10 +254,17 @@ public function testBuildContainerWithColoredTextToConsoleCoverage(): void $this->assertTrue($property->getValue($processor)); } + /** + * @template T of object + * + * @param class-string $serviceName + * + * @return T + */ private function getService(ContainerBuilder $container, string $serviceName): object { $service = $container->get(sprintf(CoverageConfiguration::PUBLIC_ALIAS_FORMAT, $serviceName)); - $this->assertNotNull($service); + $this->assertInstanceOf($serviceName, $service); return $service; } diff --git a/tests/Unit/Configuration/ParallelConfigurationTest.php b/tests/Unit/Configuration/ParallelConfigurationTest.php index 28ded92f..2252531a 100644 --- a/tests/Unit/Configuration/ParallelConfigurationTest.php +++ b/tests/Unit/Configuration/ParallelConfigurationTest.php @@ -98,8 +98,8 @@ public function testBuildContainerWithDebug(): void // test instantiation, to prevent misconfiguration $service = $this->getService($container, DebugPrinter::class); - $this->assertInstanceOf(DebugPrinter::class, $service); $this->assertInstanceOf(EventSubscriberInterface::class, $service); + $this->assertInstanceOf(DebugPrinter::class, $service); } public function testBuildContainerWithSortRandom(): void diff --git a/tests/Unit/Logs/LogFetcherTest.php b/tests/Unit/Logs/LogFetcherTest.php index 2dbabccf..b9971a61 100644 --- a/tests/Unit/Logs/LogFetcherTest.php +++ b/tests/Unit/Logs/LogFetcherTest.php @@ -25,7 +25,6 @@ public function testFetchReturnsEmptyListWithMissingLog(): void $logs = $fetcher->fetch($process); - $this->assertNotNull($logs, 'Fetcher returning a non-array'); $this->assertEmpty($logs); } @@ -42,12 +41,10 @@ public function testFetch(): void $logs = $fetcher->fetch($process); - $this->assertNotNull($logs, 'Fetcher returning a non-array'); $this->assertCount(4 + 1, $logs, 'Log ending missing'); $this->assertContainsOnlyInstancesOf(LogData::class, $logs); $endingLog = end($logs); - $this->assertInstanceOf(LogData::class, $endingLog); $this->assertEquals(LogStatus::LogTerminated, $endingLog->status); $this->assertFileDoesNotExist($filename, 'Log file should be deleted to preserve memory'); diff --git a/tests/Unit/Logs/ValueObject/LogDataTest.php b/tests/Unit/Logs/ValueObject/LogDataTest.php index af81e745..18a2bf8b 100644 --- a/tests/Unit/Logs/ValueObject/LogDataTest.php +++ b/tests/Unit/Logs/ValueObject/LogDataTest.php @@ -32,7 +32,6 @@ public function testLogEnding(): void $logStubEntry = $parsedResult[0]; $this->assertEquals($logData, $logStubEntry); $logEndingEntry = $parsedResult[1]; - $this->assertInstanceOf(LogData::class, $logEndingEntry); $this->assertEquals($logData->test, $logEndingEntry->test); $this->assertEquals(LogStatus::LogTerminated, $logEndingEntry->status); $this->assertNull($logEndingEntry->message); @@ -52,7 +51,6 @@ public function testSerializationWithSimpleTest(): void $parsedResult = LogData::parse(json_encode($logData, JSON_THROW_ON_ERROR)); $this->assertCount(2, $parsedResult); - $this->assertInstanceOf(LogData::class, $parsedResult[0]); $this->assertEquals($logData, $parsedResult[0]); $this->assertSame('Foo', $parsedResult[0]->test->name); } @@ -64,7 +62,6 @@ public function testSerializationWithTestMethod(): void $parsedResult = LogData::parse(json_encode($logData, JSON_THROW_ON_ERROR)); $this->assertCount(2, $parsedResult); - $this->assertInstanceOf(LogData::class, $parsedResult[0]); $this->assertEquals($logData, $parsedResult[0]); $this->assertObjectHasProperty('className', $parsedResult[0]->test); $this->assertObjectHasProperty('methodName', $parsedResult[0]->test); @@ -78,7 +75,6 @@ public function testSerializationError(): void $parsedResult = LogData::parse('{}'); $this->assertCount(2, $parsedResult); - $this->assertInstanceOf(LogData::class, $parsedResult[0]); $this->assertEquals(LogStatus::Unknown, $parsedResult[0]->status); $this->assertEquals(Test::unknown(), $parsedResult[0]->test); $this->assertIsString($parsedResult[0]->message); diff --git a/tests/Unit/Printer/DebugPrinterTest.php b/tests/Unit/Printer/DebugPrinterTest.php index 9214d01b..73890835 100644 --- a/tests/Unit/Printer/DebugPrinterTest.php +++ b/tests/Unit/Printer/DebugPrinterTest.php @@ -9,7 +9,6 @@ use Paraunit\Lifecycle\ProcessTerminated; use Paraunit\Lifecycle\ProcessToBeRetried; use Paraunit\Printer\DebugPrinter; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Tests\BaseUnitTestCase; use Tests\Stub\StubbedParaunitProcess; use Tests\Stub\UnformattedOutputStub; @@ -18,11 +17,6 @@ class DebugPrinterTest extends BaseUnitTestCase { public function testIsSubscribedToAllProcessEvents(): void { - $this->assertTrue( - is_subclass_of(DebugPrinter::class, EventSubscriberInterface::class), - DebugPrinter::class . ' is not an EventSubscriber!' - ); - $subscribedEvents = array_keys(DebugPrinter::getSubscribedEvents()); $processEvents = [ ProcessParsingCompleted::class, diff --git a/tests/Unit/Process/ProcessFactoryTest.php b/tests/Unit/Process/ProcessFactoryTest.php index e100add9..d8ab47c3 100644 --- a/tests/Unit/Process/ProcessFactoryTest.php +++ b/tests/Unit/Process/ProcessFactoryTest.php @@ -12,7 +12,6 @@ use Paraunit\Coverage\CoverageDriver; use Paraunit\Process\CommandLine; use Paraunit\Process\CommandLineWithCoverage; -use Paraunit\Process\Process; use Paraunit\Process\ProcessFactory; use PHPUnit\Framework\Attributes\DataProvider; use Tests\BaseUnitTestCase; @@ -51,14 +50,12 @@ public function testCreateProcess(): void $processWrapper = $factory->create('TestTest.php'); - $this->assertInstanceOf(Process::class, $processWrapper); $commandLine = $processWrapper->getCommandLine(); $this->assertStringContainsString('TestTest.php', $commandLine); $this->assertStringContainsString('--specific=value-for-TestTest.php', $commandLine); $processWrapper = $factory->create('TestTest2.php'); - $this->assertInstanceOf(Process::class, $processWrapper); $commandLine = $processWrapper->getCommandLine(); $this->assertStringContainsString('TestTest2.php', $commandLine); $this->assertStringContainsString('--specific=value-for-TestTest2.php', $commandLine); @@ -137,7 +134,6 @@ public function testCreateProcessChunked(): void $processWrapper = $factory->create('phpunit.xml'); - $this->assertInstanceOf(Process::class, $processWrapper); $commandLine = $processWrapper->getCommandLine(); $this->assertStringContainsString('--configuration=phpunit.xml', $commandLine); $this->assertStringContainsString('--specific=value-for-phpunit.xml', $commandLine);