public function testMapperShouldThrowExceptionWhenSourceMemberMissing() { $this->setExpectedException('Papper\\MappingException'); // arrange $engine = new Engine(); // act $engine->map(new Source())->toType(Destination::className()); }
public function testMappingShouldThrowExceptionWhenCreatedInvalidDestinationClass() { $this->setExpectedException('Papper\\MappingException'); // arrange $engine = new Engine(); $engine->createMap(Source::className(), Destination::className())->constructUsing(function (Source $source) { return new InvalidDestination($source->value); }); // act $engine->map(new Source('Some value'))->toType(Destination::className()); }
public function testMappingFromPropertyToProperties() { // arrange $engine = new Engine(); $source = new Source(); $source->propertyToProperty = 'property to property'; $source->propertyToSetter = 'property to setter'; $source->setGetterToProperty('getter to property'); $source->setGetterToSetter('getter to setter'); // act /** @var Destination $destination */ $destination = $engine->map($source)->toType(Destination::className()); // assert $this->assertEquals('property to property', $destination->propertyToProperty); $this->assertEquals('property to setter', $destination->getPropertyToSetter()); $this->assertEquals('getter to property', $destination->getterToProperty); $this->assertEquals('getter to setter', $destination->getGetterToSetter()); }