* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class DumperTest extends TestCase { public function testDump() { include_once __DIR__ . '/News.php'; $config = new Meta(); $config['foo'] = 'bar'; $location = new Location(); $location->setLat(12.34); $location->setLong(56.78); $author = new Author(); $author->setTitle('foo'); $author->setEmail('foo@bar.com'); $author->setCategories(['foo', 'bar']); $author->setLocations([$location, $location]); $author->setOrigin($location); $web = new Web(); $web->setName('foo'); $web->setUrl('http://google.com'); $profileImage = fopen('php://memory', 'r+'); fwrite($profileImage, 'foobar'); $meta = new Meta(); $meta['tags_0'] = 'foo'; $meta['tags_1'] = 'bar'; $news = new News(); $news->setConfig($config); $news->setTags(['foo', 'bar']); $news->setReceiver([$author]); $news->setResources([$web, $location]); $news->setProfileImage($profileImage); $news->setRead(false); $news->setSource($web); $news->setAuthor($author); $news->setMeta($meta); $news->setSendDate(new Date('2016-12-11')); $news->setReadDate(new DateTime('2016-12-11T10:50:00')); $news->setExpires(new Duration('P1D')); $news->setPrice(50); $news->setRating(4); $news->setContent('foobar'); $news->setQuestion('foo'); $news->setCoffeeTime(new Time('10:49:00')); $news->setProfileUri(new Uri('urn:foo:image')); $reader = new AnnotationReader(); $dumper = new Dumper($reader); $actual = $dumper->dump($news); $this->assertInstanceOf(RecordInterface::class, $actual); $actual = json_encode($actual, JSON_PRETTY_PRINT); $expect = file_get_contents(__DIR__ . '/expect.json'); $this->assertJsonStringEqualsJsonString($expect, $actual, $actual); } public function testDumpTraversable() { include_once __DIR__ . '/News.php'; $location = new Location(); $location->setLat(12.34); $location->setLong(56.78); $locations = [ $location, $location, ]; $author = new Author(); $author->setLocations($locations); $reader = new AnnotationReader(); $dumper = new Dumper($reader); $actual = $dumper->dump($author); $this->assertInstanceOf(RecordInterface::class, $actual); $actual = json_encode($actual, JSON_PRETTY_PRINT); $expect = file_get_contents(__DIR__ . '/expect_iterable.json'); $this->assertJsonStringEqualsJsonString($expect, $actual, $actual); } } __halt_compiler();----SIGNATURE:----CFcaouH8JzEN5ph8SfsItMseGYbQUFLVxcySfaUa4RsF2k3n5s43YK5HqYHFlxdUB1MX5ckhw0/S2ONo6PzhnnJ/6NmQxP3K7H8c8MXsFSZFXa3i5eojc8xyqCe5IfZfCbUH0GDaCZUpAO242FSJF5x9yHT71k3JV1KoSQq9Us/uqdr4lEP3kMTuqQGCePqC1FCQq6pAxE8PjpYxmRiolXMzer7oBk5MPYmXvryPidjiYidLlBRrsfOQKgJR5WyqgjFBtjquwGzuds9i6PXOqJ3LQkI3y1Td60GNBfISRXMh6m4vEPNxdOFmjuVjcTMMhx9JEpnTFRF3BV87mqkiMKv1KPNLs81VVbIkWPEswk65CMsYcPNDKdGN4mSfe0nV7jvwUFfruBVIm2AOhtBmV13r0JOmBDCQKOCSn/djP4Clf6OoKfyxVhfpj53HQndIIAncZDEnkPS+Z6S4/vvk5Wg0gDEOsVnJ3YhCsptXv6UuYnYdLKN2ieUv2ThzzVsK5d2yw99MdJXh5rDZrhlmGgcEUBdhhuKgSTgr0CHbJhQXAHCJvJ3RmX5FszXWCcWK8vJQQcFnpiimkjGwXhONdrFuAqCu2GIZttvTAWvtGCbzOPlDbotaYCrKaCB5kS2HL6lnwpkC0lONjsyY5jndspVdYOuvtthO7cPGqWN1FnU=----ATTACHMENT:----NzA5NTk2OTg0NDI0NDgxNCA2MzkyNTkzNjE3OTcwOTYwIDIwMDAxODIwMjYwMjQ1NDM=