Skip to content

Commit

Permalink
Fix SetTo not setting properties that are not present on the source o…
Browse files Browse the repository at this point in the history
…bject

See #53
  • Loading branch information
mark-gerarts committed Feb 27, 2020
1 parent 94a2863 commit a74b074
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/MappingOperation/Implementations/SetTo.php
Expand Up @@ -33,4 +33,12 @@ protected function getSourceValue($source, string $propertyName)
{
return $this->value;
}

/**
* @inheritdoc
*/
protected function canMapProperty(string $propertyName, $source): bool
{
return true;
}
}
14 changes: 14 additions & 0 deletions test/MappingOperation/Implementations/SetToTest.php
Expand Up @@ -4,6 +4,7 @@

use AutoMapperPlus\Configuration\Options;
use AutoMapperPlus\Test\Models\SimpleProperties\Destination;
use AutoMapperPlus\Test\Models\SimpleProperties\DestinationAlt;
use AutoMapperPlus\Test\Models\SimpleProperties\Source;
use PHPUnit\Framework\TestCase;

Expand All @@ -25,4 +26,17 @@ public function testItMapsAProperty()

$this->assertEquals('always the same value', $destination->name);
}

public function testItDoesntNeedTheSourceProperty()
{
$operation = new SetTo('always the same value');
$operation->setOptions(Options::default());
$source = new Source();
$destination = new DestinationAlt();

// anotherProperty is not present on the source object.
$operation->mapProperty('anotherProperty', $source, $destination);

$this->assertEquals('always the same value', $destination->anotherProperty);
}
}

0 comments on commit a74b074

Please sign in to comment.