* @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:----DOFwABdVRT2+m2vg41X7m/P6FKvQ8VrGR5T949BiRC1SBb535yHYXDA29YzLU4wdg9Dp5jvkMQNP0u+eNFnT9mzdVP6hglDhLbQ94YbqKqrA33edlSIHmbU1m8jbJfQWA8tXkWRqs9mmBn3ypo3eDG1N82IdpNR+VQcwSslhPlzMUgmn/2IrsEc/1tSs8jEVVenHgEZH5BQAb28YLWZEfSYCFVN6zrryvUg5cVMHSGZhYM4ICbgCejHZ/oa9gaTT4S4OKX0mT7ke1/HFqO2plybzSg+KF0qs7IhYB4Af59qE2XtSGCJfICgvbcI14hv5pl40/qwyi/upcDdE7QjHgixZ3CfbEqO10WhxYbCgQfMDJ5j2Jl1BLyGF4PyxzUfE7jBMlaANIH2Fdm1pLw3GjJ1Q+4uuI98NvFfIuNdUDwnPKyt1n9BvL6n5vJnf8u/enDBZxpGmwjCXuvSYTc0soTpt62cKhPGWKZg48NUuO6sWz0z4g7Gf1/vdDTcJUqOHQtLUMddlQmNqSRURMy11DfUn0P17TovFtl0sTpW7KTp2o/1199tW1S4GvEZDyKzIxE2Rx4SCyujLImbJp0y0+G1nqnjAd6DPUm+k2U8JzdjHJu466SNQMIQ0tSrYlojO8BTi9BkQaWF/q33mowldntlu/1n1J8QXO6s/Y7OvNkA=----ATTACHMENT:----NTc5OTkzMjgzMzc2NDA0NSA2MDkwNTkwODM0MDQyNTY2IDMzNTE2OTU0MTcxMDQ0Mjg=