diff --git a/src/System/Wrappers/PlainObjectWrapper.php b/src/System/Wrappers/PlainObjectWrapper.php index fb3c1b0..1532e4e 100755 --- a/src/System/Wrappers/PlainObjectWrapper.php +++ b/src/System/Wrappers/PlainObjectWrapper.php @@ -124,13 +124,14 @@ protected function hydrate($attributes) foreach ($properties as $property) { $name = $property->getName(); + $column = $this->getMap()->getColumnNameForAttribute($name); if ($property->isPublic()) { - $this->entity->$name = $attributes[$name]; + $this->entity->$name = $attributes[$column]; } else { $property->setAccessible(true); - if (isset($attributes[$name])) { - $property->setValue($this->entity, $attributes[$name]); + if (isset($attributes[$column])) { + $property->setValue($this->entity, $attributes[$column]); } } } diff --git a/tests/cases/ReflectionMappingTest.php b/tests/cases/ReflectionMappingTest.php index c49c8c3..9c7ee1b 100755 --- a/tests/cases/ReflectionMappingTest.php +++ b/tests/cases/ReflectionMappingTest.php @@ -1,5 +1,6 @@ $realisator->id, ]); } + + /** @test */ + public function we_can_store_and_retrieve_a_plain_php_object_with_a_custom_attribute_mapping() + { + $realisator = new CustomAttributeRealisator('Stanley Kubrick'); + $mapper = $this->mapper(CustomAttributeRealisator::class); + $mapper->store($realisator); + $this->seeInDatabase('realisators', [ + 'name' => 'Stanley Kubrick', + ]); + $foundRealisator = $mapper->find($realisator->id); + $this->matches('Stanley Kubrick')->evaluate($foundRealisator->getName()); + } } diff --git a/tests/src/CustomAttributeRealisator.php b/tests/src/CustomAttributeRealisator.php new file mode 100644 index 0000000..cd75a23 --- /dev/null +++ b/tests/src/CustomAttributeRealisator.php @@ -0,0 +1,28 @@ +realisatorName = $name; + } + + public function getName() + { + return $this->realisatorName; + } +} \ No newline at end of file diff --git a/tests/src/Maps/CustomAttributeRealisatorMap.php b/tests/src/Maps/CustomAttributeRealisatorMap.php new file mode 100644 index 0000000..a8cbf6b --- /dev/null +++ b/tests/src/Maps/CustomAttributeRealisatorMap.php @@ -0,0 +1,16 @@ + 'realisatorName', + ]; +} \ No newline at end of file