Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test case for constructor + readonly + list + constructor_arguments #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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', [
'kubawerlos/php-cs-fixer-custom-fixers' => '^3.21',
]);
}

#[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');
Expand Down
24 changes: 24 additions & 0 deletions tests/AutoMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\ConstructorWithRelationAndReadonlyAndList;

class Entity
{
public function __construct(
public string $id,
public array $locales,
public array $pages,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\ConstructorWithRelationAndReadonlyAndList;

class Target
{
/**
* @param list<string> $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;
}
}
Loading