Skip to content

Conversation

@lyrixx
Copy link
Member

@lyrixx lyrixx commented Mar 4, 2025

No description provided.

public function testConstructorAndRelationMissing(): void
{
$user = ['name' => 'foo'];
$this->expectException(MissingConstructorArgumentsException::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added this, from the input this is the expected use case


public function testConstructorAndRelationMissing2(): void
{
$user = ['name' => 'foo', 'int' => ['foo' => 1]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the input array, passing an Object will not work as we expecte pure base type when mapping from array, if there is something else then a transformer should be provided

/** @var Fixtures\UserConstructorDTOWithRelation $userDto */
$userDto = $this->autoMapper->map($user, Fixtures\UserConstructorDTOWithRelation::class, [
MapperContext::CONSTRUCTOR_ARGUMENTS => [
Fixtures\UserConstructorDTOWithRelation::class => ['int' => new Fixtures\IntDTO(1)],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class was wrong, i put the correct one and it works as expected

@lyrixx
Copy link
Member Author

lyrixx commented Mar 6, 2025

Thanks 👍🏼

@lyrixx lyrixx changed the title Add failing test case to show issues contructor with relation fix(constructor): better check for property exists when building constructor args Mar 6, 2025
@lyrixx
Copy link
Member Author

lyrixx commented Mar 6, 2025

thanks 👍🏼

@joelwurtz joelwurtz merged commit 8083bfd into main Mar 6, 2025
10 checks passed
@joelwurtz joelwurtz deleted the constructor-missing branch March 6, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants