diff --git a/composer.json b/composer.json index 9a9a21ac..1f42fcbf 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,6 @@ "require-dev": { "doctrine/doctrine-bundle": "^2.0|^3.0", "league/flysystem-memory": "^3.0", - "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^11.0|^12.0", "sonata-project/admin-bundle": "^4.0", diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALInsertWriter.php b/src/batch-doctrine-dbal/src/DoctrineDBALInsertWriter.php index db1ee81c..2344cd3b 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALInsertWriter.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALInsertWriter.php @@ -14,7 +14,7 @@ * via a Doctrine {@see Connection}. * All items must be arrays. */ -final class DoctrineDBALInsertWriter implements ItemWriterInterface +final readonly class DoctrineDBALInsertWriter implements ItemWriterInterface { private Connection $connection; diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php index f700ab8b..0dce46d0 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php @@ -42,8 +42,8 @@ final class DoctrineDBALJobExecutionStorage implements 'connection' => null, ]; - private Connection $connection; - private string $table; + private readonly Connection $connection; + private readonly string $table; private JobExecutionRowNormalizer $normalizer; /** @@ -334,53 +334,53 @@ private function addWheres(Query $query, QueryBuilder $qb): array $queryTypes = []; $names = $query->jobs(); - if (\count($names) > 0) { + if ($names !== []) { $qb->andWhere($qb->expr()->in('job_name', ':jobNames')); $queryParameters['jobNames'] = $names; $queryTypes['jobNames'] = ArrayParameterType::STRING; } $ids = $query->ids(); - if (\count($ids) > 0) { + if ($ids !== []) { $qb->andWhere($qb->expr()->in('id', ':ids')); $queryParameters['ids'] = $ids; $queryTypes['ids'] = ArrayParameterType::STRING; } $statuses = $query->statuses(); - if (\count($statuses) > 0) { + if ($statuses !== []) { $qb->andWhere($qb->expr()->in('status', ':statuses')); $queryParameters['statuses'] = $statuses; $queryTypes['statuses'] = ArrayParameterType::INTEGER; } - if ($query->startTime()) { + if ($query->startTime() !== null) { $qb->andWhere($qb->expr()->isNotNull('start_time')); } $startDateFrom = $query->startTime()?->getFrom(); - if ($startDateFrom) { + if ($startDateFrom !== null) { $qb->andWhere($qb->expr()->gte('start_time', ':startDateFrom')); $queryParameters['startDateFrom'] = $startDateFrom; $queryTypes['startDateFrom'] = Types::DATETIME_IMMUTABLE; } $startDateTo = $query->startTime()?->getTo(); - if ($startDateTo) { + if ($startDateTo !== null) { $qb->andWhere($qb->expr()->lte('start_time', ':startDateTo')); $queryParameters['startDateTo'] = $startDateTo; $queryTypes['startDateTo'] = Types::DATETIME_IMMUTABLE; } - if ($query->endTime()) { + if ($query->endTime() !== null) { $qb->andWhere($qb->expr()->isNotNull('start_time')); } $endDateFrom = $query->endTime()?->getFrom(); - if ($endDateFrom) { + if ($endDateFrom !== null) { $qb->andWhere($qb->expr()->gte('end_time', ':endDateFrom')); $queryParameters['endDateFrom'] = $endDateFrom; $queryTypes['endDateFrom'] = Types::DATETIME_IMMUTABLE; } $endDateTo = $query->endTime()?->getTo(); - if ($endDateTo) { + if ($endDateTo !== null) { $qb->andWhere($qb->expr()->lte('end_time', ':endDateTo')); $queryParameters['endDateTo'] = $endDateTo; $queryTypes['endDateTo'] = Types::DATETIME_IMMUTABLE; diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALQueryCursorReader.php b/src/batch-doctrine-dbal/src/DoctrineDBALQueryCursorReader.php index bf3d5a2c..db149c60 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALQueryCursorReader.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALQueryCursorReader.php @@ -25,7 +25,7 @@ * In that case, {@see DoctrineDBALQueryCursorReader::$column} argument should be "id", * and if id is a numeric column {@see DoctrineDBALQueryCursorReader::$start} should be 0. */ -final class DoctrineDBALQueryCursorReader implements ItemReaderInterface +final readonly class DoctrineDBALQueryCursorReader implements ItemReaderInterface { private Connection $connection; diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALQueryOffsetReader.php b/src/batch-doctrine-dbal/src/DoctrineDBALQueryOffsetReader.php index df073a77..ec84ad46 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALQueryOffsetReader.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALQueryOffsetReader.php @@ -15,7 +15,7 @@ * This {@see ItemReaderInterface} executes an SQL query to a Doctrine connection, * and iterate over each result as an item. */ -final class DoctrineDBALQueryOffsetReader implements ItemReaderInterface +final readonly class DoctrineDBALQueryOffsetReader implements ItemReaderInterface { private Connection $connection; private string $sql; diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALUpsert.php b/src/batch-doctrine-dbal/src/DoctrineDBALUpsert.php index 83e54675..84b6998a 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALUpsert.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALUpsert.php @@ -8,7 +8,7 @@ * This model object is used by {@see DoctrineDBALUpsertWriter}. * It holds table, data and identity to perform upsert operation. */ -final class DoctrineDBALUpsert +final readonly class DoctrineDBALUpsert { public function __construct( private string $table, diff --git a/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php b/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php index c5f6eb69..d830dc70 100644 --- a/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php +++ b/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php @@ -19,7 +19,7 @@ /** * @internal */ -final class JobExecutionRowNormalizer +final readonly class JobExecutionRowNormalizer { public function __construct( private AbstractPlatform $platform, diff --git a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php index 60fdd2cc..bdaa6330 100644 --- a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php +++ b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php @@ -41,7 +41,7 @@ public function testCreateStandardTable(): void self::assertTrue($schemaManager->tablesExist(['yokai_batch_job_execution'])); $columns = $schemaManager->listTableColumns('yokai_batch_job_execution'); - self::assertEquals( + self::assertSame( [ 'id', 'job_name', @@ -68,7 +68,7 @@ public function testCreateCustomTable(): void self::assertTrue($schemaManager->tablesExist(['acme_job_executions'])); $columns = $schemaManager->listTableColumns('acme_job_executions'); - self::assertEquals( + self::assertSame( [ 'id', 'job_name', @@ -279,7 +279,7 @@ public function testQuery(QueryBuilder $queryBuilder, array $expectedCouples): v $this->loadFixtures($storage); self::assertExecutions($expectedCouples, $storage->query($queryBuilder->getQuery())); - self::assertSame(\count($expectedCouples), $storage->count($queryBuilder->getQuery())); + self::assertCount($storage->count($queryBuilder->getQuery()), $expectedCouples); } public static function queries(): Generator diff --git a/src/batch-doctrine-dbal/tests/Dummy/SingleConnectionRegistry.php b/src/batch-doctrine-dbal/tests/Dummy/SingleConnectionRegistry.php index b0fdcdba..758c7711 100644 --- a/src/batch-doctrine-dbal/tests/Dummy/SingleConnectionRegistry.php +++ b/src/batch-doctrine-dbal/tests/Dummy/SingleConnectionRegistry.php @@ -8,7 +8,7 @@ use Doctrine\Persistence\ConnectionRegistry; use InvalidArgumentException; -final class SingleConnectionRegistry implements ConnectionRegistry +final readonly class SingleConnectionRegistry implements ConnectionRegistry { public function __construct( private Connection $connection, diff --git a/src/batch-doctrine-orm/src/EntityReader.php b/src/batch-doctrine-orm/src/EntityReader.php index e1767a45..90ebb1af 100644 --- a/src/batch-doctrine-orm/src/EntityReader.php +++ b/src/batch-doctrine-orm/src/EntityReader.php @@ -12,7 +12,7 @@ /** * This {@see ItemReaderInterface} executes an SQL query to a Doctrine connection, */ -final class EntityReader implements ItemReaderInterface +final readonly class EntityReader implements ItemReaderInterface { public function __construct( private ManagerRegistry $doctrine, diff --git a/src/batch-doctrine-orm/tests/Dummy/SingleManagerRegistry.php b/src/batch-doctrine-orm/tests/Dummy/SingleManagerRegistry.php index e13f4817..c820f946 100644 --- a/src/batch-doctrine-orm/tests/Dummy/SingleManagerRegistry.php +++ b/src/batch-doctrine-orm/tests/Dummy/SingleManagerRegistry.php @@ -11,7 +11,7 @@ final class SingleManagerRegistry extends AbstractManagerRegistry { public function __construct( - private ObjectManager $manager, + private readonly ObjectManager $manager, ) { parent::__construct('ORM', ['default'], ['default'], 'default', 'default', Proxy::class); } diff --git a/src/batch-doctrine-orm/tests/Entity/User.php b/src/batch-doctrine-orm/tests/Entity/User.php index 05c3c208..0477610b 100644 --- a/src/batch-doctrine-orm/tests/Entity/User.php +++ b/src/batch-doctrine-orm/tests/Entity/User.php @@ -4,18 +4,19 @@ namespace Yokai\Batch\Tests\Bridge\Doctrine\ORM\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: 'user')] class User { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] public string $name; public function __construct(string $name) diff --git a/src/batch-doctrine-persistence/src/ObjectRegistry.php b/src/batch-doctrine-persistence/src/ObjectRegistry.php index 75ab7b61..3451df0d 100644 --- a/src/batch-doctrine-persistence/src/ObjectRegistry.php +++ b/src/batch-doctrine-persistence/src/ObjectRegistry.php @@ -21,7 +21,7 @@ final class ObjectRegistry private array $identities = []; public function __construct( - private ManagerRegistry $doctrine, + private readonly ManagerRegistry $doctrine, ) { } diff --git a/src/batch-doctrine-persistence/src/ObjectWriter.php b/src/batch-doctrine-persistence/src/ObjectWriter.php index 6ec3b158..6bb67e0b 100644 --- a/src/batch-doctrine-persistence/src/ObjectWriter.php +++ b/src/batch-doctrine-persistence/src/ObjectWriter.php @@ -26,7 +26,7 @@ final class ObjectWriter implements ItemWriterInterface private array $managerForClass = []; public function __construct( - private ManagerRegistry $doctrine, + private readonly ManagerRegistry $doctrine, ) { } diff --git a/src/batch-doctrine-persistence/tests/Dummy/DecoratedRepositoryFactory.php b/src/batch-doctrine-persistence/tests/Dummy/DecoratedRepositoryFactory.php index b3044a08..5fdb4aa5 100644 --- a/src/batch-doctrine-persistence/tests/Dummy/DecoratedRepositoryFactory.php +++ b/src/batch-doctrine-persistence/tests/Dummy/DecoratedRepositoryFactory.php @@ -19,8 +19,8 @@ public function __construct( /** * @var class-string */ - private string $class, - private RepositoryFactory $decorated, + private readonly string $class, + private readonly RepositoryFactory $decorated, ) { } diff --git a/src/batch-doctrine-persistence/tests/Dummy/FindOneByCalledOnlyOnceWhenFoundRepositoryDecorator.php b/src/batch-doctrine-persistence/tests/Dummy/FindOneByCalledOnlyOnceWhenFoundRepositoryDecorator.php index 3979e395..d4196ae0 100644 --- a/src/batch-doctrine-persistence/tests/Dummy/FindOneByCalledOnlyOnceWhenFoundRepositoryDecorator.php +++ b/src/batch-doctrine-persistence/tests/Dummy/FindOneByCalledOnlyOnceWhenFoundRepositoryDecorator.php @@ -13,7 +13,7 @@ class FindOneByCalledOnlyOnceWhenFoundRepositoryDecorator extends EntityReposito private array $calls = []; public function __construct( - private ObjectRepository $decorated, + private readonly ObjectRepository $decorated, ) { } diff --git a/src/batch-doctrine-persistence/tests/Dummy/SimpleManagerRegistry.php b/src/batch-doctrine-persistence/tests/Dummy/SimpleManagerRegistry.php index 400382ad..9e567842 100644 --- a/src/batch-doctrine-persistence/tests/Dummy/SimpleManagerRegistry.php +++ b/src/batch-doctrine-persistence/tests/Dummy/SimpleManagerRegistry.php @@ -20,7 +20,7 @@ public function __construct( $managers = []; $defaultConnection = null; $defaultEntityManager = null; - foreach ($this->services as $id => $service) { + foreach (\array_keys($this->services) as $id) { $connections[] = $id; $managers[] = $id; $defaultConnection ??= $id; diff --git a/src/batch-doctrine-persistence/tests/Entity/Auth/Group.php b/src/batch-doctrine-persistence/tests/Entity/Auth/Group.php index c5893d7e..f8104457 100644 --- a/src/batch-doctrine-persistence/tests/Entity/Auth/Group.php +++ b/src/batch-doctrine-persistence/tests/Entity/Auth/Group.php @@ -4,18 +4,19 @@ namespace Yokai\Batch\Tests\Bridge\Doctrine\Persistence\Entity\Auth; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: 'auth_group')] class Group { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] public string $name; public function __construct(string $name) diff --git a/src/batch-doctrine-persistence/tests/Entity/Auth/User.php b/src/batch-doctrine-persistence/tests/Entity/Auth/User.php index 40baaa9f..c6cae763 100644 --- a/src/batch-doctrine-persistence/tests/Entity/Auth/User.php +++ b/src/batch-doctrine-persistence/tests/Entity/Auth/User.php @@ -4,18 +4,19 @@ namespace Yokai\Batch\Tests\Bridge\Doctrine\Persistence\Entity\Auth; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: 'auth_user')] class User { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] public string $name; public function __construct(string $name) diff --git a/src/batch-doctrine-persistence/tests/Entity/Shop/Product.php b/src/batch-doctrine-persistence/tests/Entity/Shop/Product.php index dc2a3dff..3978a691 100644 --- a/src/batch-doctrine-persistence/tests/Entity/Shop/Product.php +++ b/src/batch-doctrine-persistence/tests/Entity/Shop/Product.php @@ -4,18 +4,19 @@ namespace Yokai\Batch\Tests\Bridge\Doctrine\Persistence\Entity\Shop; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: 'shop_product')] class Product { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] public string $name; public function __construct(string $name) diff --git a/src/batch-league-flysystem/composer.json b/src/batch-league-flysystem/composer.json index 27d35f31..7d269ac8 100644 --- a/src/batch-league-flysystem/composer.json +++ b/src/batch-league-flysystem/composer.json @@ -22,7 +22,6 @@ }, "require-dev": { "league/flysystem-memory": "^3.0", - "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5" }, "autoload-dev": { diff --git a/src/batch-league-flysystem/src/Job/CopyFilesJob.php b/src/batch-league-flysystem/src/Job/CopyFilesJob.php index e691f8ce..1a5e19d2 100644 --- a/src/batch-league-flysystem/src/Job/CopyFilesJob.php +++ b/src/batch-league-flysystem/src/Job/CopyFilesJob.php @@ -21,10 +21,10 @@ class CopyFilesJob implements JobInterface { public function __construct( - private JobParameterAccessorInterface $location, - private FilesystemReader $source, - private FilesystemWriter $destination, - private Closure|null $transformLocation = null, + private readonly JobParameterAccessorInterface $location, + private readonly FilesystemReader $source, + private readonly FilesystemWriter $destination, + private readonly Closure|null $transformLocation = null, ) { } diff --git a/src/batch-league-flysystem/src/Job/MoveFilesJob.php b/src/batch-league-flysystem/src/Job/MoveFilesJob.php index d8c4717e..9e297b04 100644 --- a/src/batch-league-flysystem/src/Job/MoveFilesJob.php +++ b/src/batch-league-flysystem/src/Job/MoveFilesJob.php @@ -22,10 +22,10 @@ class MoveFilesJob implements JobInterface { public function __construct( - private JobParameterAccessorInterface $location, - private FilesystemOperator $source, - private FilesystemWriter $destination, - private Closure|null $transformLocation = null, + private readonly JobParameterAccessorInterface $location, + private readonly FilesystemOperator $source, + private readonly FilesystemWriter $destination, + private readonly Closure|null $transformLocation = null, ) { } diff --git a/src/batch-league-flysystem/src/Scheduler/FileFoundScheduler.php b/src/batch-league-flysystem/src/Scheduler/FileFoundScheduler.php index 74daa2c7..45e4466b 100644 --- a/src/batch-league-flysystem/src/Scheduler/FileFoundScheduler.php +++ b/src/batch-league-flysystem/src/Scheduler/FileFoundScheduler.php @@ -16,7 +16,7 @@ /** * Watch for the existence of a location on a filesystem to trigger a job. */ -final class FileFoundScheduler implements SchedulerInterface +final readonly class FileFoundScheduler implements SchedulerInterface { public function __construct( private FilesystemReader $filesystem, diff --git a/src/batch-league-flysystem/tests/Dummy/CannotCheckMemoryAdapter.php b/src/batch-league-flysystem/tests/Dummy/CannotCheckMemoryAdapter.php index 547a47c8..b48bb6fc 100644 --- a/src/batch-league-flysystem/tests/Dummy/CannotCheckMemoryAdapter.php +++ b/src/batch-league-flysystem/tests/Dummy/CannotCheckMemoryAdapter.php @@ -11,7 +11,7 @@ final class CannotCheckMemoryAdapter extends InMemoryFilesystemAdapter { public function __construct( - private UnableToCheckExistence|FilesystemException $exception, + private readonly UnableToCheckExistence|FilesystemException $exception, ) { parent::__construct(); } diff --git a/src/batch-league-flysystem/tests/Dummy/CannotDeleteMemoryAdapter.php b/src/batch-league-flysystem/tests/Dummy/CannotDeleteMemoryAdapter.php index 8a34527b..5d2f0754 100644 --- a/src/batch-league-flysystem/tests/Dummy/CannotDeleteMemoryAdapter.php +++ b/src/batch-league-flysystem/tests/Dummy/CannotDeleteMemoryAdapter.php @@ -11,7 +11,7 @@ final class CannotDeleteMemoryAdapter extends InMemoryFilesystemAdapter { public function __construct( - private UnableToDeleteFile|FilesystemException $exception, + private readonly UnableToDeleteFile|FilesystemException $exception, ) { parent::__construct(); } diff --git a/src/batch-league-flysystem/tests/Dummy/CannotReadMemoryAdapter.php b/src/batch-league-flysystem/tests/Dummy/CannotReadMemoryAdapter.php index 0d8490bc..d154d08d 100644 --- a/src/batch-league-flysystem/tests/Dummy/CannotReadMemoryAdapter.php +++ b/src/batch-league-flysystem/tests/Dummy/CannotReadMemoryAdapter.php @@ -11,7 +11,7 @@ final class CannotReadMemoryAdapter extends InMemoryFilesystemAdapter { public function __construct( - private UnableToReadFile|FilesystemException $exception, + private readonly UnableToReadFile|FilesystemException $exception, ) { parent::__construct(); } diff --git a/src/batch-league-flysystem/tests/Dummy/CannotWriteMemoryAdapter.php b/src/batch-league-flysystem/tests/Dummy/CannotWriteMemoryAdapter.php index 546ea13a..50d1c8c6 100644 --- a/src/batch-league-flysystem/tests/Dummy/CannotWriteMemoryAdapter.php +++ b/src/batch-league-flysystem/tests/Dummy/CannotWriteMemoryAdapter.php @@ -12,7 +12,7 @@ final class CannotWriteMemoryAdapter extends InMemoryFilesystemAdapter { public function __construct( - private UnableToWriteFile|FilesystemException $exception, + private readonly UnableToWriteFile|FilesystemException $exception, ) { parent::__construct(); } diff --git a/src/batch-openspout/src/Exception/InvalidRowSizeException.php b/src/batch-openspout/src/Exception/InvalidRowSizeException.php index ed952cdd..be06128c 100644 --- a/src/batch-openspout/src/Exception/InvalidRowSizeException.php +++ b/src/batch-openspout/src/Exception/InvalidRowSizeException.php @@ -12,11 +12,11 @@ public function __construct( /** * @var array */ - private array $headers, + private readonly array $headers, /** * @var array */ - private array $row, + private readonly array $row, ) { parent::__construct('Invalid row size'); } diff --git a/src/batch-openspout/src/Reader/FlatFileReader.php b/src/batch-openspout/src/Reader/FlatFileReader.php index 3c9ed671..4a2383e8 100644 --- a/src/batch-openspout/src/Reader/FlatFileReader.php +++ b/src/batch-openspout/src/Reader/FlatFileReader.php @@ -59,10 +59,8 @@ public function read(): iterable $reader->open($path); foreach ($this->rows($reader) as $rowIndex => $row) { - if ($rowIndex === 1) { - if (!$this->headerStrategy->setHeaders($row)) { - continue; - } + if ($rowIndex === 1 && !$this->headerStrategy->setHeaders($row)) { + continue; } try { diff --git a/src/batch-openspout/src/Reader/HeaderStrategy.php b/src/batch-openspout/src/Reader/HeaderStrategy.php index 89224046..73c05952 100644 --- a/src/batch-openspout/src/Reader/HeaderStrategy.php +++ b/src/batch-openspout/src/Reader/HeaderStrategy.php @@ -19,7 +19,7 @@ final class HeaderStrategy private const NONE = 'none'; private function __construct( - private string $mode, + private readonly string $mode, /** * @var list|null */ diff --git a/src/batch-openspout/src/Reader/SheetFilter.php b/src/batch-openspout/src/Reader/SheetFilter.php index 331cb206..ebbc252a 100644 --- a/src/batch-openspout/src/Reader/SheetFilter.php +++ b/src/batch-openspout/src/Reader/SheetFilter.php @@ -13,17 +13,16 @@ * A sheet filter is used by {@see XLSXOptions} & {@see ODSOptions} * so you can tell which sheet is to be read. */ -final class SheetFilter +final readonly class SheetFilter { - private Closure $accept; - - /** - * @param Closure $accept A closure with {@see SheetInterface} as single argument, - * and returning a boolean, telling if the sheet should be read. - */ - public function __construct(Closure $accept) - { - $this->accept = $accept; + public function __construct( + /** + * A closure with {@see SheetInterface} as single argument, + * and returning a boolean, telling if the sheet should be read. + * @var Closure + */ + private Closure $accept, + ) { } /** diff --git a/src/batch-openspout/src/Writer/WriteToSheetItem.php b/src/batch-openspout/src/Writer/WriteToSheetItem.php index 8fbc8a2b..4b9fe074 100644 --- a/src/batch-openspout/src/Writer/WriteToSheetItem.php +++ b/src/batch-openspout/src/Writer/WriteToSheetItem.php @@ -11,7 +11,7 @@ * This model object is used by {@see FlatFileWriter}. * It holds sheet and row to write to file. */ -final class WriteToSheetItem +final readonly class WriteToSheetItem { private function __construct( private string $sheet, diff --git a/src/batch-symfony-console/composer.json b/src/batch-symfony-console/composer.json index a56c0059..2137dbc6 100644 --- a/src/batch-symfony-console/composer.json +++ b/src/batch-symfony-console/composer.json @@ -22,7 +22,6 @@ } }, "require-dev": { - "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5", "symfony/process": "^7.4|^8.0" }, diff --git a/src/batch-symfony-console/src/CommandRunner.php b/src/batch-symfony-console/src/CommandRunner.php index ae4a032f..907d2101 100644 --- a/src/batch-symfony-console/src/CommandRunner.php +++ b/src/batch-symfony-console/src/CommandRunner.php @@ -12,12 +12,12 @@ */ class CommandRunner { - private string $consolePath; - private null|PhpExecutableFinder $phpLocator; + private readonly string $consolePath; + private readonly null|PhpExecutableFinder $phpLocator; public function __construct( string $binDir, - private string $logDir, + private readonly string $logDir, PhpExecutableFinder|null $phpLocator = null, ) { $this->consolePath = \implode(DIRECTORY_SEPARATOR, [$binDir, 'console']); @@ -58,7 +58,7 @@ private function buildCommand(string $commandName, array $arguments): string { return \sprintf( '%s %s %s %s', - $this->phpLocator ? $this->phpLocator->find() : 'php', + $this->phpLocator?->find() ?? 'php', $this->consolePath, $commandName, (string)(new ArrayInput($arguments)), diff --git a/src/batch-symfony-console/src/RunCommandJobLauncher.php b/src/batch-symfony-console/src/RunCommandJobLauncher.php index 180f349b..c07b0213 100644 --- a/src/batch-symfony-console/src/RunCommandJobLauncher.php +++ b/src/batch-symfony-console/src/RunCommandJobLauncher.php @@ -18,7 +18,7 @@ * * php bin/console yokai:batch:run import '{"foo":"bar"}' >> var/log/batch_execute.log 2>&1 & */ -final class RunCommandJobLauncher implements JobLauncherInterface +final readonly class RunCommandJobLauncher implements JobLauncherInterface { public function __construct( private JobExecutionFactory $jobExecutionFactory, diff --git a/src/batch-symfony-console/src/RunJobCommand.php b/src/batch-symfony-console/src/RunJobCommand.php index 9fd5f17f..3cb884ab 100644 --- a/src/batch-symfony-console/src/RunJobCommand.php +++ b/src/batch-symfony-console/src/RunJobCommand.php @@ -28,8 +28,8 @@ final class RunJobCommand extends Command public const EXIT_WARNING_CODE = 2; public function __construct( - private JobExecutionAccessor $jobExecutionAccessor, - private JobExecutor $jobExecutor, + private readonly JobExecutionAccessor $jobExecutionAccessor, + private readonly JobExecutor $jobExecutor, ) { parent::__construct(); } @@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function guessExecutionExitCode(JobExecution $jobExecution): int { if ($jobExecution->getStatus()->is(BatchStatus::COMPLETED)) { - if (\count($jobExecution->getAllWarnings()) === 0) { + if ($jobExecution->getAllWarnings() === []) { return self::EXIT_SUCCESS_CODE; } @@ -77,7 +77,7 @@ private function outputExecution(JobExecution $jobExecution, OutputInterface $ou $jobName = $jobExecution->getJobName(); if ($jobExecution->getStatus()->is(BatchStatus::COMPLETED)) { $warnings = $jobExecution->getAllWarnings(); - if (\count($warnings)) { + if ($warnings !== []) { foreach ($warnings as $warning) { $output->writeln(\sprintf('%s', $warning), $output::VERBOSITY_VERBOSE); } diff --git a/src/batch-symfony-console/src/SetupStorageCommand.php b/src/batch-symfony-console/src/SetupStorageCommand.php index 115fead0..7a1d14e3 100644 --- a/src/batch-symfony-console/src/SetupStorageCommand.php +++ b/src/batch-symfony-console/src/SetupStorageCommand.php @@ -19,7 +19,7 @@ final class SetupStorageCommand extends Command { public function __construct( - private JobExecutionStorageInterface $storage, + private readonly JobExecutionStorageInterface $storage, ) { parent::__construct(); } diff --git a/src/batch-symfony-console/tests/CommandRunnerTest.php b/src/batch-symfony-console/tests/CommandRunnerTest.php index ffbc86f3..5b01e9dd 100644 --- a/src/batch-symfony-console/tests/CommandRunnerTest.php +++ b/src/batch-symfony-console/tests/CommandRunnerTest.php @@ -5,28 +5,22 @@ namespace Yokai\Batch\Tests\Bridge\Symfony\Console; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\Process\PhpExecutableFinder; use Yokai\Batch\Bridge\Symfony\Console\CommandRunner; class CommandRunnerTest extends TestCase { - use ProphecyTrait; - - /** - * @return MockObject|CommandRunner - */ - private function createRunner(): MockObject + private function createRunner(): MockObject&CommandRunner { - /** @var PhpExecutableFinder|ObjectProphecy $phpLocator */ - $phpLocator = $this->prophesize(PhpExecutableFinder::class); - $phpLocator->find()->willReturn('/usr/bin/php'); + /** @var Stub&PhpExecutableFinder $phpLocator */ + $phpLocator = $this->createStub(PhpExecutableFinder::class); + $phpLocator->method('find')->willReturn('/usr/bin/php'); return $this->getMockBuilder(CommandRunner::class) ->onlyMethods(['exec']) - ->setConstructorArgs(['/path/to/bin', '/path/to/logs', $phpLocator->reveal()]) + ->setConstructorArgs(['/path/to/bin', '/path/to/logs', $phpLocator]) ->getMock(); } diff --git a/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php b/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php index b1f47608..1655bc3f 100644 --- a/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php +++ b/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php @@ -5,8 +5,7 @@ namespace Yokai\Batch\Tests\Bridge\Symfony\Console; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; +use PHPUnit\Framework\MockObject\MockObject; use Yokai\Batch\BatchStatus; use Yokai\Batch\Bridge\Symfony\Console\CommandRunner; use Yokai\Batch\Bridge\Symfony\Console\RunCommandJobLauncher; @@ -17,21 +16,20 @@ class RunCommandJobLauncherTest extends TestCase { - use ProphecyTrait; - public function testLaunch(): void { $config = ['_id' => '123456789', 'foo' => ['bar']]; $arguments = ['job' => 'testing', 'configuration' => '{"_id":"123456789","foo":["bar"]}']; - /** @var CommandRunner|ObjectProphecy $commandRunner */ - $commandRunner = $this->prophesize(CommandRunner::class); - $commandRunner->runAsync('yokai:batch:run', 'test.log', $arguments) - ->shouldBeCalledTimes(1); + /** @var MockObject&CommandRunner $commandRunner */ + $commandRunner = $this->createMock(CommandRunner::class); + $commandRunner->expects($this->once()) + ->method('runAsync') + ->with('yokai:batch:run', 'test.log', $arguments); $launcher = new RunCommandJobLauncher( new JobExecutionFactory(new UniqidJobExecutionIdGenerator(), new NullJobExecutionParametersBuilder()), - $commandRunner->reveal(), + $commandRunner, $storage = new InMemoryJobExecutionStorage(), 'test.log', ); diff --git a/src/batch-symfony-console/tests/RunJobCommandTest.php b/src/batch-symfony-console/tests/RunJobCommandTest.php index e20b2687..9efff1bd 100644 --- a/src/batch-symfony-console/tests/RunJobCommandTest.php +++ b/src/batch-symfony-console/tests/RunJobCommandTest.php @@ -7,9 +7,7 @@ use JsonException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; use Yokai\Batch\Bridge\Symfony\Console\RunJobCommand; @@ -27,24 +25,22 @@ class RunJobCommandTest extends TestCase { - use ProphecyTrait; - private const JOBNAME = 'testing'; - private JobInterface|ObjectProphecy $job; + private MockObject&JobInterface $job; private JobExecutionAccessor $accessor; private JobExecutor $executor; protected function setUp(): void { - $this->job = $this->prophesize(JobInterface::class); + $this->job = $this->createMock(JobInterface::class); $this->accessor = new JobExecutionAccessor( new JobExecutionFactory(new UniqidJobExecutionIdGenerator(), new NullJobExecutionParametersBuilder()), new InMemoryJobExecutionStorage(), ); $this->executor = new JobExecutor( - JobRegistry::fromJobArray([self::JOBNAME => $this->job->reveal()]), + JobRegistry::fromJobArray([self::JOBNAME => $this->job]), new InMemoryJobExecutionStorage(), null, ); @@ -54,7 +50,8 @@ public function testRunWithMalformedConfiguration(): void { $this->expectException(JsonException::class); - $this->job->execute(Argument::any())->shouldNotBeCalled(); + $this->job->expects($this->never()) + ->method('execute'); $this->execute('{]'); } @@ -62,17 +59,17 @@ public function testRunWithInvalidConfiguration(): void { $this->expectException(UnexpectedValueException::class); - $this->job->execute(Argument::any())->shouldNotBeCalled(); + $this->job->expects($this->never()) + ->method('execute'); $this->execute('"string"'); } #[DataProvider('verbosity')] public function testRunWithErrors(int $verbosity): void { - $this->job->execute(Argument::any()) - ->will(function (array $args) { - /** @var JobExecution $jobExecution */ - $jobExecution = $args[0]; + $this->job->expects($this->once()) + ->method('execute') + ->willReturnCallback(function (JobExecution $jobExecution): never { $jobExecution->addFailureException(new \RuntimeException('1st exception', 100)); $jobExecution->addFailureException(new \LogicException('2nd exception', 200)); @@ -99,10 +96,9 @@ public function testRunWithErrors(int $verbosity): void #[DataProvider('verbosity')] public function testRunWithWarnings(int $verbosity): void { - $this->job->execute(Argument::any()) - ->will(function (array $args) { - /** @var JobExecution $jobExecution */ - $jobExecution = $args[0]; + $this->job->expects($this->once()) + ->method('execute') + ->willReturnCallback(function (JobExecution $jobExecution) { $jobExecution->addWarning(new Warning('1st warning')); $jobExecution->addWarning(new Warning('2nd warning')); }); @@ -128,9 +124,9 @@ public function testRunWithWarnings(int $verbosity): void #[DataProvider('verbosity')] public function testRunSuccessful(int $verbosity): void { - $this->job->execute(Argument::any()) - ->will(function (array $args) { - }); + $this->job->expects($this->once()) + ->method('execute') + ->willReturnCallback(function () {}); [$code, $display] = $this->execute(null, $verbosity); diff --git a/src/batch-symfony-framework/src/ContainerParameterAccessor.php b/src/batch-symfony-framework/src/ContainerParameterAccessor.php index a9077146..89e57909 100644 --- a/src/batch-symfony-framework/src/ContainerParameterAccessor.php +++ b/src/batch-symfony-framework/src/ContainerParameterAccessor.php @@ -13,7 +13,7 @@ /** * This job parameter accessor implementation returns container parameter value. */ -final class ContainerParameterAccessor implements JobParameterAccessorInterface +final readonly class ContainerParameterAccessor implements JobParameterAccessorInterface { public function __construct( private ContainerInterface $container, diff --git a/src/batch-symfony-framework/src/DependencyInjection/Configuration.php b/src/batch-symfony-framework/src/DependencyInjection/Configuration.php index 771bd4b8..07964abe 100644 --- a/src/batch-symfony-framework/src/DependencyInjection/Configuration.php +++ b/src/batch-symfony-framework/src/DependencyInjection/Configuration.php @@ -171,7 +171,7 @@ private function parameters(): ArrayNodeDefinition return false; } - foreach ($value as $key => $unused) { + foreach (\array_keys($value) as $key) { if (!\is_string($key)) { return false; } @@ -247,7 +247,9 @@ private function ui(): ArrayNodeDefinition throw new \InvalidArgumentException( 'You must either configure "service" or "prefix".', ); - } elseif (isset($value['service']) && isset($value['prefix'])) { + } + + if (isset($value['service']) && isset($value['prefix'])) { throw new \InvalidArgumentException( 'You cannot configure "service" and "prefix" at the same time.', ); diff --git a/src/batch-symfony-framework/src/UserInterface/Controller/JobController.php b/src/batch-symfony-framework/src/UserInterface/Controller/JobController.php index acbf6c81..6de762d8 100644 --- a/src/batch-symfony-framework/src/UserInterface/Controller/JobController.php +++ b/src/batch-symfony-framework/src/UserInterface/Controller/JobController.php @@ -25,7 +25,7 @@ /** * Controller handling HTTP layer of user interface. */ -final class JobController +final readonly class JobController { private const LIMIT = 20; diff --git a/src/batch-symfony-framework/src/UserInterface/Form/JobFilter.php b/src/batch-symfony-framework/src/UserInterface/Form/JobFilter.php index 70f5f03f..ca1610ab 100644 --- a/src/batch-symfony-framework/src/UserInterface/Form/JobFilter.php +++ b/src/batch-symfony-framework/src/UserInterface/Form/JobFilter.php @@ -12,23 +12,15 @@ */ final class JobFilter { - /** - * @var array - */ - public array $jobs = []; - - /** - * @var array - */ - public array $statuses = []; - - /** - * @param array $jobs - * @param array $statuses - */ - public function __construct(array $jobs = [], array $statuses = []) - { - $this->jobs = $jobs; - $this->statuses = $statuses; + public function __construct( + /** + * @var array + */ + public array $jobs = [], + /** + * @var array + */ + public array $statuses = [], + ) { } } diff --git a/src/batch-symfony-framework/src/UserInterface/Form/JobFilterType.php b/src/batch-symfony-framework/src/UserInterface/Form/JobFilterType.php index 2b8daccb..d3f9ea62 100644 --- a/src/batch-symfony-framework/src/UserInterface/Form/JobFilterType.php +++ b/src/batch-symfony-framework/src/UserInterface/Form/JobFilterType.php @@ -28,7 +28,7 @@ public function __construct( /** * @var array */ - private array $jobs, + private readonly array $jobs, ) { } diff --git a/src/batch-symfony-framework/src/UserInterface/JobSecurity.php b/src/batch-symfony-framework/src/UserInterface/JobSecurity.php index 14fc6b45..e323b7fd 100644 --- a/src/batch-symfony-framework/src/UserInterface/JobSecurity.php +++ b/src/batch-symfony-framework/src/UserInterface/JobSecurity.php @@ -12,7 +12,7 @@ * User interface security facade. * The security may not be installed, or configured, but this class will still be called. */ -final class JobSecurity +final readonly class JobSecurity { public function __construct( private null|AuthorizationCheckerInterface $authorizationChecker, diff --git a/src/batch-symfony-framework/src/UserInterface/Templating/ConfigurableTemplating.php b/src/batch-symfony-framework/src/UserInterface/Templating/ConfigurableTemplating.php index aa165420..fd941a5c 100644 --- a/src/batch-symfony-framework/src/UserInterface/Templating/ConfigurableTemplating.php +++ b/src/batch-symfony-framework/src/UserInterface/Templating/ConfigurableTemplating.php @@ -7,7 +7,7 @@ /** * Apply a prefix to every template names. */ -final class ConfigurableTemplating implements TemplatingInterface +final readonly class ConfigurableTemplating implements TemplatingInterface { /** * @param array $context diff --git a/src/batch-symfony-framework/src/UserInterface/Templating/SonataAdminTemplating.php b/src/batch-symfony-framework/src/UserInterface/Templating/SonataAdminTemplating.php index 8ccb78e5..14b668cd 100644 --- a/src/batch-symfony-framework/src/UserInterface/Templating/SonataAdminTemplating.php +++ b/src/batch-symfony-framework/src/UserInterface/Templating/SonataAdminTemplating.php @@ -9,7 +9,7 @@ /** * Add all variables required by a SonataAdminBundle template to the context. */ -final class SonataAdminTemplating implements TemplatingInterface +final readonly class SonataAdminTemplating implements TemplatingInterface { public function __construct( private TemplateRegistryInterface $templates, diff --git a/src/batch-symfony-framework/src/UserInterface/TwigExtension.php b/src/batch-symfony-framework/src/UserInterface/TwigExtension.php index 6702cf1d..3422448b 100644 --- a/src/batch-symfony-framework/src/UserInterface/TwigExtension.php +++ b/src/batch-symfony-framework/src/UserInterface/TwigExtension.php @@ -15,7 +15,7 @@ final class TwigExtension extends AbstractExtension { public function __construct( - private JobSecurity $security, + private readonly JobSecurity $security, ) { } diff --git a/src/batch-symfony-framework/tests/DependencyInjection/YokaiBatchExtensionTest.php b/src/batch-symfony-framework/tests/DependencyInjection/YokaiBatchExtensionTest.php index 83ac3ec0..1c0d06c0 100644 --- a/src/batch-symfony-framework/tests/DependencyInjection/YokaiBatchExtensionTest.php +++ b/src/batch-symfony-framework/tests/DependencyInjection/YokaiBatchExtensionTest.php @@ -89,7 +89,7 @@ public function testLauncher( self::assertSame($class, $container->getDefinition($id)->getClass()); } - if ($assert) { + if ($assert !== null) { $assert($container); } } @@ -310,7 +310,7 @@ function (Definition $templating) { ConfigurableTemplating::class, ), function (Definition $templating, string $id) { - self::assertSame($id, 'app.yokai_batch_templating'); + self::assertSame('app.yokai_batch_templating', $id); }, [ 'list' => 'IS_AUTHENTICATED', @@ -374,7 +374,7 @@ public function testParameters(array $config, array|null $global, array|null $pe self::assertNotNull($defaultService); self::assertSame(ChainJobExecutionParametersBuilder::class, $defaultService->getClass()); $defaultServiceBuilders = $defaultService->getArgument(0); - self::assertTrue($defaultServiceBuilders instanceof TaggedIteratorArgument); + self::assertInstanceOf(TaggedIteratorArgument::class, $defaultServiceBuilders); /** @var TaggedIteratorArgument $defaultServiceBuilders */ self::assertSame('yokai_batch.job_execution_parameters_builder', $defaultServiceBuilders->getTag()); } diff --git a/src/batch-symfony-framework/tests/UserInterface/Controller/JobControllerTest.php b/src/batch-symfony-framework/tests/UserInterface/Controller/JobControllerTest.php index 72185c73..96e19839 100644 --- a/src/batch-symfony-framework/tests/UserInterface/Controller/JobControllerTest.php +++ b/src/batch-symfony-framework/tests/UserInterface/Controller/JobControllerTest.php @@ -410,7 +410,7 @@ private static function securities(): \Generator yield [ new JobSecurity( new class($granted) implements AuthorizationCheckerInterface { - public function __construct(private bool $granted) + public function __construct(private readonly bool $granted) { } diff --git a/src/batch-symfony-framework/tests/UserInterface/JobSecurityTest.php b/src/batch-symfony-framework/tests/UserInterface/JobSecurityTest.php index bac22bb4..73e28b54 100644 --- a/src/batch-symfony-framework/tests/UserInterface/JobSecurityTest.php +++ b/src/batch-symfony-framework/tests/UserInterface/JobSecurityTest.php @@ -35,7 +35,7 @@ public function testWithNoSecurity(): void public function testWithSecurity(array $attributes, array $expected): void { $authorizationChecker = new class($attributes) implements AuthorizationCheckerInterface { - public function __construct(private array $attributes) + public function __construct(private readonly array $attributes) { } diff --git a/src/batch-symfony-framework/tests/UserInterface/TwigExtensionTest.php b/src/batch-symfony-framework/tests/UserInterface/TwigExtensionTest.php index 0fff73f7..5fe72888 100644 --- a/src/batch-symfony-framework/tests/UserInterface/TwigExtensionTest.php +++ b/src/batch-symfony-framework/tests/UserInterface/TwigExtensionTest.php @@ -40,7 +40,7 @@ public static function security(): \Generator yield [ new JobSecurity( new class($granted) implements AuthorizationCheckerInterface { - public function __construct(private bool $granted) + public function __construct(private readonly bool $granted) { } diff --git a/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php b/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php index 9088b31a..997e0ecc 100644 --- a/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php +++ b/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php @@ -17,7 +17,7 @@ /** * This {@see JobLauncherInterface} will execute job via a symfony message dispatch. */ -final class DispatchMessageJobLauncher implements JobLauncherInterface +final readonly class DispatchMessageJobLauncher implements JobLauncherInterface { public function __construct( private JobExecutionFactory $jobExecutionFactory, diff --git a/src/batch-symfony-messenger/src/LaunchJobMessage.php b/src/batch-symfony-messenger/src/LaunchJobMessage.php index 6efe22a9..44e20abd 100644 --- a/src/batch-symfony-messenger/src/LaunchJobMessage.php +++ b/src/batch-symfony-messenger/src/LaunchJobMessage.php @@ -7,7 +7,7 @@ /** * A message, dispatched in symfony/messenger's bus, that is requiring to launch a job. */ -final class LaunchJobMessage +final readonly class LaunchJobMessage { public function __construct( private string $jobName, diff --git a/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php b/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php index 187e1e5a..897a113f 100644 --- a/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php +++ b/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php @@ -10,7 +10,7 @@ /** * Answer to {@see LaunchJobMessage} and launch requested job. */ -final class LaunchJobMessageHandler +final readonly class LaunchJobMessageHandler { public function __construct( private JobExecutionAccessor $jobExecutionAccessor, diff --git a/src/batch-symfony-messenger/tests/Dummy/FailingMessageBus.php b/src/batch-symfony-messenger/tests/Dummy/FailingMessageBus.php index 3b45d15a..d7f735aa 100644 --- a/src/batch-symfony-messenger/tests/Dummy/FailingMessageBus.php +++ b/src/batch-symfony-messenger/tests/Dummy/FailingMessageBus.php @@ -8,7 +8,7 @@ use Symfony\Component\Messenger\Exception\ExceptionInterface; use Symfony\Component\Messenger\MessageBusInterface; -final class FailingMessageBus implements MessageBusInterface +final readonly class FailingMessageBus implements MessageBusInterface { public function __construct( private ExceptionInterface $exception, diff --git a/src/batch-symfony-messenger/tests/LaunchJobMessageHandlerTest.php b/src/batch-symfony-messenger/tests/LaunchJobMessageHandlerTest.php index bc401f97..0bcb9a16 100644 --- a/src/batch-symfony-messenger/tests/LaunchJobMessageHandlerTest.php +++ b/src/batch-symfony-messenger/tests/LaunchJobMessageHandlerTest.php @@ -5,7 +5,6 @@ namespace Yokai\Batch\Tests\Bridge\Symfony\Messenger; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Yokai\Batch\Bridge\Symfony\Messenger\LaunchJobMessage; use Yokai\Batch\Bridge\Symfony\Messenger\LaunchJobMessageHandler; use Yokai\Batch\Factory\JobExecutionFactory; @@ -20,8 +19,6 @@ final class LaunchJobMessageHandlerTest extends TestCase { - use ProphecyTrait; - public function testInvoke(): void { $job = new class implements JobInterface { diff --git a/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php b/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php index 88bf14ef..86fa1923 100644 --- a/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php +++ b/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php @@ -13,7 +13,7 @@ /** * This {@see ItemProcessorInterface} uses Symfony's serializer to denormalize items. */ -final class DenormalizeItemProcessor implements ItemProcessorInterface +final readonly class DenormalizeItemProcessor implements ItemProcessorInterface { public function __construct( private DenormalizerInterface $denormalizer, diff --git a/src/batch-symfony-serializer/src/NormalizeItemProcessor.php b/src/batch-symfony-serializer/src/NormalizeItemProcessor.php index 41f76851..0e354411 100644 --- a/src/batch-symfony-serializer/src/NormalizeItemProcessor.php +++ b/src/batch-symfony-serializer/src/NormalizeItemProcessor.php @@ -13,7 +13,7 @@ /** * This {@see ItemProcessorInterface} uses Symfony's serializer to normalize items. */ -final class NormalizeItemProcessor implements ItemProcessorInterface +final readonly class NormalizeItemProcessor implements ItemProcessorInterface { public function __construct( private NormalizerInterface $normalizer, diff --git a/src/batch-symfony-serializer/tests/Dummy/DummyNormalizer.php b/src/batch-symfony-serializer/tests/Dummy/DummyNormalizer.php index 7720af9c..bb1b7cb6 100644 --- a/src/batch-symfony-serializer/tests/Dummy/DummyNormalizer.php +++ b/src/batch-symfony-serializer/tests/Dummy/DummyNormalizer.php @@ -7,7 +7,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -final class DummyNormalizer implements NormalizerInterface, DenormalizerInterface +final readonly class DummyNormalizer implements NormalizerInterface, DenormalizerInterface { public function __construct( private bool $supports, diff --git a/src/batch-symfony-serializer/tests/Dummy/FailingNormalizer.php b/src/batch-symfony-serializer/tests/Dummy/FailingNormalizer.php index c245921f..a1b93e44 100644 --- a/src/batch-symfony-serializer/tests/Dummy/FailingNormalizer.php +++ b/src/batch-symfony-serializer/tests/Dummy/FailingNormalizer.php @@ -8,7 +8,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -final class FailingNormalizer implements NormalizerInterface, DenormalizerInterface +final readonly class FailingNormalizer implements NormalizerInterface, DenormalizerInterface { public function __construct( private ExceptionInterface $exception, diff --git a/src/batch-symfony-uid/src/Factory/RandomBasedUuidJobExecutionIdGenerator.php b/src/batch-symfony-uid/src/Factory/RandomBasedUuidJobExecutionIdGenerator.php index 5e0d2e8e..af9af2bf 100644 --- a/src/batch-symfony-uid/src/Factory/RandomBasedUuidJobExecutionIdGenerator.php +++ b/src/batch-symfony-uid/src/Factory/RandomBasedUuidJobExecutionIdGenerator.php @@ -11,7 +11,7 @@ * This {@see JobExecutionIdGeneratorInterface} will use * Symfony's {@see UuidFactory} to generate random based UUIDs. */ -final class RandomBasedUuidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface +final readonly class RandomBasedUuidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface { public function __construct( private UuidFactory $uuidFactory, diff --git a/src/batch-symfony-uid/src/Factory/TimeBasedUuidJobExecutionIdGenerator.php b/src/batch-symfony-uid/src/Factory/TimeBasedUuidJobExecutionIdGenerator.php index 4c0e8c5b..2c0e6613 100644 --- a/src/batch-symfony-uid/src/Factory/TimeBasedUuidJobExecutionIdGenerator.php +++ b/src/batch-symfony-uid/src/Factory/TimeBasedUuidJobExecutionIdGenerator.php @@ -11,7 +11,7 @@ * This {@see JobExecutionIdGeneratorInterface} will use * Symfony's {@see UuidFactory} to generate time based UUIDs. */ -final class TimeBasedUuidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface +final readonly class TimeBasedUuidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface { public function __construct( private UuidFactory $uuidFactory, diff --git a/src/batch-symfony-uid/src/Factory/UlidJobExecutionIdGenerator.php b/src/batch-symfony-uid/src/Factory/UlidJobExecutionIdGenerator.php index e014115b..479c80c0 100644 --- a/src/batch-symfony-uid/src/Factory/UlidJobExecutionIdGenerator.php +++ b/src/batch-symfony-uid/src/Factory/UlidJobExecutionIdGenerator.php @@ -11,7 +11,7 @@ * This {@see JobExecutionIdGeneratorInterface} will use * Symfony's {@see UlidFactory} to ULIDs. */ -final class UlidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface +final readonly class UlidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface { public function __construct( private UlidFactory $ulidFactory, diff --git a/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php b/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php index 0dbccc00..00471ce5 100644 --- a/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php +++ b/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php @@ -14,7 +14,7 @@ * This {@see ItemProcessorInterface} uses Symfony's validator to validate items. * When an item is not valid, it throw a {@see SkipItemException} with a {@see SkipItemOnViolations} cause. */ -final class SkipInvalidItemProcessor implements ItemProcessorInterface +final readonly class SkipInvalidItemProcessor implements ItemProcessorInterface { public function __construct( private ValidatorInterface $validator, diff --git a/src/batch-symfony-validator/src/SkipItemOnViolations.php b/src/batch-symfony-validator/src/SkipItemOnViolations.php index 99e7f0a6..c82d3229 100644 --- a/src/batch-symfony-validator/src/SkipItemOnViolations.php +++ b/src/batch-symfony-validator/src/SkipItemOnViolations.php @@ -14,7 +14,7 @@ /** * Skip item when validation fails and leave a warning with violations to the {@see JobExecution}. */ -final class SkipItemOnViolations implements SkipItemCauseInterface +final readonly class SkipItemOnViolations implements SkipItemCauseInterface { public function __construct( /** diff --git a/src/batch-symfony-validator/tests/Fixtures/StringableClass.php b/src/batch-symfony-validator/tests/Fixtures/StringableClass.php index 8843ce7c..8b71c352 100644 --- a/src/batch-symfony-validator/tests/Fixtures/StringableClass.php +++ b/src/batch-symfony-validator/tests/Fixtures/StringableClass.php @@ -4,7 +4,7 @@ namespace Yokai\Batch\Tests\Bridge\Symfony\Validator\Fixtures; -final class StringableClass +final class StringableClass implements \Stringable { public function __toString(): string { diff --git a/src/batch-symfony-validator/tests/SkipItemOnViolationsTest.php b/src/batch-symfony-validator/tests/SkipItemOnViolationsTest.php index 95545c70..ebf4362c 100644 --- a/src/batch-symfony-validator/tests/SkipItemOnViolationsTest.php +++ b/src/batch-symfony-validator/tests/SkipItemOnViolationsTest.php @@ -35,12 +35,9 @@ public function test(array $violations, array $expectedViolations): void public static function provider(): \Generator { - $violation = function (string $message, $value) { - return new ConstraintViolation($message, $message, [], null, 'property.path', $value); - }; - $message = function (string $message, string $value) { - return "property.path: $message (invalid value: $value)"; - }; + $violation = fn(string $message, $value) + => new ConstraintViolation($message, $message, [], null, 'property.path', $value); + $message = fn(string $message, string $value) => "property.path: $message (invalid value: $value)"; yield 'empty string' => [ [$violation('This value should not be blank.', '')], diff --git a/src/batch/composer.json b/src/batch/composer.json index d4cb5ebf..c176f5ec 100644 --- a/src/batch/composer.json +++ b/src/batch/composer.json @@ -22,7 +22,6 @@ } }, "require-dev": { - "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5", "symfony/filesystem": "^7.4|^8.0" }, diff --git a/src/batch/src/BatchStatus.php b/src/batch/src/BatchStatus.php index a0145a18..dac2c55a 100644 --- a/src/batch/src/BatchStatus.php +++ b/src/batch/src/BatchStatus.php @@ -10,7 +10,7 @@ /** * The status of a job execution. */ -final class BatchStatus implements \Stringable +final readonly class BatchStatus implements \Stringable { /** * The job execution has not started yet. diff --git a/src/batch/src/Event/ExceptionEvent.php b/src/batch/src/Event/ExceptionEvent.php index ec11ba08..f1c5ef4b 100644 --- a/src/batch/src/Event/ExceptionEvent.php +++ b/src/batch/src/Event/ExceptionEvent.php @@ -22,7 +22,7 @@ final class ExceptionEvent extends JobEvent public function __construct( JobExecution $execution, - private Throwable $exception, + private readonly Throwable $exception, ) { parent::__construct($execution); } diff --git a/src/batch/src/Event/JobEvent.php b/src/batch/src/Event/JobEvent.php index 1797e6a0..107d0850 100644 --- a/src/batch/src/Event/JobEvent.php +++ b/src/batch/src/Event/JobEvent.php @@ -12,7 +12,7 @@ class JobEvent { public function __construct( - private JobExecution $execution, + private readonly JobExecution $execution, ) { } diff --git a/src/batch/src/Factory/JobExecutionFactory.php b/src/batch/src/Factory/JobExecutionFactory.php index 14573b29..39be96d1 100644 --- a/src/batch/src/Factory/JobExecutionFactory.php +++ b/src/batch/src/Factory/JobExecutionFactory.php @@ -10,7 +10,7 @@ /** * Create a {@see JobExecution} from scalar members. */ -final class JobExecutionFactory +final readonly class JobExecutionFactory { public function __construct( private JobExecutionIdGeneratorInterface $idGenerator, @@ -25,7 +25,7 @@ public function __construct( */ public function create(string $name, array $configuration = []): JobExecution { - $configuration = $configuration + $this->parametersBuilder->build($name); + $configuration += $this->parametersBuilder->build($name); /** @var string $id */ $id = $configuration['_id'] ??= $this->idGenerator->generate(); diff --git a/src/batch/src/Factory/JobExecutionParametersBuilder/ChainJobExecutionParametersBuilder.php b/src/batch/src/Factory/JobExecutionParametersBuilder/ChainJobExecutionParametersBuilder.php index 8c222dbe..92b981c5 100644 --- a/src/batch/src/Factory/JobExecutionParametersBuilder/ChainJobExecutionParametersBuilder.php +++ b/src/batch/src/Factory/JobExecutionParametersBuilder/ChainJobExecutionParametersBuilder.php @@ -11,13 +11,13 @@ * implementations, calls each and merge the results into a single array. * The later the {@see JobExecutionParametersBuilderInterface} is in the list, the more chance it's values will be kept. */ -final class ChainJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface +final readonly class ChainJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface { public function __construct( /** * @var iterable */ - private readonly iterable $builders, + private iterable $builders, ) { } diff --git a/src/batch/src/Factory/JobExecutionParametersBuilder/PerJobJobExecutionParametersBuilder.php b/src/batch/src/Factory/JobExecutionParametersBuilder/PerJobJobExecutionParametersBuilder.php index 4e7b265a..b8499ac9 100644 --- a/src/batch/src/Factory/JobExecutionParametersBuilder/PerJobJobExecutionParametersBuilder.php +++ b/src/batch/src/Factory/JobExecutionParametersBuilder/PerJobJobExecutionParametersBuilder.php @@ -9,13 +9,13 @@ /** * This {@see JobExecutionParametersBuilderInterface} has different default values per job provided at construction. */ -final class PerJobJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface +final readonly class PerJobJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface { public function __construct( /** * @var array> */ - private readonly array $perJobParameters, + private array $perJobParameters, ) { } diff --git a/src/batch/src/Factory/JobExecutionParametersBuilder/StaticJobExecutionParametersBuilder.php b/src/batch/src/Factory/JobExecutionParametersBuilder/StaticJobExecutionParametersBuilder.php index 472910ac..42402064 100644 --- a/src/batch/src/Factory/JobExecutionParametersBuilder/StaticJobExecutionParametersBuilder.php +++ b/src/batch/src/Factory/JobExecutionParametersBuilder/StaticJobExecutionParametersBuilder.php @@ -9,13 +9,13 @@ /** * This {@see JobExecutionParametersBuilderInterface} has same default values for all jobs provided at construction. */ -final class StaticJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface +final readonly class StaticJobExecutionParametersBuilder implements JobExecutionParametersBuilderInterface { public function __construct( /** * @var array */ - private readonly array $parameters, + private array $parameters, ) { } diff --git a/src/batch/src/Failure.php b/src/batch/src/Failure.php index fa450e41..91935311 100644 --- a/src/batch/src/Failure.php +++ b/src/batch/src/Failure.php @@ -10,7 +10,7 @@ * This class represent an exception that occurred during a {@see JobExecution}. * Failure can be added to the execution via {@see JobExecution::addFailureException}. */ -final class Failure implements \Stringable +final readonly class Failure implements \Stringable { public function __construct( /** @@ -88,11 +88,11 @@ public function getTrace(): string|null private static function buildTrace(Throwable $exception, bool $deep = false): string { - $trace = ($deep ? 'Caused by: ' : '') . \get_class($exception) . ': ' . $exception->getMessage() . + $trace = ($deep ? 'Caused by: ' : '') . $exception::class . ': ' . $exception->getMessage() . ' (at ' . $exception->getFile() . '(' . $exception->getLine() . '))' . PHP_EOL . \str_replace("\n", \PHP_EOL, $exception->getTraceAsString()); - if ($exception->getPrevious()) { + if ($exception->getPrevious() !== null) { $trace .= \PHP_EOL . self::buildTrace($exception->getPrevious(), true); } diff --git a/src/batch/src/Finder/CallbackFinder.php b/src/batch/src/Finder/CallbackFinder.php index 7a6899fc..ff267fc3 100644 --- a/src/batch/src/Finder/CallbackFinder.php +++ b/src/batch/src/Finder/CallbackFinder.php @@ -11,7 +11,7 @@ * @psalm-template T of object * @template-implements FinderInterface */ -class CallbackFinder implements FinderInterface +readonly class CallbackFinder implements FinderInterface { public function __construct( /** diff --git a/src/batch/src/Finder/ClassMapFinder.php b/src/batch/src/Finder/ClassMapFinder.php index 8e441e4c..677c55a6 100644 --- a/src/batch/src/Finder/ClassMapFinder.php +++ b/src/batch/src/Finder/ClassMapFinder.php @@ -11,7 +11,7 @@ * @psalm-template T of object * @template-extends CallbackFinder */ -class ClassMapFinder extends CallbackFinder +readonly class ClassMapFinder extends CallbackFinder { /** * @param array $classMap @@ -21,7 +21,7 @@ public function __construct(array $classMap, object $default) { $strategies = []; foreach ($classMap as $class => $component) { - $strategies[] = [fn($item) => \is_object($item) && $item instanceof $class, $component]; + $strategies[] = [fn($item) => $item instanceof $class, $component]; } parent::__construct($strategies, $default); } diff --git a/src/batch/src/Job/AbstractDecoratedJob.php b/src/batch/src/Job/AbstractDecoratedJob.php index 38432cb5..b7021a9a 100644 --- a/src/batch/src/Job/AbstractDecoratedJob.php +++ b/src/batch/src/Job/AbstractDecoratedJob.php @@ -14,7 +14,7 @@ abstract class AbstractDecoratedJob implements JobInterface { public function __construct( - private JobInterface $job, + private readonly JobInterface $job, ) { } diff --git a/src/batch/src/Job/Item/Exception/SkipItemException.php b/src/batch/src/Job/Item/Exception/SkipItemException.php index efa462a7..7a7c1025 100644 --- a/src/batch/src/Job/Item/Exception/SkipItemException.php +++ b/src/batch/src/Job/Item/Exception/SkipItemException.php @@ -17,12 +17,12 @@ final class SkipItemException extends RuntimeException { public function __construct( - private mixed $item, - private SkipItemCauseInterface|null $cause, + private readonly mixed $item, + private readonly SkipItemCauseInterface|null $cause, /** * @var array */ - private array $context = [], + private readonly array $context = [], ) { parent::__construct(); } diff --git a/src/batch/src/Job/Item/Exception/SkipItemOnError.php b/src/batch/src/Job/Item/Exception/SkipItemOnError.php index 6dca9802..e162742c 100644 --- a/src/batch/src/Job/Item/Exception/SkipItemOnError.php +++ b/src/batch/src/Job/Item/Exception/SkipItemOnError.php @@ -11,7 +11,7 @@ /** * Skip item when an exception occurs and leave a warning with exception to the {@see JobExecution}. */ -final class SkipItemOnError implements SkipItemCauseInterface +final readonly class SkipItemOnError implements SkipItemCauseInterface { public function __construct( private Throwable $error, diff --git a/src/batch/src/Job/Item/Exception/SkipItemWithWarning.php b/src/batch/src/Job/Item/Exception/SkipItemWithWarning.php index 5f4e2826..0514f01d 100644 --- a/src/batch/src/Job/Item/Exception/SkipItemWithWarning.php +++ b/src/batch/src/Job/Item/Exception/SkipItemWithWarning.php @@ -10,7 +10,7 @@ /** * Skip item and leave an arbitrary warning to the {@see JobExecution}. */ -final class SkipItemWithWarning implements SkipItemCauseInterface +final readonly class SkipItemWithWarning implements SkipItemCauseInterface { public function __construct( private string $message, diff --git a/src/batch/src/Job/Item/ItemJob.php b/src/batch/src/Job/Item/ItemJob.php index 70991131..09bae84b 100644 --- a/src/batch/src/Job/Item/ItemJob.php +++ b/src/batch/src/Job/Item/ItemJob.php @@ -64,7 +64,7 @@ final public function execute(JobExecution $jobExecution): void ); $cause = $exception->getCause(); - if ($cause) { + if ($cause !== null) { $cause->report($jobExecution, $readIndex, $exception->getItem()); } diff --git a/src/batch/src/Job/Item/Processor/ArrayMapProcessor.php b/src/batch/src/Job/Item/Processor/ArrayMapProcessor.php index 2e90e2a2..6959bd4a 100644 --- a/src/batch/src/Job/Item/Processor/ArrayMapProcessor.php +++ b/src/batch/src/Job/Item/Processor/ArrayMapProcessor.php @@ -11,13 +11,11 @@ /** * This {@see ItemProcessorInterface} calls {@see array_map} on each item. */ -final class ArrayMapProcessor implements ItemProcessorInterface +final readonly class ArrayMapProcessor implements ItemProcessorInterface { - private Closure $callback; - - public function __construct(Closure $callback) - { - $this->callback = $callback; + public function __construct( + private Closure $callback, + ) { } /** diff --git a/src/batch/src/Job/Item/Processor/ChainProcessor.php b/src/batch/src/Job/Item/Processor/ChainProcessor.php index 02aaee72..93486647 100644 --- a/src/batch/src/Job/Item/Processor/ChainProcessor.php +++ b/src/batch/src/Job/Item/Processor/ChainProcessor.php @@ -18,7 +18,7 @@ public function __construct( /** * @var iterable $processors */ - private iterable $processors, + private readonly iterable $processors, ) { } diff --git a/src/batch/src/Job/Item/Processor/FilterUniqueProcessor.php b/src/batch/src/Job/Item/Processor/FilterUniqueProcessor.php index b8a0c889..dd2dc024 100644 --- a/src/batch/src/Job/Item/Processor/FilterUniqueProcessor.php +++ b/src/batch/src/Job/Item/Processor/FilterUniqueProcessor.php @@ -17,16 +17,14 @@ */ final class FilterUniqueProcessor implements ItemProcessorInterface { - private Closure $extractUnique; - /** * @var array */ private array $encountered = []; - public function __construct(Closure $extractUnique) - { - $this->extractUnique = $extractUnique; + public function __construct( + private readonly Closure $extractUnique, + ) { } /** diff --git a/src/batch/src/Job/Item/Reader/AddMetadataReader.php b/src/batch/src/Job/Item/Reader/AddMetadataReader.php index cc27f753..9ce4a0ce 100644 --- a/src/batch/src/Job/Item/Reader/AddMetadataReader.php +++ b/src/batch/src/Job/Item/Reader/AddMetadataReader.php @@ -17,11 +17,11 @@ final class AddMetadataReader extends AbstractElementDecorator implements ItemReaderInterface { public function __construct( - private ItemReaderInterface $reader, + private readonly ItemReaderInterface $reader, /** * @var array */ - private array $metadata, + private readonly array $metadata, ) { } diff --git a/src/batch/src/Job/Item/Reader/CallbackReader.php b/src/batch/src/Job/Item/Reader/CallbackReader.php index d1aba2b3..f95a8951 100644 --- a/src/batch/src/Job/Item/Reader/CallbackReader.php +++ b/src/batch/src/Job/Item/Reader/CallbackReader.php @@ -11,13 +11,13 @@ * * Provided {@see Closure} must accept no argument and must return an iterable of read items. */ -final class CallbackReader implements ItemReaderInterface +final readonly class CallbackReader implements ItemReaderInterface { public function __construct( /** * @var \Closure(): iterable */ - private readonly \Closure $callback, + private \Closure $callback, ) { } diff --git a/src/batch/src/Job/Item/Reader/Filesystem/FixedColumnSizeFileReader.php b/src/batch/src/Job/Item/Reader/Filesystem/FixedColumnSizeFileReader.php index 2894025e..a19f6690 100644 --- a/src/batch/src/Job/Item/Reader/Filesystem/FixedColumnSizeFileReader.php +++ b/src/batch/src/Job/Item/Reader/Filesystem/FixedColumnSizeFileReader.php @@ -80,9 +80,7 @@ public function read(): Generator } } - if (\is_array($headers)) { - $row = \array_combine($headers, $row); - } + $row = \array_combine($headers, $row); yield $row; } diff --git a/src/batch/src/Job/Item/Reader/IndexWithReader.php b/src/batch/src/Job/Item/Reader/IndexWithReader.php index 4226de97..199ada49 100644 --- a/src/batch/src/Job/Item/Reader/IndexWithReader.php +++ b/src/batch/src/Job/Item/Reader/IndexWithReader.php @@ -18,8 +18,8 @@ final class IndexWithReader extends AbstractElementDecorator implements ItemReaderInterface { public function __construct( - private ItemReaderInterface $reader, - private Closure $extractItemIndex, + private readonly ItemReaderInterface $reader, + private readonly Closure $extractItemIndex, ) { } diff --git a/src/batch/src/Job/Item/Reader/SequenceReader.php b/src/batch/src/Job/Item/Reader/SequenceReader.php index 67229ffe..379d2f5a 100644 --- a/src/batch/src/Job/Item/Reader/SequenceReader.php +++ b/src/batch/src/Job/Item/Reader/SequenceReader.php @@ -16,7 +16,7 @@ public function __construct( /** * @var iterable $readers */ - private iterable $readers, + private readonly iterable $readers, ) { } diff --git a/src/batch/src/Job/Item/Reader/StaticIterableReader.php b/src/batch/src/Job/Item/Reader/StaticIterableReader.php index ba438eea..5b894cd2 100644 --- a/src/batch/src/Job/Item/Reader/StaticIterableReader.php +++ b/src/batch/src/Job/Item/Reader/StaticIterableReader.php @@ -9,7 +9,7 @@ /** * This {@see ItemReaderInterface} reads from items provided as constructor argument. */ -final class StaticIterableReader implements ItemReaderInterface +final readonly class StaticIterableReader implements ItemReaderInterface { public function __construct( /** diff --git a/src/batch/src/Job/Item/Writer/ChainWriter.php b/src/batch/src/Job/Item/Writer/ChainWriter.php index ed94a1df..e5ef2c89 100644 --- a/src/batch/src/Job/Item/Writer/ChainWriter.php +++ b/src/batch/src/Job/Item/Writer/ChainWriter.php @@ -16,7 +16,7 @@ public function __construct( /** * @var iterable $writers */ - private iterable $writers, + private readonly iterable $writers, ) { } diff --git a/src/batch/src/Job/Item/Writer/DispatchEventsWriter.php b/src/batch/src/Job/Item/Writer/DispatchEventsWriter.php index 45c627f6..0994ebdd 100644 --- a/src/batch/src/Job/Item/Writer/DispatchEventsWriter.php +++ b/src/batch/src/Job/Item/Writer/DispatchEventsWriter.php @@ -17,8 +17,8 @@ final class DispatchEventsWriter extends AbstractElementDecorator implements ItemWriterInterface { public function __construct( - private EventDispatcherInterface $eventDispatcher, - private ItemWriterInterface $writer, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly ItemWriterInterface $writer, ) { } diff --git a/src/batch/src/Job/Item/Writer/TransformingWriter.php b/src/batch/src/Job/Item/Writer/TransformingWriter.php index a11758f3..f9e5320e 100644 --- a/src/batch/src/Job/Item/Writer/TransformingWriter.php +++ b/src/batch/src/Job/Item/Writer/TransformingWriter.php @@ -52,7 +52,7 @@ public function write(iterable $items): void ); $cause = $exception->getCause(); - if ($cause) { + if ($cause !== null) { $cause->report($this->jobExecution, $index, $exception->getItem()); } @@ -60,7 +60,7 @@ public function write(iterable $items): void } } - if (\count($transformedItems) > 0) { + if ($transformedItems !== []) { $this->writer->write($transformedItems); } } diff --git a/src/batch/src/Job/JobExecutionAccessor.php b/src/batch/src/Job/JobExecutionAccessor.php index 4e5737e3..47601134 100644 --- a/src/batch/src/Job/JobExecutionAccessor.php +++ b/src/batch/src/Job/JobExecutionAccessor.php @@ -14,7 +14,7 @@ * It will either find it from {@see JobExecutionStorageInterface}. * Or create and store new one using {@see JobExecutionFactory}. */ -final class JobExecutionAccessor +final readonly class JobExecutionAccessor { public function __construct( private JobExecutionFactory $jobExecutionFactory, diff --git a/src/batch/src/Job/JobExecutor.php b/src/batch/src/Job/JobExecutor.php index 33639e28..25c2a821 100644 --- a/src/batch/src/Job/JobExecutor.php +++ b/src/batch/src/Job/JobExecutor.php @@ -24,7 +24,7 @@ * - lifecycle events during execution * - JobExecution storage before and after execution */ -final class JobExecutor +final readonly class JobExecutor { public function __construct( private JobRegistry $jobRegistry, @@ -81,7 +81,7 @@ public function execute(JobExecution $jobExecution): void } $summary = $jobExecution->getSummary()->all(); - if (\count($summary) > 0) { + if ($summary !== []) { $logger->debug('Job produced summary', \array_merge(['job' => $name], $summary)); } diff --git a/src/batch/src/Job/JobWithChildJobs.php b/src/batch/src/Job/JobWithChildJobs.php index 289698b6..aac0c8fa 100644 --- a/src/batch/src/Job/JobWithChildJobs.php +++ b/src/batch/src/Job/JobWithChildJobs.php @@ -19,12 +19,12 @@ class JobWithChildJobs implements JobInterface { public function __construct( - private JobExecutionStorageInterface $executionStorage, - private JobExecutor $jobExecutor, + private readonly JobExecutionStorageInterface $executionStorage, + private readonly JobExecutor $jobExecutor, /** * @var iterable */ - private iterable $childJobs, + private readonly iterable $childJobs, ) { } diff --git a/src/batch/src/Job/Parameters/ChainParameterAccessor.php b/src/batch/src/Job/Parameters/ChainParameterAccessor.php index e53f2550..4a60aa0d 100644 --- a/src/batch/src/Job/Parameters/ChainParameterAccessor.php +++ b/src/batch/src/Job/Parameters/ChainParameterAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation iterates over a list of other accessors * and return the value from the first successful of the list. */ -final class ChainParameterAccessor implements JobParameterAccessorInterface +final readonly class ChainParameterAccessor implements JobParameterAccessorInterface { public function __construct( /** diff --git a/src/batch/src/Job/Parameters/ClosestJobExecutionAccessor.php b/src/batch/src/Job/Parameters/ClosestJobExecutionAccessor.php index f31739d1..75368676 100644 --- a/src/batch/src/Job/Parameters/ClosestJobExecutionAccessor.php +++ b/src/batch/src/Job/Parameters/ClosestJobExecutionAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation decorates an other implementation * but tries every job execution from the one provided to the root, returning the first that matches. */ -final class ClosestJobExecutionAccessor implements JobParameterAccessorInterface +final readonly class ClosestJobExecutionAccessor implements JobParameterAccessorInterface { public function __construct( private JobParameterAccessorInterface $accessor, diff --git a/src/batch/src/Job/Parameters/DefaultParameterAccessor.php b/src/batch/src/Job/Parameters/DefaultParameterAccessor.php index 7abf2037..b426c27b 100644 --- a/src/batch/src/Job/Parameters/DefaultParameterAccessor.php +++ b/src/batch/src/Job/Parameters/DefaultParameterAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation return a static value * if the decorated job parameter accessor fails accessing parameter. */ -final class DefaultParameterAccessor implements JobParameterAccessorInterface +final readonly class DefaultParameterAccessor implements JobParameterAccessorInterface { public function __construct( private JobParameterAccessorInterface $accessor, diff --git a/src/batch/src/Job/Parameters/JobExecutionParameterAccessor.php b/src/batch/src/Job/Parameters/JobExecutionParameterAccessor.php index ccbc11da..d2bfa407 100644 --- a/src/batch/src/Job/Parameters/JobExecutionParameterAccessor.php +++ b/src/batch/src/Job/Parameters/JobExecutionParameterAccessor.php @@ -12,7 +12,7 @@ * This job parameter accessor implementation access parameters * through the contextual JobExecution parameter. */ -final class JobExecutionParameterAccessor implements JobParameterAccessorInterface +final readonly class JobExecutionParameterAccessor implements JobParameterAccessorInterface { public function __construct( private string $name, diff --git a/src/batch/src/Job/Parameters/JobExecutionSummaryAccessor.php b/src/batch/src/Job/Parameters/JobExecutionSummaryAccessor.php index 63bf7e40..099c0183 100644 --- a/src/batch/src/Job/Parameters/JobExecutionSummaryAccessor.php +++ b/src/batch/src/Job/Parameters/JobExecutionSummaryAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation access summary * through the contextual JobExecution parameter. */ -final class JobExecutionSummaryAccessor implements JobParameterAccessorInterface +final readonly class JobExecutionSummaryAccessor implements JobParameterAccessorInterface { public function __construct( private string $name, diff --git a/src/batch/src/Job/Parameters/ParentJobExecutionAccessor.php b/src/batch/src/Job/Parameters/ParentJobExecutionAccessor.php index edcd1cda..3755e501 100644 --- a/src/batch/src/Job/Parameters/ParentJobExecutionAccessor.php +++ b/src/batch/src/Job/Parameters/ParentJobExecutionAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation decorates an other implementation * but tries with parent job execution of the one provided. */ -final class ParentJobExecutionAccessor implements JobParameterAccessorInterface +final readonly class ParentJobExecutionAccessor implements JobParameterAccessorInterface { public function __construct( private JobParameterAccessorInterface $accessor, diff --git a/src/batch/src/Job/Parameters/ReplaceWithVariablesParameterAccessor.php b/src/batch/src/Job/Parameters/ReplaceWithVariablesParameterAccessor.php index 15d023c8..a476e841 100644 --- a/src/batch/src/Job/Parameters/ReplaceWithVariablesParameterAccessor.php +++ b/src/batch/src/Job/Parameters/ReplaceWithVariablesParameterAccessor.php @@ -14,11 +14,11 @@ class ReplaceWithVariablesParameterAccessor implements JobParameterAccessorInterface { public function __construct( - private JobParameterAccessorInterface $accessor, + private readonly JobParameterAccessorInterface $accessor, /** * @var array */ - private array $variables = [], + private readonly array $variables = [], ) { } diff --git a/src/batch/src/Job/Parameters/RootJobExecutionAccessor.php b/src/batch/src/Job/Parameters/RootJobExecutionAccessor.php index c54e8586..37546b86 100644 --- a/src/batch/src/Job/Parameters/RootJobExecutionAccessor.php +++ b/src/batch/src/Job/Parameters/RootJobExecutionAccessor.php @@ -10,7 +10,7 @@ * This job parameter accessor implementation decorates an other implementation * but passes root job execution instead of provided execution. */ -final class RootJobExecutionAccessor implements JobParameterAccessorInterface +final readonly class RootJobExecutionAccessor implements JobParameterAccessorInterface { public function __construct( private JobParameterAccessorInterface $accessor, diff --git a/src/batch/src/Job/Parameters/SiblingJobExecutionAccessor.php b/src/batch/src/Job/Parameters/SiblingJobExecutionAccessor.php index 9da4fc28..2694b695 100644 --- a/src/batch/src/Job/Parameters/SiblingJobExecutionAccessor.php +++ b/src/batch/src/Job/Parameters/SiblingJobExecutionAccessor.php @@ -11,7 +11,7 @@ * This job parameter accessor implementation decorates an other implementation * but passes a named sibling job execution instead of provided execution. */ -final class SiblingJobExecutionAccessor implements JobParameterAccessorInterface +final readonly class SiblingJobExecutionAccessor implements JobParameterAccessorInterface { public function __construct( private JobParameterAccessorInterface $accessor, diff --git a/src/batch/src/Job/Parameters/StaticValueParameterAccessor.php b/src/batch/src/Job/Parameters/StaticValueParameterAccessor.php index 9b2984cd..203fc900 100644 --- a/src/batch/src/Job/Parameters/StaticValueParameterAccessor.php +++ b/src/batch/src/Job/Parameters/StaticValueParameterAccessor.php @@ -9,7 +9,7 @@ /** * This job parameter accessor implementation returns a static value from constructor. */ -final class StaticValueParameterAccessor implements JobParameterAccessorInterface +final readonly class StaticValueParameterAccessor implements JobParameterAccessorInterface { public function __construct( private mixed $value, diff --git a/src/batch/src/JobExecution.php b/src/batch/src/JobExecution.php index ecd88481..86113aa4 100644 --- a/src/batch/src/JobExecution.php +++ b/src/batch/src/JobExecution.php @@ -26,12 +26,12 @@ final class JobExecution /** * The job execution id (generated by {@see JobExecutionIdGeneratorInterface}). */ - private string $id; + private readonly string $id; /** * The job name. */ - private string $jobName; + private readonly string $jobName; /** * The status in which the job execution is. @@ -65,19 +65,19 @@ final class JobExecution /** * The summary information collected during execution. */ - private Summary $summary; + private readonly Summary $summary; /** * The parameters provided before job execution. */ - private JobParameters $parameters; + private readonly JobParameters $parameters; /** * The parent execution. * Most of the time null, filled whenever using a {@see JobWithChildJobs}. * Inverse side of {@see JobExecution::$childExecutions} */ - private JobExecution|null $parentExecution; + private readonly JobExecution|null $parentExecution; /** * The children executions. @@ -91,13 +91,13 @@ final class JobExecution * Logs collected during job execution. * Filled via {@see JobExecution::$logger}. */ - private JobExecutionLogs $logs; + private readonly JobExecutionLogs $logs; /** * Private job execution logger. * Will fill {@see JobExecution::$logs}. */ - private LoggerInterface $logger; + private readonly LoggerInterface $logger; private function __construct( JobExecution|null $parentExecution, @@ -114,8 +114,8 @@ private function __construct( $this->status = $status ?: new BatchStatus(BatchStatus::PENDING); $this->parameters = $parameters ?: new JobParameters(); $this->summary = $summary ?: new Summary(); - $this->logs = $parentExecution ? $parentExecution->getLogs() : ($logs ?: new JobExecutionLogs()); - $this->logger = $parentExecution ? $parentExecution->getLogger() : new JobExecutionLogger($this->logs); + $this->logs = $parentExecution !== null ? $parentExecution->getLogs() : ($logs ?: new JobExecutionLogs()); + $this->logger = $parentExecution !== null ? $parentExecution->getLogger() : new JobExecutionLogger($this->logs); } /** @@ -319,10 +319,7 @@ public function addFailureException(Throwable $exception, array $parameters = [] */ public function getAllFailures(): array { - $all = []; - foreach ($this->failures as $failure) { - $all[] = $failure; - } + $all = $this->failures; foreach ($this->getChildExecutions() as $child) { foreach ($child->getAllFailures() as $failure) { $all[] = $failure; @@ -358,10 +355,7 @@ public function addWarning(Warning $warning, bool $log = true): void */ public function getAllWarnings(): array { - $all = []; - foreach ($this->warnings as $warning) { - $all[] = $warning; - } + $all = $this->warnings; foreach ($this->getChildExecutions() as $child) { foreach ($child->getAllWarnings() as $warning) { $all[] = $warning; diff --git a/src/batch/src/JobExecutionLogger.php b/src/batch/src/JobExecutionLogger.php index e2a48001..acbcfddb 100644 --- a/src/batch/src/JobExecutionLogger.php +++ b/src/batch/src/JobExecutionLogger.php @@ -35,7 +35,7 @@ public function __construct( /** * Logs container : where logs are actually written. */ - private JobExecutionLogs $logs, + private readonly JobExecutionLogs $logs, ) { } diff --git a/src/batch/src/Launcher/RoutingJobLauncher.php b/src/batch/src/Launcher/RoutingJobLauncher.php index 63739dd2..5974c41b 100644 --- a/src/batch/src/Launcher/RoutingJobLauncher.php +++ b/src/batch/src/Launcher/RoutingJobLauncher.php @@ -20,8 +20,8 @@ final class RoutingJobLauncher implements JobLauncherInterface { public function __construct( - private ContainerInterface $launchers, - private JobLauncherInterface $default, + private readonly ContainerInterface $launchers, + private readonly JobLauncherInterface $default, /** * @var array */ diff --git a/src/batch/src/Launcher/SimpleJobLauncher.php b/src/batch/src/Launcher/SimpleJobLauncher.php index fc4019c7..d8eb7d89 100644 --- a/src/batch/src/Launcher/SimpleJobLauncher.php +++ b/src/batch/src/Launcher/SimpleJobLauncher.php @@ -15,8 +15,8 @@ class SimpleJobLauncher implements JobLauncherInterface { public function __construct( - private JobExecutionAccessor $jobExecutionAccessor, - private JobExecutor $jobExecutor, + private readonly JobExecutionAccessor $jobExecutionAccessor, + private readonly JobExecutor $jobExecutor, ) { } diff --git a/src/batch/src/Registry/JobRegistry.php b/src/batch/src/Registry/JobRegistry.php index 19743190..e9846c0f 100644 --- a/src/batch/src/Registry/JobRegistry.php +++ b/src/batch/src/Registry/JobRegistry.php @@ -15,7 +15,7 @@ * It can be registered as a global registry, * but it can be also created with a subset of jobs if required. */ -final class JobRegistry +final readonly class JobRegistry { public function __construct( private ContainerInterface $jobs, diff --git a/src/batch/src/Storage/FilesystemJobExecutionStorage.php b/src/batch/src/Storage/FilesystemJobExecutionStorage.php index d14c6a63..4537ef20 100644 --- a/src/batch/src/Storage/FilesystemJobExecutionStorage.php +++ b/src/batch/src/Storage/FilesystemJobExecutionStorage.php @@ -27,7 +27,7 @@ * │ └── 61519f8e0f4a7.json * │ └── 61519f8e46fb3.json */ -final class FilesystemJobExecutionStorage implements QueryableJobExecutionStorageInterface +final readonly class FilesystemJobExecutionStorage implements QueryableJobExecutionStorageInterface { public function __construct( private JobExecutionSerializerInterface $serializer, @@ -99,17 +99,17 @@ public function query(Query $query): iterable } $names = $query->jobs(); - if (\count($names) > 0 && !\in_array($execution->getJobName(), $names, true)) { + if ($names !== [] && !\in_array($execution->getJobName(), $names, true)) { continue; } $ids = $query->ids(); - if (\count($ids) > 0 && !\in_array($execution->getId(), $ids, true)) { + if ($ids !== [] && !\in_array($execution->getId(), $ids, true)) { continue; } $statuses = $query->statuses(); - if (\count($statuses) > 0 && !$execution->getStatus()->isOneOf($statuses)) { + if ($statuses !== [] && !$execution->getStatus()->isOneOf($statuses)) { continue; } @@ -137,18 +137,10 @@ public function query(Query $query): iterable } $order = match ($query->sort()) { - Query::SORT_BY_START_ASC => static function (JobExecution $left, JobExecution $right): int { - return $left->getStartTime() <=> $right->getStartTime(); - }, - Query::SORT_BY_START_DESC => static function (JobExecution $left, JobExecution $right): int { - return $right->getStartTime() <=> $left->getStartTime(); - }, - Query::SORT_BY_END_ASC => static function (JobExecution $left, JobExecution $right): int { - return $left->getEndTime() <=> $right->getEndTime(); - }, - Query::SORT_BY_END_DESC => static function (JobExecution $left, JobExecution $right): int { - return $right->getEndTime() <=> $left->getEndTime(); - }, + Query::SORT_BY_START_ASC => static fn(JobExecution $left, JobExecution $right): int => $left->getStartTime() <=> $right->getStartTime(), + Query::SORT_BY_START_DESC => static fn(JobExecution $left, JobExecution $right): int => $right->getStartTime() <=> $left->getStartTime(), + Query::SORT_BY_END_ASC => static fn(JobExecution $left, JobExecution $right): int => $left->getEndTime() <=> $right->getEndTime(), + Query::SORT_BY_END_DESC => static fn(JobExecution $left, JobExecution $right): int => $right->getEndTime() <=> $left->getEndTime(), default => null, }; diff --git a/src/batch/src/Storage/Query.php b/src/batch/src/Storage/Query.php index a14dfd4d..f51d4b0f 100644 --- a/src/batch/src/Storage/Query.php +++ b/src/batch/src/Storage/Query.php @@ -10,7 +10,7 @@ * Query {@see JobExecution} list. * Passed as only argument of {@see QueryableJobExecutionStorageInterface::query} method. */ -final class Query +final readonly class Query { public const SORT_BY_START_ASC = 'start_asc'; public const SORT_BY_START_DESC = 'start_desc'; diff --git a/src/batch/src/Storage/TimeFilter.php b/src/batch/src/Storage/TimeFilter.php index 2b79de10..4c9b3034 100644 --- a/src/batch/src/Storage/TimeFilter.php +++ b/src/batch/src/Storage/TimeFilter.php @@ -10,7 +10,7 @@ /** * DTO with optional time boundaries. */ -final class TimeFilter +final readonly class TimeFilter { public function __construct( private DateTimeInterface|null $from, diff --git a/src/batch/src/Test/Finder/DummyFinder.php b/src/batch/src/Test/Finder/DummyFinder.php index cd5953ec..50c239e9 100644 --- a/src/batch/src/Test/Finder/DummyFinder.php +++ b/src/batch/src/Test/Finder/DummyFinder.php @@ -12,7 +12,7 @@ * @psalm-template T of object * @template-implements FinderInterface */ -final class DummyFinder implements FinderInterface +final readonly class DummyFinder implements FinderInterface { public function __construct( /** diff --git a/src/batch/src/Test/Job/Item/Processor/TestDebugProcessor.php b/src/batch/src/Test/Job/Item/Processor/TestDebugProcessor.php index 41667b9d..cf21b427 100644 --- a/src/batch/src/Test/Job/Item/Processor/TestDebugProcessor.php +++ b/src/batch/src/Test/Job/Item/Processor/TestDebugProcessor.php @@ -14,7 +14,7 @@ */ final class TestDebugProcessor extends TestDebugComponent implements ItemProcessorInterface { - private ItemProcessorInterface $decorated; + private readonly ItemProcessorInterface $decorated; private bool $processed = false; public function __construct(ItemProcessorInterface $decorated) diff --git a/src/batch/src/Test/Job/Item/Reader/TestDebugReader.php b/src/batch/src/Test/Job/Item/Reader/TestDebugReader.php index ee3c6dc3..0c3d9a61 100644 --- a/src/batch/src/Test/Job/Item/Reader/TestDebugReader.php +++ b/src/batch/src/Test/Job/Item/Reader/TestDebugReader.php @@ -14,7 +14,7 @@ */ final class TestDebugReader extends TestDebugComponent implements ItemReaderInterface { - private ItemReaderInterface $decorated; + private readonly ItemReaderInterface $decorated; private bool $read = false; public function __construct(ItemReaderInterface $decorated) diff --git a/src/batch/src/Test/Job/Item/Writer/TestDebugWriter.php b/src/batch/src/Test/Job/Item/Writer/TestDebugWriter.php index b359d195..1fe91fed 100644 --- a/src/batch/src/Test/Job/Item/Writer/TestDebugWriter.php +++ b/src/batch/src/Test/Job/Item/Writer/TestDebugWriter.php @@ -14,7 +14,7 @@ */ final class TestDebugWriter extends TestDebugComponent implements ItemWriterInterface { - private ItemWriterInterface $decorated; + private readonly ItemWriterInterface $decorated; private bool $written = false; public function __construct(ItemWriterInterface $decorated) diff --git a/src/batch/src/Test/Launcher/BufferingJobLauncher.php b/src/batch/src/Test/Launcher/BufferingJobLauncher.php index 4606e0ed..71da2205 100644 --- a/src/batch/src/Test/Launcher/BufferingJobLauncher.php +++ b/src/batch/src/Test/Launcher/BufferingJobLauncher.php @@ -22,7 +22,7 @@ final class BufferingJobLauncher implements JobLauncherInterface private array $executions = []; public function __construct( - private JobExecutionIdGeneratorInterface $idGenerator, + private readonly JobExecutionIdGeneratorInterface $idGenerator, ) { } diff --git a/src/batch/src/Trigger/Scheduler/CallbackScheduler.php b/src/batch/src/Trigger/Scheduler/CallbackScheduler.php index fdb8ded1..6d4e8cbe 100644 --- a/src/batch/src/Trigger/Scheduler/CallbackScheduler.php +++ b/src/batch/src/Trigger/Scheduler/CallbackScheduler.php @@ -25,14 +25,13 @@ class CallbackScheduler implements SchedulerInterface /** * @var list, 3: string|null}> */ - private array $config; + private array $config = []; /** * @param list|null, 3: string|null}> $config */ public function __construct(array $config) { - $this->config = []; foreach ($config as $entry) { $this->config[] = [ $entry[0], diff --git a/src/batch/src/Trigger/Scheduler/ScheduledJob.php b/src/batch/src/Trigger/Scheduler/ScheduledJob.php index 5de52948..30a4be33 100644 --- a/src/batch/src/Trigger/Scheduler/ScheduledJob.php +++ b/src/batch/src/Trigger/Scheduler/ScheduledJob.php @@ -7,7 +7,7 @@ /** * This model class is used by schedulers to hold information about a job that should be triggered. */ -final class ScheduledJob +final readonly class ScheduledJob { public function __construct( private string $jobName, diff --git a/src/batch/src/Trigger/TriggerScheduledJobsJob.php b/src/batch/src/Trigger/TriggerScheduledJobsJob.php index 209ffbfd..c2fce95b 100644 --- a/src/batch/src/Trigger/TriggerScheduledJobsJob.php +++ b/src/batch/src/Trigger/TriggerScheduledJobsJob.php @@ -15,7 +15,7 @@ * * This job can be launched using a crontab, so the jobs you scheduled will be evaluated at each crontab rotation. */ -final class TriggerScheduledJobsJob implements JobInterface +final readonly class TriggerScheduledJobsJob implements JobInterface { /** * @param iterable $schedulers diff --git a/src/batch/src/Warning.php b/src/batch/src/Warning.php index 434d5635..630b886a 100644 --- a/src/batch/src/Warning.php +++ b/src/batch/src/Warning.php @@ -9,7 +9,7 @@ * It is usually something about sanity/validation. * Warning can be added to the execution via {@see JobExecution::addWarning}. */ -final class Warning implements \Stringable +final readonly class Warning implements \Stringable { public function __construct( /** diff --git a/src/batch/tests/BatchStatusTest.php b/src/batch/tests/BatchStatusTest.php index 9da54e2e..01976946 100644 --- a/src/batch/tests/BatchStatusTest.php +++ b/src/batch/tests/BatchStatusTest.php @@ -11,7 +11,7 @@ class BatchStatusTest extends TestCase { #[DataProvider('statuses')] - public function testStatus(int $value, string $label, bool $unsucessful) + public function testStatus(int $value, string $label, bool $unsucessful): void { $status = new BatchStatus($value); self::assertSame($label, (string)$status); diff --git a/src/batch/tests/Dummy/DebugEventDispatcher.php b/src/batch/tests/Dummy/DebugEventDispatcher.php index 90272a83..e41f09b8 100644 --- a/src/batch/tests/Dummy/DebugEventDispatcher.php +++ b/src/batch/tests/Dummy/DebugEventDispatcher.php @@ -18,10 +18,10 @@ final class DebugEventDispatcher implements EventDispatcherInterface */ private array $listeners = []; - public function dispatch(object $event) + public function dispatch(object $event): void { $this->events[] = $event; - foreach ($this->listeners[\get_class($event)] ?? [] as $listener) { + foreach ($this->listeners[$event::class] ?? [] as $listener) { $listener($event); } } diff --git a/src/batch/tests/Job/Item/Exception/SkipItemOnErrorTest.php b/src/batch/tests/Job/Item/Exception/SkipItemOnErrorTest.php index 4bea1c62..6b12f9ce 100644 --- a/src/batch/tests/Job/Item/Exception/SkipItemOnErrorTest.php +++ b/src/batch/tests/Job/Item/Exception/SkipItemOnErrorTest.php @@ -30,7 +30,7 @@ public function test(Throwable $error): void [ 'itemIndex' => 'itemIndex', 'item' => 'item', - 'class' => \get_class($error), + 'class' => $error::class, 'message' => $error->getMessage(), 'code' => $error->getCode(), 'trace' => $error->getTraceAsString(), diff --git a/src/batch/tests/Job/Item/ItemJobTest.php b/src/batch/tests/Job/Item/ItemJobTest.php index f2213ae3..53756c6a 100644 --- a/src/batch/tests/Job/Item/ItemJobTest.php +++ b/src/batch/tests/Job/Item/ItemJobTest.php @@ -28,7 +28,7 @@ public function testExecute(): void new StaticIterableReader([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), ); $processor = new TestDebugProcessor( - new CallbackProcessor(function ($item) { + new CallbackProcessor(function (null|int $item) { if ($item > 9) { throw SkipItemException::withWarning( $item, diff --git a/src/batch/tests/Job/Item/Processor/ArrayMapProcessorTest.php b/src/batch/tests/Job/Item/Processor/ArrayMapProcessorTest.php index dfa0e7c6..94685737 100644 --- a/src/batch/tests/Job/Item/Processor/ArrayMapProcessorTest.php +++ b/src/batch/tests/Job/Item/Processor/ArrayMapProcessorTest.php @@ -12,7 +12,7 @@ class ArrayMapProcessorTest extends TestCase { public function test(): void { - $processor = new ArrayMapProcessor(fn($string) => \mb_strtoupper($string)); + $processor = new ArrayMapProcessor(fn(string $string) => \mb_strtoupper($string)); self::assertSame( ['firstName' => 'JOHN', 'lastName' => 'DOE'], $processor->process(['firstName' => 'John', 'lastName' => 'Doe']), diff --git a/src/batch/tests/Job/Item/Processor/FilterUniqueProcessorTest.php b/src/batch/tests/Job/Item/Processor/FilterUniqueProcessorTest.php index 81a7bf87..cf46331f 100644 --- a/src/batch/tests/Job/Item/Processor/FilterUniqueProcessorTest.php +++ b/src/batch/tests/Job/Item/Processor/FilterUniqueProcessorTest.php @@ -23,7 +23,7 @@ public function test(callable $factory, array $items, array $expected): void foreach ($items as $item) { try { $actual[] = $processor->process($item); - } catch (SkipItemException $exception) { + } catch (SkipItemException) { //the item have be filtered and not won't be added to $actual } } diff --git a/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php b/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php index 8cd72a11..568a8b55 100644 --- a/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php +++ b/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php @@ -28,11 +28,8 @@ public static function items(): \Iterator $items = [1, 2, 3]; $aggregate = new class($items) implements \IteratorAggregate { - private array $items; - - public function __construct(array $items) + public function __construct(private readonly array $items) { - $this->items = $items; } public function getIterator(): \Generator diff --git a/src/batch/tests/Job/Item/Writer/DispatchEventsWriterTest.php b/src/batch/tests/Job/Item/Writer/DispatchEventsWriterTest.php index 81c289ac..a8d35116 100644 --- a/src/batch/tests/Job/Item/Writer/DispatchEventsWriterTest.php +++ b/src/batch/tests/Job/Item/Writer/DispatchEventsWriterTest.php @@ -21,7 +21,7 @@ public function test(): void $dispatcher = new DebugEventDispatcher(), $decorated = new TestDebugWriter(new NullWriter()), ); - $dispatcher->addListener(PostWriteEvent::class, function () { + $dispatcher->addListener(PostWriteEvent::class, function (): never { throw new \RuntimeException('Test exception'); }); diff --git a/src/batch/tests/Job/Item/Writer/SummaryWriterTest.php b/src/batch/tests/Job/Item/Writer/SummaryWriterTest.php index b2c5ae04..3663e85d 100644 --- a/src/batch/tests/Job/Item/Writer/SummaryWriterTest.php +++ b/src/batch/tests/Job/Item/Writer/SummaryWriterTest.php @@ -16,7 +16,7 @@ public function test(): void $writer = new SummaryWriter(new StaticValueParameterAccessor('target')); $writer->setJobExecution($jobExecution = JobExecution::createRoot('123456', 'testing')); - self::assertSame(null, $jobExecution->getSummary()->get('target')); + self::assertNull($jobExecution->getSummary()->get('target')); $writer->write(['One']); self::assertSame(['One'], $jobExecution->getSummary()->get('target')); $writer->write(['Two', 'Three']); diff --git a/src/batch/tests/Job/Item/Writer/TransformingWriterTest.php b/src/batch/tests/Job/Item/Writer/TransformingWriterTest.php index c69e1705..3f809aa9 100644 --- a/src/batch/tests/Job/Item/Writer/TransformingWriterTest.php +++ b/src/batch/tests/Job/Item/Writer/TransformingWriterTest.php @@ -20,7 +20,7 @@ class TransformingWriterTest extends TestCase public function test(): void { $writer = new TransformingWriter( - $debugProcessor = new TestDebugProcessor(new CallbackProcessor(fn($string) => \strtoupper($string))), + $debugProcessor = new TestDebugProcessor(new CallbackProcessor(fn(string $string) => \strtoupper($string))), $debugWriter = new TestDebugWriter($innerWriter = new InMemoryWriter()), ); diff --git a/src/batch/tests/Job/JobExecutorTest.php b/src/batch/tests/Job/JobExecutorTest.php index 488e9f02..fe9ab684 100644 --- a/src/batch/tests/Job/JobExecutorTest.php +++ b/src/batch/tests/Job/JobExecutorTest.php @@ -6,10 +6,8 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Throwable; use Yokai\Batch\BatchStatus; use Yokai\Batch\Event\ExceptionEvent; @@ -25,18 +23,16 @@ class JobExecutorTest extends TestCase { - use ProphecyTrait; - - private JobInterface|ObjectProphecy $job; + private Stub&JobInterface $job; private DebugEventDispatcher $dispatcher; private JobExecutor $executor; protected function setUp(): void { - $this->job = $this->prophesize(JobInterface::class); + $this->job = $this->createMock(JobInterface::class); $this->dispatcher = new DebugEventDispatcher(); $this->executor = new JobExecutor( - JobRegistry::fromJobArray(['test.job_executor' => $this->job->reveal()]), + JobRegistry::fromJobArray(['test.job_executor' => $this->job]), new InMemoryJobExecutionStorage(), $this->dispatcher, ); @@ -45,11 +41,10 @@ protected function setUp(): void public function testLaunch(): void { $execution = JobExecution::createRoot('123', 'test.job_executor'); - $this->job->execute($execution) - ->shouldBeCalledTimes(1) - ->will(function (array $args): void { - /** @var JobExecution $execution */ - $execution = $args[0]; + $this->job->expects($this->once()) + ->method('execute') + ->with($execution) + ->willReturnCallback(function (JobExecution $execution): void { $execution->getSummary()->set('foo', 'FOO'); $execution->addWarning(new Warning('Test warning on purpose')); }); @@ -74,15 +69,17 @@ public function testLaunch(): void public function testLaunchJobCatchErrors(Throwable $error): void { $execution = JobExecution::createRoot('123', 'test.job_executor'); - $this->job->execute($execution) - ->willThrow($error); + $this->job->expects($this->once()) + ->method('execute') + ->with($execution) + ->willThrowException($error); $this->executor->execute($execution); self::assertNotNull($execution->getStartTime()); self::assertNotNull($execution->getEndTime()); self::assertSame(BatchStatus::FAILED, $execution->getStatus()->getValue()); - self::assertSame(\get_class($error), $execution->getFailures()[0]->getClass()); + self::assertSame($error::class, $execution->getFailures()[0]->getClass()); self::assertSame($error->getMessage(), $execution->getFailures()[0]->getMessage()); $logs = (string)$execution->getLogs(); self::assertStringContainsString('DEBUG: Starting job', $logs); @@ -97,8 +94,10 @@ public function testLaunchJobCatchErrors(Throwable $error): void public function testLaunchErrorWithStatusListener(): void { $execution = JobExecution::createRoot('123', 'test.job_executor'); - $this->job->execute($execution) - ->willThrow($exception = new \RuntimeException()); + $this->job->expects($this->once()) + ->method('execute') + ->with($execution) + ->willThrowException($exception = new \RuntimeException()); $this->dispatcher->addListener( ExceptionEvent::class, @@ -125,8 +124,8 @@ function (ExceptionEvent $event) use ($exception) { public function testLaunchJobNotExecutable(): void { - $this->job->execute(Argument::any()) - ->shouldNotBeCalled(); + $this->job->expects($this->never()) + ->method('execute'); $execution = JobExecution::createRoot('123', 'test.job_executor', new BatchStatus(BatchStatus::COMPLETED)); $this->executor->execute($execution); diff --git a/src/batch/tests/Job/LoggerTest.php b/src/batch/tests/Job/LoggerTest.php index e1708b18..17539ddb 100644 --- a/src/batch/tests/Job/LoggerTest.php +++ b/src/batch/tests/Job/LoggerTest.php @@ -11,7 +11,7 @@ class LoggerTest extends TestCase { - public function testLogError() + public function testLogError(): void { $idGenerator = new UniqidJobExecutionIdGenerator(); $errorToLog = 'test assert logErrorMethod'; diff --git a/src/batch/tests/JobExecutionTest.php b/src/batch/tests/JobExecutionTest.php index 749c6c7f..f3ecc4f5 100644 --- a/src/batch/tests/JobExecutionTest.php +++ b/src/batch/tests/JobExecutionTest.php @@ -55,7 +55,7 @@ public function testConstruct(): void self::assertNull($minimalJobExecution->getEndTime()); } - public function testGetParameter() + public function testGetParameter(): void { $jobExecution = JobExecution::createRoot( '123456789', @@ -66,15 +66,15 @@ public function testGetParameter() ), ); - self::assertSame(null, $jobExecution->getParameter('null')); + self::assertNull($jobExecution->getParameter('null')); self::assertSame('foo', $jobExecution->getParameter('string')); self::assertSame([], $jobExecution->getParameter('array')); - self::assertSame(false, $jobExecution->getParameter('bool')); + self::assertFalse($jobExecution->getParameter('bool')); self::assertSame(0, $jobExecution->getParameter('int')); self::assertSame(0.000, $jobExecution->getParameter('float')); } - public function testGetUndefinedParameter() + public function testGetUndefinedParameter(): void { $this->expectException(UndefinedJobParameterException::class); @@ -132,7 +132,7 @@ public function testChangeStatus(): void self::assertTrue($jobExecution->getStatus()->is(BatchStatus::COMPLETED)); } - public function testManipulatesFailures() + public function testManipulatesFailures(): void { $failureMessage = fn(Failure $failure): string => $failure->getMessage(); $failureToString = fn(Failure $failure): string => (string)$failure; @@ -165,7 +165,7 @@ public function testManipulatesFailures() self::assertStringContainsString('ERROR: Export Job Failure', $logs); } - public function testManipulatesWarnings() + public function testManipulatesWarnings(): void { $warningMessage = fn(Warning $warning): string => $warning->getMessage(); $warningToString = fn(Warning $warning): string => (string)$warning; @@ -198,7 +198,7 @@ public function testManipulatesWarnings() self::assertStringContainsString('WARNING: Export Job Warning {"bar":"BAR"}', $logs); } - public function testComputesDuration() + public function testComputesDuration(): void { $jobExecution = JobExecution::createRoot('123456789', 'export'); $jobExecution->setStartTime(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2019-01-01 10:00:00')); diff --git a/src/batch/tests/JobParametersTest.php b/src/batch/tests/JobParametersTest.php index 24f3cc75..3c6e2d0c 100644 --- a/src/batch/tests/JobParametersTest.php +++ b/src/batch/tests/JobParametersTest.php @@ -31,10 +31,10 @@ public function testGet(): void ['null' => null, 'string' => 'foo', 'array' => [], 'bool' => false, 'int' => 0, 'float' => 0.000], ); - self::assertSame(null, $parameters->get('null')); + self::assertNull($parameters->get('null')); self::assertSame('foo', $parameters->get('string')); self::assertSame([], $parameters->get('array')); - self::assertSame(false, $parameters->get('bool')); + self::assertFalse($parameters->get('bool')); self::assertSame(0, $parameters->get('int')); self::assertSame(0.000, $parameters->get('float')); } diff --git a/src/batch/tests/Launcher/SimpleJobLauncherTest.php b/src/batch/tests/Launcher/SimpleJobLauncherTest.php index 95215a0c..7f42c887 100644 --- a/src/batch/tests/Launcher/SimpleJobLauncherTest.php +++ b/src/batch/tests/Launcher/SimpleJobLauncherTest.php @@ -5,7 +5,6 @@ namespace Yokai\Batch\Tests\Launcher; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Yokai\Batch\BatchStatus; use Yokai\Batch\Factory\JobExecutionFactory; use Yokai\Batch\Factory\JobExecutionParametersBuilder\NullJobExecutionParametersBuilder; @@ -19,11 +18,9 @@ class SimpleJobLauncherTest extends TestCase { - use ProphecyTrait; - public function test(): void { - $job = $this->prophesize(JobInterface::class); + $job = $this->createStub(JobInterface::class); $launcher = new SimpleJobLauncher( new JobExecutionAccessor( @@ -34,7 +31,7 @@ public function test(): void $jobExecutionStorage = new InMemoryJobExecutionStorage(), ), new JobExecutor( - JobRegistry::fromJobArray(['phpunit' => $job->reveal()]), + JobRegistry::fromJobArray(['phpunit' => $job]), $jobExecutionStorage, null, ), diff --git a/src/batch/tests/Logger/BatchLoggerTest.php b/src/batch/tests/Logger/BatchLoggerTest.php index 14743972..d3139025 100644 --- a/src/batch/tests/Logger/BatchLoggerTest.php +++ b/src/batch/tests/Logger/BatchLoggerTest.php @@ -18,8 +18,8 @@ public function testLaunch(): void $dispatcher = new DebugEventDispatcher(); $logger = new BatchLogger(); - $dispatcher->addListener(PreExecuteEvent::class, [$logger, 'onPreExecute']); - $dispatcher->addListener(PostExecuteEvent::class, [$logger, 'onPostExecute']); + $dispatcher->addListener(PreExecuteEvent::class, $logger->onPreExecute(...)); + $dispatcher->addListener(PostExecuteEvent::class, $logger->onPostExecute(...)); $execution = JobExecution::createRoot('123', 'test.job_executor'); diff --git a/src/batch/tests/Registry/JobContainerTest.php b/src/batch/tests/Registry/JobContainerTest.php index eb1e759e..f0e707cc 100644 --- a/src/batch/tests/Registry/JobContainerTest.php +++ b/src/batch/tests/Registry/JobContainerTest.php @@ -5,19 +5,16 @@ namespace Yokai\Batch\Tests\Registry; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\NotFoundExceptionInterface; use Yokai\Batch\Job\JobInterface; use Yokai\Batch\Registry\JobContainer; class JobContainerTest extends TestCase { - use ProphecyTrait; - public function testGet(): void { - $foo = $this->prophesize(JobInterface::class)->reveal(); - $bar = $this->prophesize(JobInterface::class)->reveal(); + $foo = $this->createStub(JobInterface::class); + $bar = $this->createStub(JobInterface::class); $container = new JobContainer(['foo' => $foo, 'bar' => $bar]); self::assertSame($foo, $container->get('foo')); self::assertSame($bar, $container->get('bar')); @@ -27,14 +24,14 @@ public function testGetNotFound(): void { $this->expectExceptionMessage('You have requested a non-existent job "bar".'); $this->expectException(NotFoundExceptionInterface::class); - $foo = $this->prophesize(JobInterface::class)->reveal(); + $foo = $this->createStub(JobInterface::class); $container = new JobContainer(['foo' => $foo]); $container->get('bar'); } public function testHas(): void { - $foo = $this->prophesize(JobInterface::class)->reveal(); + $foo = $this->createStub(JobInterface::class); $container = new JobContainer(['foo' => $foo]); self::assertTrue($container->has('foo')); self::assertFalse($container->has('bar')); diff --git a/src/batch/tests/Registry/JobRegistryTest.php b/src/batch/tests/Registry/JobRegistryTest.php index 5cc5f7f4..91a3f45b 100644 --- a/src/batch/tests/Registry/JobRegistryTest.php +++ b/src/batch/tests/Registry/JobRegistryTest.php @@ -5,26 +5,20 @@ namespace Yokai\Batch\Tests\Registry; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Yokai\Batch\Exception\UndefinedJobException; use Yokai\Batch\Job\JobInterface; use Yokai\Batch\Registry\JobRegistry; class JobRegistryTest extends TestCase { - use ProphecyTrait; - public function testRegistry(): void { - /** @var ObjectProphecy|JobInterface $export */ - $export = $this->prophesize(JobInterface::class); - /** @var ObjectProphecy|JobInterface $import */ - $import = $this->prophesize(JobInterface::class); + $export = $this->createStub(JobInterface::class); + $import = $this->createStub(JobInterface::class); - $registry = JobRegistry::fromJobArray(['export' => $export->reveal(), 'import' => $import->reveal()]); - self::assertSame($export->reveal(), $registry->get('export')); - self::assertSame($import->reveal(), $registry->get('import')); + $registry = JobRegistry::fromJobArray(['export' => $export, 'import' => $import]); + self::assertSame($export, $registry->get('export')); + self::assertSame($import, $registry->get('import')); } public function testGetNotFound(): void diff --git a/src/batch/tests/Storage/FilesystemJobExecutionStorageTest.php b/src/batch/tests/Storage/FilesystemJobExecutionStorageTest.php index 2cf1aada..d0c755dd 100644 --- a/src/batch/tests/Storage/FilesystemJobExecutionStorageTest.php +++ b/src/batch/tests/Storage/FilesystemJobExecutionStorageTest.php @@ -5,9 +5,8 @@ namespace Yokai\Batch\Tests\Storage; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Yokai\Batch\BatchStatus; use Yokai\Batch\Exception\CannotRemoveJobExecutionException; use Yokai\Batch\Exception\CannotStoreJobExecutionException; @@ -22,16 +21,12 @@ class FilesystemJobExecutionStorageTest extends TestCase { - use ProphecyTrait; use JobExecutionStorageTestTrait; private const STORAGE_DIR = ARTIFACT_DIR . '/filesystem-storage'; private const READONLY_STORAGE_DIR = ARTIFACT_DIR . '/filesystem-storage-readonly'; - /** - * @var JobExecutionSerializerInterface|ObjectProphecy - */ - private $serializer; + private Stub&JobExecutionSerializerInterface $serializer; public static function setUpBeforeClass(): void { @@ -44,8 +39,8 @@ public static function setUpBeforeClass(): void protected function setUp(): void { - $this->serializer = $this->prophesize(JobExecutionSerializerInterface::class); - $this->serializer->extension() + $this->serializer = $this->createStub(JobExecutionSerializerInterface::class); + $this->serializer->method('extension') ->willReturn('txt'); } @@ -54,7 +49,7 @@ private function createStorage( JobExecutionSerializerInterface|null $serializer = null, ): FilesystemJobExecutionStorage { return new FilesystemJobExecutionStorage( - $serializer ?? $this->serializer->reveal(), + $serializer ?? $this->serializer, $dir, ); } @@ -63,8 +58,8 @@ public function testStore(): void { $jobExecution = JobExecution::createRoot('123456789', 'export'); - $this->serializer->serialize($jobExecution) - ->shouldBeCalledTimes(1) + $this->serializer->method('serialize') + ->with($jobExecution) ->willReturn('serialized job execution'); $this->createStorage()->store($jobExecution); @@ -72,7 +67,7 @@ public function testStore(): void $file = self::STORAGE_DIR . '/export/123456789.txt'; self::assertFileExists($file); self::assertIsReadable($file); - self::assertEquals('serialized job execution', \file_get_contents($file)); + self::assertSame('serialized job execution', \file_get_contents($file)); } public function testStoreFileNotWritable(): void @@ -80,8 +75,8 @@ public function testStoreFileNotWritable(): void $this->expectException(CannotStoreJobExecutionException::class); $jobExecution = JobExecution::createRoot('123456789', 'export'); - $this->serializer->serialize($jobExecution) - ->shouldBeCalledTimes(1) + $this->serializer->method('serialize') + ->with($jobExecution) ->willReturn('serialized job execution'); $this->createStorage(self::READONLY_STORAGE_DIR)->store($jobExecution); @@ -101,8 +96,8 @@ public function testRetrieve(): void $jobExecution = JobExecution::createRoot('123456789', 'export'); \file_put_contents(self::STORAGE_DIR . '/export/123456789.txt', 'serialized and stored job execution'); - $this->serializer->unserialize('serialized and stored job execution') - ->shouldBeCalledTimes(1) + $this->serializer->method('unserialize') + ->with('serialized and stored job execution') ->willReturn($jobExecution); self::assertSame($jobExecution, $this->createStorage()->retrieve('export', '123456789')); @@ -147,7 +142,7 @@ public function testQueryWithProvider(QueryBuilder $query, array $expectedCouple ); self::assertExecutions($expectedCouples, $storage->query($query->getQuery())); - self::assertEquals(\count($expectedCouples), $storage->count($query->getQuery())); + self::assertCount($storage->count($query->getQuery()), $expectedCouples); } public static function query(): \Generator @@ -307,8 +302,8 @@ public function testRemove(): void { $jobExecution = JobExecution::createRoot('will_be_removed', 'export'); - $this->serializer->serialize($jobExecution) - ->shouldBeCalledTimes(1) + $this->serializer->method('serialize') + ->with($jobExecution) ->willReturn('serialized job execution'); $path = self::STORAGE_DIR . '/export/will_be_removed.txt'; diff --git a/src/batch/tests/SummaryTest.php b/src/batch/tests/SummaryTest.php index 333244de..96e5834e 100644 --- a/src/batch/tests/SummaryTest.php +++ b/src/batch/tests/SummaryTest.php @@ -68,7 +68,7 @@ public function testGet(): void self::assertSame('foo', $summary->get('string')); self::assertSame([], $summary->get('array')); - self::assertSame(true, $summary->get('bool')); + self::assertTrue($summary->get('bool')); self::assertSame(1, $summary->get('int')); self::assertSame(0.999, $summary->get('float')); } diff --git a/src/batch/tests/Test/ArrayContainerTest.php b/src/batch/tests/Test/ArrayContainerTest.php index acbae1ac..67cdec91 100644 --- a/src/batch/tests/Test/ArrayContainerTest.php +++ b/src/batch/tests/Test/ArrayContainerTest.php @@ -30,8 +30,8 @@ public function testHas(): void { $container = new ArrayContainer(['foo' => 'FOO', 'bar' => 'BAR']); - self::assertSame(true, $container->has('foo')); - self::assertSame(true, $container->has('bar')); - self::assertSame(false, $container->has('baz')); + self::assertTrue($container->has('foo')); + self::assertTrue($container->has('bar')); + self::assertFalse($container->has('baz')); } } diff --git a/tests/integration/Entity/Badge.php b/tests/integration/Entity/Badge.php index e6381667..81d9c633 100644 --- a/tests/integration/Entity/Badge.php +++ b/tests/integration/Entity/Badge.php @@ -4,28 +4,20 @@ namespace Yokai\Batch\Sources\Tests\Integration\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Badge { - /** - * @var int - */ - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] - public $id; + public null|int $id = null; - /** - * @var string - */ - #[ORM\Column(type: 'string')] - public $label; + #[ORM\Column(type: Types::STRING)] + public null|string $label = null; - /** - * @var string - */ - #[ORM\Column(type: 'integer')] - public $rank; + #[ORM\Column(type: Types::INTEGER)] + public null|int $rank = null; } diff --git a/tests/integration/Entity/Developer.php b/tests/integration/Entity/Developer.php index dfa387a2..ae310053 100644 --- a/tests/integration/Entity/Developer.php +++ b/tests/integration/Entity/Developer.php @@ -6,42 +6,34 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Developer { - /** - * @var int - */ - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] - public $id; + public null|int $id = null; - /** - * @var string - */ - #[ORM\Column(type: 'string')] - public $firstName; + #[ORM\Column(type: Types::STRING)] + public null|string $firstName = null; - /** - * @var string - */ - #[ORM\Column(type: 'string')] - public $lastName; + #[ORM\Column(type: Types::STRING)] + public null|string $lastName = null; /** - * @var Collection + * @var Collection */ #[ORM\ManyToMany(targetEntity: Badge::class)] - public $badges; + public Collection $badges; /** - * @var Collection + * @var Collection */ #[ORM\ManyToMany(targetEntity: Repository::class)] - public $repositories; + public Collection $repositories; public function __construct() { diff --git a/tests/integration/Entity/Repository.php b/tests/integration/Entity/Repository.php index 027c1328..a489e944 100644 --- a/tests/integration/Entity/Repository.php +++ b/tests/integration/Entity/Repository.php @@ -4,28 +4,20 @@ namespace Yokai\Batch\Sources\Tests\Integration\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Repository { - /** - * @var int - */ - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] - public $id; + public null|int $id = null; - /** - * @var string - */ - #[ORM\Column(type: 'string')] - public $label; + #[ORM\Column(type: Types::STRING)] + public null|string $label = null; - /** - * @var string - */ - #[ORM\Column(type: 'string')] - public $url; + #[ORM\Column(type: Types::STRING)] + public null|string $url = null; } diff --git a/tests/integration/ImportDevelopersXlsxToORMTest.php b/tests/integration/ImportDevelopersXlsxToORMTest.php index e3590eb2..57b0a16d 100644 --- a/tests/integration/ImportDevelopersXlsxToORMTest.php +++ b/tests/integration/ImportDevelopersXlsxToORMTest.php @@ -10,13 +10,12 @@ use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\ManagerRegistry; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; +use PHPUnit\Framework\MockObject\Stub; use Yokai\Batch\Bridge\Doctrine\Persistence\ObjectWriter; use Yokai\Batch\Bridge\OpenSpout\Reader\FlatFileReader; use Yokai\Batch\Bridge\OpenSpout\Reader\HeaderStrategy; use Yokai\Batch\Job\Item\ItemJob; +use Yokai\Batch\Job\Item\Processor\CallbackProcessor; use Yokai\Batch\Job\JobInterface; use Yokai\Batch\Job\JobWithChildJobs; use Yokai\Batch\Job\Parameters\StaticValueParameterAccessor; @@ -25,37 +24,22 @@ use Yokai\Batch\Sources\Tests\Integration\Entity\Developer; use Yokai\Batch\Sources\Tests\Integration\Entity\Repository; use Yokai\Batch\Sources\Tests\Integration\Job\SplitDeveloperXlsxJob; -use Yokai\Batch\Sources\Tests\Integration\Processor\BadgeProcessor; -use Yokai\Batch\Sources\Tests\Integration\Processor\DeveloperProcessor; -use Yokai\Batch\Sources\Tests\Integration\Processor\RepositoryProcessor; use Yokai\Batch\Storage\JobExecutionStorageInterface; class ImportDevelopersXlsxToORMTest extends JobTestCase { - use ProphecyTrait; - private const OUTPUT_BASE_DIR = self::OUTPUT_DIR . '/multi-tab-xlsx-to-objects'; private const OUTPUT_BADGE_FILE = self::OUTPUT_BASE_DIR . '/badge.csv'; private const OUTPUT_REPOSITORY_FILE = self::OUTPUT_BASE_DIR . '/repository.csv'; private const OUTPUT_DEVELOPER_FILE = self::OUTPUT_BASE_DIR . '/developer.csv'; private const INPUT_FILE = __DIR__ . '/fixtures/multi-tab-xlsx-to-objects.xslx'; - private $persisted; - - /** - * @var EntityManager - */ - private $entityManager; + private EntityManager $entityManager; - /** - * @var ManagerRegistry|ObjectProphecy - */ - private $doctrine; + private Stub&ManagerRegistry $doctrine; protected function setUp(): void { - $this->persisted = []; - $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/Entity'], true); if (\PHP_VERSION_ID >= 80400) { $config->enableNativeLazyObjects(true); @@ -69,8 +53,8 @@ protected function setUp(): void (new SchemaTool($this->entityManager)) ->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata()); - $this->doctrine = $this->prophesize(ManagerRegistry::class); - $this->doctrine->getManagerForClass(Argument::any()) + $this->doctrine = $this->createStub(ManagerRegistry::class); + $this->doctrine->method('getManagerForClass') ->willReturn($this->entityManager); } @@ -82,19 +66,17 @@ protected function getJobName(): string protected function createJob(JobExecutionStorageInterface $executionStorage): JobInterface { $entityManager = $this->entityManager; - $objectWriter = new ObjectWriter($this->doctrine->reveal()); + $objectWriter = new ObjectWriter($this->doctrine); $inputFile = self::INPUT_FILE; $outputBadgeFile = self::OUTPUT_BADGE_FILE; $outputRepositoryFile = self::OUTPUT_REPOSITORY_FILE; $outputDeveloperFile = self::OUTPUT_DEVELOPER_FILE; - $csvReader = function (string $file): FlatFileReader { - return new FlatFileReader( - filePath: new StaticValueParameterAccessor($file), - headerStrategy: HeaderStrategy::combine(), - ); - }; + $csvReader = fn(string $file): FlatFileReader => new FlatFileReader( + filePath: new StaticValueParameterAccessor($file), + headerStrategy: HeaderStrategy::combine(), + ); return new JobWithChildJobs( $executionStorage, @@ -111,21 +93,50 @@ protected function createJob(JobExecutionStorageInterface $executionStorage): Jo 'import-badge' => new ItemJob( PHP_INT_MAX, $csvReader(self::OUTPUT_BADGE_FILE), - new BadgeProcessor(), + new CallbackProcessor(function (array $item) { + $badge = new Badge(); + $badge->label = $item['label']; + $badge->rank = (int)$item['rank']; + + return $badge; + }), $objectWriter, $executionStorage, ), 'import-repository' => new ItemJob( PHP_INT_MAX, $csvReader(self::OUTPUT_REPOSITORY_FILE), - new RepositoryProcessor(), + new CallbackProcessor(function (array $item) { + $repository = new Repository(); + $repository->label = $item['label']; + $repository->url = $item['url']; + + return $repository; + }), $objectWriter, $executionStorage, ), 'import-developer' => new ItemJob( 5, $csvReader(self::OUTPUT_DEVELOPER_FILE), - new DeveloperProcessor($entityManager), + new CallbackProcessor(function (array $item) use ($entityManager) { + $badges = $entityManager->getRepository(Badge::class) + ->findBy(['label' => \str_getcsv((string)$item['badges'], '|', '"', '\\')]); + $repositories = $entityManager->getRepository(Repository::class) + ->findBy(['label' => \str_getcsv((string)$item['repositories'], '|', '"', '\\')]); + + $developer = new Developer(); + $developer->firstName = $item['firstName']; + $developer->lastName = $item['lastName']; + foreach ($badges as $badge) { + $developer->badges->add($badge); + } + foreach ($repositories as $repository) { + $developer->repositories->add($repository); + } + + return $developer; + }), $objectWriter, $executionStorage, ), diff --git a/tests/integration/Job/SplitDeveloperXlsxJob.php b/tests/integration/Job/SplitDeveloperXlsxJob.php index 4b0248e8..7ee48b01 100644 --- a/tests/integration/Job/SplitDeveloperXlsxJob.php +++ b/tests/integration/Job/SplitDeveloperXlsxJob.php @@ -12,7 +12,7 @@ use Yokai\Batch\Job\Parameters\StaticValueParameterAccessor; use Yokai\Batch\JobExecution; -final class SplitDeveloperXlsxJob implements JobInterface +final readonly class SplitDeveloperXlsxJob implements JobInterface { public function __construct( private string $inputFile, @@ -41,8 +41,8 @@ public function execute(JobExecution $jobExecution): void $developerData = ['firstName' => $firstName, 'lastName' => $lastName, 'badges' => [], 'repositories' => []]; $developerKey = $firstName . '/' . $lastName; - $badges[$badgeKey] = $badges[$badgeKey] ?? $badgeData; - $developers[$developerKey] = $developers[$developerKey] ?? $developerData; + $badges[$badgeKey] ??= $badgeData; + $developers[$developerKey] ??= $developerData; $developers[$developerKey]['badges'][] = $badgeLabel; } @@ -54,8 +54,8 @@ public function execute(JobExecution $jobExecution): void $developerData = ['firstName' => $firstName, 'lastName' => $lastName, 'badges' => [], 'repositories' => []]; $developerKey = $firstName . '/' . $lastName; - $repositories[$repositoryKey] = $repositories[$repositoryKey] ?? $repositoryData; - $developers[$developerKey] = $developers[$developerKey] ?? $developerData; + $repositories[$repositoryKey] ??= $repositoryData; + $developers[$developerKey] ??= $developerData; $developers[$developerKey]['repositories'][] = $repositoryUrl; } @@ -89,13 +89,7 @@ private function writeToCsv(string $filename, array $data, array $headers): void private function sheetToArray(SheetInterface $sheet): array { return \array_map( - function ($row): array { - if ($row instanceof Row) { - return $row->toArray(); - } - - return $row; - }, + fn(Row $row) => $row->toArray(), \iterator_to_array(new \LimitIterator($sheet->getRowIterator(), 1), false), ); } diff --git a/tests/integration/JobTestCase.php b/tests/integration/JobTestCase.php index bfaaaa60..afccc65e 100644 --- a/tests/integration/JobTestCase.php +++ b/tests/integration/JobTestCase.php @@ -28,7 +28,7 @@ abstract class JobTestCase extends TestCase protected const STORAGE_DIR = self::ARTIFACTS_DIR . '/storage'; protected const OUTPUT_DIR = self::ARTIFACTS_DIR . '/output'; - private static $run = false; + private static bool $run = false; public static function setUpBeforeClass(): void { @@ -88,7 +88,7 @@ protected function assertAgainstExecution( ); } - private function compareExecutions(JobExecution $jobExecution, JobExecution $storedJobExecution) + private function compareExecutions(JobExecution $jobExecution, JobExecution $storedJobExecution): void { self::assertSame($jobExecution->getId(), $storedJobExecution->getId()); self::assertSame($jobExecution->getJobName(), $storedJobExecution->getJobName()); @@ -123,16 +123,16 @@ private static function storages(): \Iterator ); } - private static function compareStatuses(BatchStatus $expected, BatchStatus $actual) + private static function compareStatuses(BatchStatus $expected, BatchStatus $actual): void { self::assertSame($expected->getValue(), $actual->getValue()); } - private static function compareDates(null|\DateTimeInterface $expected, null|\DateTimeInterface $actual) + private static function compareDates(null|\DateTimeInterface $expected, null|\DateTimeInterface $actual): void { self::assertSame( - $expected ? $expected->format(\DateTime::ISO8601) : null, - $actual ? $actual->format(\DateTime::ISO8601) : null, + $expected?->format(\DateTime::ATOM) ?? null, + $actual?->format(\DateTime::ATOM) ?? null, ); } @@ -140,7 +140,7 @@ private static function compareDates(null|\DateTimeInterface $expected, null|\Da * @param Failure[] $expected * @param Failure[] $actual */ - private static function compareFailures(array $expected, array $actual) + private static function compareFailures(array $expected, array $actual): void { self::assertCount(\count($expected), $actual); @@ -159,7 +159,7 @@ private static function compareFailures(array $expected, array $actual) * @param Warning[] $expected * @param Warning[] $actual */ - private static function compareWarnings(array $expected, array $actual) + private static function compareWarnings(array $expected, array $actual): void { self::assertCount(\count($expected), $actual); diff --git a/tests/integration/JobWithDummyItemChildrenTest.php b/tests/integration/JobWithDummyItemChildrenTest.php index b635000f..93deb4ce 100644 --- a/tests/integration/JobWithDummyItemChildrenTest.php +++ b/tests/integration/JobWithDummyItemChildrenTest.php @@ -23,14 +23,8 @@ protected function createJob(JobExecutionStorageInterface $executionStorage): Jo $output = self::OUTPUT_FILE; $fileLineWriter = new class($output) implements ItemWriterInterface { - /** - * @var string - */ - private $file; - - public function __construct(string $file) + public function __construct(private readonly string $file) { - $this->file = $file; } public function write(iterable $items): void @@ -101,6 +95,6 @@ protected function assertAgainstExecution( OUT; self::assertFileExists($output); - self::assertEquals($expected, \file_get_contents($output)); + self::assertSame($expected, \file_get_contents($output)); } } diff --git a/tests/integration/Processor/BadgeProcessor.php b/tests/integration/Processor/BadgeProcessor.php deleted file mode 100644 index 8accee43..00000000 --- a/tests/integration/Processor/BadgeProcessor.php +++ /dev/null @@ -1,20 +0,0 @@ -label = $item['label']; - $badge->rank = $item['rank']; - - return $badge; - } -} diff --git a/tests/integration/Processor/DeveloperProcessor.php b/tests/integration/Processor/DeveloperProcessor.php deleted file mode 100644 index 2c5631c0..00000000 --- a/tests/integration/Processor/DeveloperProcessor.php +++ /dev/null @@ -1,43 +0,0 @@ -manager = $manager; - } - - public function process(mixed $item): Developer - { - $badges = $this->manager->getRepository(Badge::class) - ->findBy(['label' => \str_getcsv($item['badges'], '|', '"', '\\')]) - ; - $repositories = $this->manager->getRepository(Repository::class) - ->findBy(['label' => \str_getcsv($item['repositories'], '|', '"', '\\')]) - ; - - $developer = new Developer(); - $developer->firstName = $item['firstName']; - $developer->lastName = $item['lastName']; - foreach ($badges as $badge) { - $developer->badges->add($badge); - } - foreach ($repositories as $repository) { - $developer->repositories->add($repository); - } - - return $developer; - } -} diff --git a/tests/integration/Processor/RepositoryProcessor.php b/tests/integration/Processor/RepositoryProcessor.php deleted file mode 100644 index d5d81749..00000000 --- a/tests/integration/Processor/RepositoryProcessor.php +++ /dev/null @@ -1,20 +0,0 @@ -label = $item['label']; - $repository->url = $item['url']; - - return $repository; - } -} diff --git a/tests/symfony/src/Entity/RickAndMorty/Character.php b/tests/symfony/src/Entity/RickAndMorty/Character.php index fc41af43..51d6d96d 100644 --- a/tests/symfony/src/Entity/RickAndMorty/Character.php +++ b/tests/symfony/src/Entity/RickAndMorty/Character.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -20,35 +21,35 @@ #[UniqueEntity('name')] class Character { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'string', enumType: CharacterStatus::class)] + #[ORM\Column(type: Types::STRING, enumType: CharacterStatus::class)] #[Assert\NotNull] - public null|CharacterStatus $status; + public null|CharacterStatus $status = null; - #[ORM\Column(type: 'string', enumType: CharacterSpecie::class)] + #[ORM\Column(type: Types::STRING, enumType: CharacterSpecie::class)] #[Assert\NotNull] - public null|CharacterSpecie $specie; + public null|CharacterSpecie $specie = null; - #[ORM\Column(type: 'string', enumType: CharacterGender::class)] + #[ORM\Column(type: Types::STRING, enumType: CharacterGender::class)] #[Assert\NotNull] - public null|CharacterGender $gender; + public null|CharacterGender $gender = null; - #[ORM\Column(type: 'string', nullable: true)] - public null|string $description; + #[ORM\Column(type: Types::STRING, nullable: true)] + public null|string $description = null; #[ORM\ManyToOne(targetEntity: Location::class)] - public null|Location $origin; + public null|Location $origin = null; #[ORM\ManyToOne(targetEntity: Location::class)] - public null|Location $location; + public null|Location $location = null; /** * @var Collection diff --git a/tests/symfony/src/Entity/RickAndMorty/Episode.php b/tests/symfony/src/Entity/RickAndMorty/Episode.php index 80630649..6150a867 100644 --- a/tests/symfony/src/Entity/RickAndMorty/Episode.php +++ b/tests/symfony/src/Entity/RickAndMorty/Episode.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Sources\Tests\Symfony\App\Entity\RickAndMorty; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -18,20 +19,20 @@ #[UniqueEntity('code')] class Episode { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string', unique: true)] + #[ORM\Column(type: Types::STRING, unique: true)] #[Assert\NotNull] - public null|string $code; + public null|string $code = null; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'date_immutable')] + #[ORM\Column(type: Types::DATE_IMMUTABLE)] #[Assert\NotNull] - public null|\DateTimeImmutable $date; + public null|\DateTimeImmutable $date = null; } diff --git a/tests/symfony/src/Entity/RickAndMorty/Location.php b/tests/symfony/src/Entity/RickAndMorty/Location.php index ebb7100b..98d89d93 100644 --- a/tests/symfony/src/Entity/RickAndMorty/Location.php +++ b/tests/symfony/src/Entity/RickAndMorty/Location.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Sources\Tests\Symfony\App\Entity\RickAndMorty; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Yokai\Batch\Sources\Tests\Symfony\App\Job\RickAndMorty\ImportRickAndMortyLocationJob; @@ -16,19 +17,19 @@ #[ORM\Table(name: 'rick_and_morty_location')] class Location { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'string', enumType: LocationType::class)] + #[ORM\Column(type: Types::STRING, enumType: LocationType::class)] #[Assert\NotNull] - public null|LocationType $type; + public null|LocationType $type = null; - #[ORM\Column(type: 'string', nullable: true)] - public null|string $dimension; + #[ORM\Column(type: Types::STRING, nullable: true)] + public null|string $dimension = null; } diff --git a/tests/symfony/src/Entity/StarWars/Character.php b/tests/symfony/src/Entity/StarWars/Character.php index ba7fd02a..b8099c6d 100644 --- a/tests/symfony/src/Entity/StarWars/Character.php +++ b/tests/symfony/src/Entity/StarWars/Character.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Sources\Tests\Symfony\App\Entity\StarWars; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -18,25 +19,25 @@ #[UniqueEntity('name')] class Character { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string', unique: true)] + #[ORM\Column(type: Types::STRING, unique: true)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'integer', nullable: true)] - public null|int $birthYear; + #[ORM\Column(type: Types::INTEGER, nullable: true)] + public null|int $birthYear = null; - #[ORM\Column(type: 'string')] + #[ORM\Column(type: Types::STRING)] #[Assert\NotNull] - public null|string $gender; + public null|string $gender = null; #[ORM\ManyToOne(targetEntity: Planet::class)] - public null|Planet $homeWorld; + public null|Planet $homeWorld = null; #[ORM\ManyToOne(targetEntity: Specie::class)] - public null|Specie $specie; + public null|Specie $specie = null; } diff --git a/tests/symfony/src/Entity/StarWars/Planet.php b/tests/symfony/src/Entity/StarWars/Planet.php index 6db0ab8a..ca13ec29 100644 --- a/tests/symfony/src/Entity/StarWars/Planet.php +++ b/tests/symfony/src/Entity/StarWars/Planet.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Sources\Tests\Symfony\App\Entity\StarWars; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -18,25 +19,25 @@ #[UniqueEntity('name')] class Planet { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string', unique: true)] + #[ORM\Column(type: Types::STRING, unique: true)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'integer', nullable: true)] - public null|int $rotationPeriod; + #[ORM\Column(type: Types::INTEGER, nullable: true)] + public null|int $rotationPeriod = null; - #[ORM\Column(type: 'integer', nullable: true)] - public null|int $orbitalPeriod; + #[ORM\Column(type: Types::INTEGER, nullable: true)] + public null|int $orbitalPeriod = null; - #[ORM\Column(type: 'integer', nullable: true)] - public null|int $population; + #[ORM\Column(type: Types::INTEGER, nullable: true)] + public null|int $population = null; - #[ORM\Column(type: 'json')] + #[ORM\Column(type: Types::JSON)] #[Assert\NotNull] public array $terrain; } diff --git a/tests/symfony/src/Entity/StarWars/Specie.php b/tests/symfony/src/Entity/StarWars/Specie.php index 50acada7..be49af2c 100644 --- a/tests/symfony/src/Entity/StarWars/Specie.php +++ b/tests/symfony/src/Entity/StarWars/Specie.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Sources\Tests\Symfony\App\Entity\StarWars; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -18,20 +19,20 @@ #[UniqueEntity('name')] class Specie { - #[ORM\Column(type: 'integer')] + #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] public int $id; - #[ORM\Column(type: 'string', unique: true)] + #[ORM\Column(type: Types::STRING, unique: true)] #[Assert\NotNull] - public null|string $name; + public null|string $name = null; - #[ORM\Column(type: 'string', nullable: true)] - public null|string $classification; + #[ORM\Column(type: Types::STRING, nullable: true)] + public null|string $classification = null; - #[ORM\Column(type: 'string', nullable: true)] - public null|string $language; + #[ORM\Column(type: Types::STRING, nullable: true)] + public null|string $language = null; #[ORM\ManyToOne(targetEntity: Planet::class)] public Planet $homeWorld; diff --git a/tests/symfony/src/Job/Country/CountryJob.php b/tests/symfony/src/Job/Country/CountryJob.php index d5ccdb7d..185d6f90 100644 --- a/tests/symfony/src/Job/Country/CountryJob.php +++ b/tests/symfony/src/Job/Country/CountryJob.php @@ -57,7 +57,6 @@ final class CountryJob extends AbstractDecoratedJob implements private ItemWriterInterface $writer; private array $countries = []; private bool $flushed = false; - private LoggerInterface $yokaiBatchLogger; public static function getJobName(): string { @@ -67,7 +66,7 @@ public static function getJobName(): string public function __construct( JobExecutionStorageInterface $executionStorage, KernelInterface $kernel, - LoggerInterface $yokaiBatchLogger, + private readonly LoggerInterface $yokaiBatchLogger, ) { $writePath = fn(string $format) => new StaticValueParameterAccessor( ARTIFACT_DIR . '/symfony/country/countries.' . $format, @@ -86,7 +85,6 @@ public function __construct( new FlatFileWriter($writePath('csv'), null, null, $headers), new JsonLinesWriter($writePath('jsonl')), ]); - $this->yokaiBatchLogger = $yokaiBatchLogger; parent::__construct( new ItemJob( diff --git a/tests/symfony/src/Job/Country/CountryJsonFileReader.php b/tests/symfony/src/Job/Country/CountryJsonFileReader.php index 5b57014f..a41e3f65 100644 --- a/tests/symfony/src/Job/Country/CountryJsonFileReader.php +++ b/tests/symfony/src/Job/Country/CountryJsonFileReader.php @@ -13,11 +13,9 @@ final class CountryJsonFileReader implements ItemReaderInterface, JobExecutionAw { use JobExecutionAwareTrait; - private JobParameterAccessorInterface $filePath; - - public function __construct(JobParameterAccessorInterface $filePath) - { - $this->filePath = $filePath; + public function __construct( + private JobParameterAccessorInterface $filePath, + ) { } public function read(): iterable diff --git a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyCharacterJob.php b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyCharacterJob.php index 3d4838e5..8021e3a8 100644 --- a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyCharacterJob.php +++ b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyCharacterJob.php @@ -17,7 +17,7 @@ /** * Rick and Morty {@see Character} entity import. */ -final class ImportRickAndMortyCharacterJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportRickAndMortyCharacterJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -25,7 +25,7 @@ public static function getJobName(): string } public function __construct( - private readonly ImportRickAndMortyJobFactory $factory, + private ImportRickAndMortyJobFactory $factory, ) { } diff --git a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyEpisodeJob.php b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyEpisodeJob.php index 3693710a..59fdfbe3 100644 --- a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyEpisodeJob.php +++ b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyEpisodeJob.php @@ -12,7 +12,7 @@ /** * Rick and Morty {@see Episode} entity import. */ -final class ImportRickAndMortyEpisodeJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportRickAndMortyEpisodeJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -20,8 +20,8 @@ public static function getJobName(): string } public function __construct( - private readonly ImportRickAndMortyJobFactory $factory, - private readonly ImportRickAndMortyMemory $memory, + private ImportRickAndMortyJobFactory $factory, + private ImportRickAndMortyMemory $memory, ) { } diff --git a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyJobFactory.php b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyJobFactory.php index 5188c574..6400520a 100644 --- a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyJobFactory.php +++ b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyJobFactory.php @@ -18,7 +18,7 @@ use Yokai\Batch\Job\JobInterface; use Yokai\Batch\Storage\JobExecutionStorageInterface; -final class ImportRickAndMortyJobFactory +final readonly class ImportRickAndMortyJobFactory { public function __construct( private ValidatorInterface $validator, @@ -44,9 +44,7 @@ public function create(string $api, array $mocks, Closure $process): JobInterfac new ArrayMapProcessor( fn(mixed $value) => $value === '' ? null : $value, ), - new CallbackProcessor(function (mixed $item) use ($process) { - return $process($item, $this->memory); - }), + new CallbackProcessor(fn(mixed $item) => $process($item, $this->memory)), new SkipInvalidItemProcessor($this->validator), ]), new ObjectWriter($this->doctrine), diff --git a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyLocationJob.php b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyLocationJob.php index f3e72955..39da9f51 100644 --- a/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyLocationJob.php +++ b/tests/symfony/src/Job/RickAndMorty/ImportRickAndMortyLocationJob.php @@ -14,7 +14,7 @@ /** * Rick and Morty {@see Episode} entity import. */ -final class ImportRickAndMortyLocationJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportRickAndMortyLocationJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -22,8 +22,8 @@ public static function getJobName(): string } public function __construct( - private readonly ImportRickAndMortyJobFactory $factory, - private readonly ImportRickAndMortyMemory $memory, + private ImportRickAndMortyJobFactory $factory, + private ImportRickAndMortyMemory $memory, ) { } diff --git a/tests/symfony/src/Job/RickAndMorty/RickAndMortyApiReader.php b/tests/symfony/src/Job/RickAndMorty/RickAndMortyApiReader.php index 96620903..202eac5d 100644 --- a/tests/symfony/src/Job/RickAndMorty/RickAndMortyApiReader.php +++ b/tests/symfony/src/Job/RickAndMorty/RickAndMortyApiReader.php @@ -7,7 +7,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; use Yokai\Batch\Job\Item\ItemReaderInterface; -final class RickAndMortyApiReader implements ItemReaderInterface +final readonly class RickAndMortyApiReader implements ItemReaderInterface { public function __construct( private HttpClientInterface $httpClient, diff --git a/tests/symfony/src/Job/StarWars/ImportStarWarsCharacterJob.php b/tests/symfony/src/Job/StarWars/ImportStarWarsCharacterJob.php index 59a4494b..8d06717b 100644 --- a/tests/symfony/src/Job/StarWars/ImportStarWarsCharacterJob.php +++ b/tests/symfony/src/Job/StarWars/ImportStarWarsCharacterJob.php @@ -15,7 +15,7 @@ /** * Star Wars {@see Character} entity import. */ -final class ImportStarWarsCharacterJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportStarWarsCharacterJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -23,7 +23,7 @@ public static function getJobName(): string } public function __construct( - private readonly ImportStarWarsJobFactory $factory, + private ImportStarWarsJobFactory $factory, ) { } diff --git a/tests/symfony/src/Job/StarWars/ImportStarWarsJobFactory.php b/tests/symfony/src/Job/StarWars/ImportStarWarsJobFactory.php index 0ab16867..9cc31312 100644 --- a/tests/symfony/src/Job/StarWars/ImportStarWarsJobFactory.php +++ b/tests/symfony/src/Job/StarWars/ImportStarWarsJobFactory.php @@ -20,7 +20,7 @@ use Yokai\Batch\Job\Parameters\StaticValueParameterAccessor; use Yokai\Batch\Storage\JobExecutionStorageInterface; -final class ImportStarWarsJobFactory +final readonly class ImportStarWarsJobFactory { public function __construct( private ValidatorInterface $validator, @@ -44,9 +44,7 @@ public function create(string $file, Closure $process): JobInterface new ArrayMapProcessor( fn(string $value) => $value === 'NA' ? null : $value, ), - new CallbackProcessor(function (mixed $item) use ($process) { - return $process($item, $this->objectRegistry); - }), + new CallbackProcessor(fn(mixed $item) => $process($item, $this->objectRegistry)), new SkipInvalidItemProcessor($this->validator), ]), new ObjectWriter($this->doctrine), diff --git a/tests/symfony/src/Job/StarWars/ImportStarWarsPlanetJob.php b/tests/symfony/src/Job/StarWars/ImportStarWarsPlanetJob.php index 6b00da70..ca208778 100644 --- a/tests/symfony/src/Job/StarWars/ImportStarWarsPlanetJob.php +++ b/tests/symfony/src/Job/StarWars/ImportStarWarsPlanetJob.php @@ -12,7 +12,7 @@ /** * Star Wars {@see Planet} entity import. */ -final class ImportStarWarsPlanetJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportStarWarsPlanetJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -20,7 +20,7 @@ public static function getJobName(): string } public function __construct( - private readonly ImportStarWarsJobFactory $factory, + private ImportStarWarsJobFactory $factory, ) { } diff --git a/tests/symfony/src/Job/StarWars/ImportStarWarsSpecieJob.php b/tests/symfony/src/Job/StarWars/ImportStarWarsSpecieJob.php index 6de377af..e6fd37ca 100644 --- a/tests/symfony/src/Job/StarWars/ImportStarWarsSpecieJob.php +++ b/tests/symfony/src/Job/StarWars/ImportStarWarsSpecieJob.php @@ -14,7 +14,7 @@ /** * Star Wars {@see Specie} entity import. */ -final class ImportStarWarsSpecieJob implements JobInterface, JobWithStaticNameInterface +final readonly class ImportStarWarsSpecieJob implements JobInterface, JobWithStaticNameInterface { public static function getJobName(): string { @@ -22,7 +22,7 @@ public static function getJobName(): string } public function __construct( - private readonly ImportStarWarsJobFactory $factory, + private ImportStarWarsJobFactory $factory, ) { } diff --git a/tests/symfony/src/Kernel.php b/tests/symfony/src/Kernel.php index 004980c9..c55d710d 100644 --- a/tests/symfony/src/Kernel.php +++ b/tests/symfony/src/Kernel.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\HttpKernel\Log\Logger; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Yokai\Batch\Bridge\Doctrine\Persistence\ObjectRegistry; use Yokai\Batch\Bridge\Symfony\Framework\YokaiBatchBundle; use Yokai\Batch\Job\JobInterface; @@ -65,7 +66,7 @@ protected function configureContainer(ContainerConfigurator $container): void ]); $container->extension('security', [ 'password_hashers' => [ - 'Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface' => 'auto', + PasswordAuthenticatedUserInterface::class => 'auto', ], 'providers' => [ 'users_in_memory' => ['memory' => null], diff --git a/tests/symfony/tests/UserInterfaceTest.php b/tests/symfony/tests/UserInterfaceTest.php index 6396b9fc..5d9a6afc 100644 --- a/tests/symfony/tests/UserInterfaceTest.php +++ b/tests/symfony/tests/UserInterfaceTest.php @@ -87,7 +87,7 @@ public function testView(string $job, \Closure $expected): void $expected($page); } - public static function view() + public static function view(): \Generator { yield [ CountryJob::getJobName(), @@ -126,7 +126,7 @@ public function testLogs(string $job, \Closure $expected): void $expected($http->getResponse()->getContent()); } - public static function logs() + public static function logs(): \Generator { yield [ CountryJob::getJobName(),