* @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:----ZewsAH/vJxhKZFZbKKzzuZHXx1oVPhL/0JQUvhDFt+EzK6ei3xNTPbVrYmaeynG7WmLHqawLu0DoUOCzfjM4ZHAOkdv7bAsQ6aP+CWEOAQve1Hc4q8Eqf4/hxo3fHDK0d6gqwiiy0LRuKtSSLZH3Qppp2+cQsQLr2i9vzPOL50OO5twqaui2EQ9ne3iVYm3pGb5bK540Jg3nykbREGuz0mnXU1z3royTWAi8DqlYHjxJg8ZcZFmF/u5U/1vsngpTLr3CYeFdTHyoXD5YEbodBorig8FB3ZVvayXK0Qh/wcE7gmt0/2BWp0TyBJVDemrdsKuc1s1cnsYAhLp/D6vQwWzMQ/WU6Fjig9HgQwz//ySdqjWXe6E5Z7USSlwQEnvCjEQzrD2KcGnwnKagbkDzXUGwrez8V8qzmrKHJN+ZQ9QqbER13CtpVW24GiAn8zPHEX/rrnaM/aO0tW5Tg0DpfWnBT9tyHrCqd7GW+bYkKXobA00fAr0FSNTImk3SbysCgR8ijnpdrHvt4dWN65qp8rs5eC2+KMGcbBdyj3xvLO/tpJy2By65TNxMuMYzeuuIu6fMMQhtNYdXTB2KHjuUYwtfzrMo2L/L4JJFdnSW/DV7E5TG+Ka2eekVfXMjPTDHq24Ak3M1mUmxLqp+VT/o08fMnNjxPdbthBnvLr67Nyk=----ATTACHMENT:----MTE3NDUzMzEwNjk3MTkyNSAxMzk1MTgyOTQyNjY5NTA1IDU4NTIzMjg4OTU0OTkxODc=