* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class MapperTest extends TestCase { public function testMap() { $source = Record::fromArray([ 'id' => 1, // userId is not available in the source "userId" => 12, // underscore names are converted to camelcase "right_level" => 'bar', 'title' => 'foo', 'content' => 'bar', 'rating' => 'a-rating', 'date' => '2014-09-06', ]); $destination = new Destination(); $testCase = $this; Mapper::map($source, $destination, array( 'title' => 'description', 'content' => new Rule('content'), 'rating' => new Rule('level', 'no-rating'), 'date' => new Rule('date', function ($value) use ($testCase) { $testCase->assertEquals('2014-09-06', $value); return strtotime($value); }), )); $this->assertEquals($source->id, $destination->getId()); $this->assertEquals($source->right_level, $destination->getRightLevel()); $this->assertEquals($source->title, $destination->getDescription()); $this->assertEquals($source->content, $destination->getContent()); $this->assertEquals('no-rating', $destination->getLevel()); $this->assertEquals('1409961600', $destination->getDate()); } public function testMapInvalidDestination() { $this->expectException(\InvalidArgumentException::class); Mapper::map(new Record(), 'foo', array()); } } class Destination { protected $id; protected $rightLevel; protected $description; protected $content; protected $level; protected $date; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; } public function setRightLevel($rightLevel) { $this->rightLevel = $rightLevel; } public function getRightLevel() { return $this->rightLevel; } public function setDescription($description) { $this->description = $description; } public function getDescription() { return $this->description; } public function setContent($content) { $this->content = $content; } public function getContent() { return $this->content; } public function setLevel($level) { $this->level = $level; } public function getLevel() { return $this->level; } public function setDate($date) { $this->date = $date; } public function getDate() { return $this->date; } } __halt_compiler();----SIGNATURE:----Wj5NwrBRrgHhwpLAzmQ1Hk9zX613OoyDDZY2mT4bdWk4tRpmZR/jf++c3gTq/TcCgbJBu1wULnOrwDcJoL6gWhAFv823wOBzrIxy7yRF6c0nBbhm1f8e/ea54GwdpVEwXLIUq/SdPQcq+0cyuZKKneJJ0aFtlnXU2GEO9ZXf8Q7sD6vFSVYww7eNVx9q3JpZ6LMgFnY62zT/xGE+c38dGrE7oA3BvzGm6q26tlj+Cg8Z7CRRw5fs1iZbD95pUPXfpmRDUD4dp/7M776R+Cde3blPPi2kn+7hRjAVlmTE4W/FhSK9y71UXwEYwMqj3S6HwUbnLq3aP1qXXxTJjscv7HkrOr0YvYaEqKaIQWGRb2U2DdY8omzDTuvskYTCcBVovRpNuQteCFilHBweiAvwVPEl29JSIv68U69gA2x+uUryKUhrbRdj906kl1MbpDST3U7RK2G27CXugrlTc06CD2TDsP7mvWPvjAIyQJzLngPl/h514t/3qy9n9CHJkUpioyRGyMr6Y0g+Gw+FY/yRnZgFAZPOpyp4xTDguORDi/uhR6CfNbzFD4cyUXJg2IkI3sBaYuGmeUgk/96tgpwpmIjG5Grm09bFCxnk7kRwV7sgaIgnZ869j0ZAHTx+p50ee5tPxwXKFbm1mTAclrJ1gV0d8SJ0cJO/oPdLQ3i97A0=----ATTACHMENT:----Nzk4OTkzNzM3MTY1MDE1MyAyODc1NDU4NzQ3Mjk0OTc5IDczMTMyNjU0MTQyNzU4Nzc=