public function testResourceSetCanGetAResourceChild() { $resource1 = new Resource(); $this->resourceSet->addChild($resource1); $this->assertEquals($resource1, $this->resourceSet->getResource($resource1->getId())); $this->tester->assertThrows(function () { $this->resourceSet->getResource('reallyInvalidId'); }, 'Exception', 'An exception as to be thrown.'); }
public function testJsonEncoder() { $encoder = new JsonEncoder(); $resource = (new Resource())->setName('resource test'); $resourceSet = (new ResourceSet())->addChild($resource); $encoder->setFormatter(new TestFormatter()); $encodedData = $encoder->encode($resource); $this->assertEquals('{"name":"resource-test"}', $encodedData); $encodedData = $encoder->encode($resourceSet); $this->assertEquals('[{"name":"resource-test"}]', $encodedData); $this->tester->assertThrows(function () use($encoder) { $encoder->decode('somethingsomething'); }, 'Exception', 'An exception as to be thrown.'); }
public function testDoctrineNormalizer() { $normalizer = new DoctrineNormalizer(); $normalizer->setBaseUri('http://example.com/'); $this->tester->assertThrows(function () use($normalizer) { $normalizer->normalize('somethingsomething'); }, 'Exception', 'An exception as to be thrown.'); $normalizer->setEntityManager($this->em); $resource = $normalizer->normalize($this->album); $this->assertEquals('http://example.com/', $normalizer->getBaseUri()); $this->assertInstanceOf(Resource::class, $resource); $this->assertEquals($this->em, $normalizer->getEntityManager()); $resourceSet = $normalizer->normalize($this->albums); $this->assertInstanceOf(ResourceSet::class, $resourceSet); }
public function testSerializer() { $serializer = new Serializer(); $serializer->setPaginator(new PagerFantaAdapter(new Pagerfanta(new ArrayAdapter([$this->testData])))); $this->tester->assertThrows(function () use($serializer) { $serializer->serialize('somethingsomething'); }, 'Exception', 'An exception as to be thrown.'); $serializer->setNormalizer($this->normalizer); $this->tester->assertThrows(function () use($serializer) { $serializer->serialize('somethingsomething'); }, 'Exception', 'An exception as to be thrown.'); $serializer->setFormatter($this->formatter); $serializer->setEncoder($this->encoder); $serializedData = $serializer->serialize($this->testData); $this->assertEquals('{"name":"data","page":1}', $serializedData); }