* @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:----LPvdCgXpbNC8nLGPM9gqVwai12htMPDxW6VIlEGXieHWyA71/Crp3UkAAzLjTDBOStPTUDYP1xXHPREr6IGthWQF+lw0eHOgrKxy1wHUi2DXEDm0vmXk5yK4BQBeJvMpodN8fxjF50jy54YR9bt6VogVyhUSX4VIyOK5bfBQrnaqaoipTJLSO5JwNwt2V+5yj4gcKLKao8cgAXbG5qB+qpIEVdstA8IOUCWSLDmM2VFe6FUibFIKXMscleTgn54nvJgxvo5Xr8eq/tu1GGpdO2UvoeHN2WRKcIlgFDPdt6YiCsJKrN+ZkK11JKR0nfoIBMLL3S0SI4ik0rVTDHBc1LK16+gjp0P5bAU+Wza53mRaW9sCYz0SE/epWRSvE+Vea1eUgAwXRk1OLXJSdT2qJFbRtlXxfHY8wLQ1gM24cMziUT8cTVjF/D5oKJzNRWNmE6I45AbuaG6B543VN4Jq0QfkCTJ4zfGJA2qn29QEQKK3Dz4EC8hlrHia292M7H5n62HcZI1HedSaAWp2hWKgYCsXpU9AanhjiHk58/yrGhF1ivnRn/IE8ZX1bdfRasxYUzdkNLGT0t9oX7xOd1G7tTBm4ZIYuLH/gKUwd1N3FfCgS6PJkKvCg3PdFw2nfkcLOQpS6OGBEI6Bskh7auYF3g4Uj5IVMM48x6Y4ar74IOI=----ATTACHMENT:----Nzc0OTYzMzczMTMzODIyOCAzMDk4MDc4NzI2NzYyMDE1IDgwNTkzNjU4NjIyNzk2MTA=