diff --git a/castor.php b/castor.php index 70207343..14e691fb 100644 --- a/castor.php +++ b/castor.php @@ -15,7 +15,7 @@ function qa_cs_check() ]); } -#[AsTask('cs:fix', namespace: 'qa', description: 'Fix all coding standards')] +#[AsTask('cs:fix', namespace: 'qa', description: 'Fix all coding standards', aliases: ['cs'])] function qa_cs_fix() { php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php'], '3.50', [ @@ -23,7 +23,7 @@ function qa_cs_fix() ]); } -#[AsTask('phpstan', namespace: 'qa', description: 'Run PHPStan for static analysis')] +#[AsTask('phpstan', namespace: 'qa', description: 'Run PHPStan for static analysis', aliases: ['phpstan'])] function qa_phpstan() { phpstan(['analyse', '--configuration', __DIR__ . '/phpstan.neon', '--memory-limit=-1'], '1.11.1'); diff --git a/tests/AutoMapperTest.php b/tests/AutoMapperTest.php index 0c708e27..90810769 100644 --- a/tests/AutoMapperTest.php +++ b/tests/AutoMapperTest.php @@ -519,6 +519,30 @@ public function testConstructorAndRelationMissing2(): void self::assertSame(30, $userDto->age); } + public function testConstructorWithRelationAndReadonlyAndList(): void + { + $entity = new Fixtures\ConstructorWithRelationAndReadonlyAndList\Entity( + 'my id', + ['fr', 'en'], + ['page1' => ['foo'], 'page2' => ['bar']], + ); + + /** @var Fixtures\ConstructorWithRelationAndReadonlyAndList\Target $target */ + $target = $this->autoMapper->map($entity, Fixtures\ConstructorWithRelationAndReadonlyAndList\Target::class, [ + MapperContext::CONSTRUCTOR_ARGUMENTS => [ + Fixtures\ConstructorWithRelationAndReadonlyAndList\Target::class => [ + 'entity' => $entity, + ], + ], + ]); + + $this->assertInstanceOf(Fixtures\ConstructorWithRelationAndReadonlyAndList\Target::class, $target); + $this->assertInstanceOf(Fixtures\ConstructorWithRelationAndReadonlyAndList\Entity::class, $target->getEntity()); + $this->assertSame('my id', $target->id); + $this->assertSame(['fr', 'en'], $target->locales); + $this->assertSame(['page1' => ['foo'], 'page2' => ['bar']], $target->pages); + } + public function testConstructorAndRelationMissingAndContext(): void { $user = ['name' => 'foo']; diff --git a/tests/Fixtures/ConstructorWithRelationAndReadonlyAndList/Entity.php b/tests/Fixtures/ConstructorWithRelationAndReadonlyAndList/Entity.php new file mode 100644 index 00000000..a77e514c --- /dev/null +++ b/tests/Fixtures/ConstructorWithRelationAndReadonlyAndList/Entity.php @@ -0,0 +1,15 @@ + $locales + */ + public function __construct( + private readonly Entity $entity, + public readonly string $id, + public array $locales, + public array $pages, + ) { + } + + public function getEntity(): Entity + { + return $this->entity; + } +}