public function testOverwriteTransformers() { $serializerMock = $this->getMockBuilder('SoboLAN\\RestNegotiator\\Serializer\\RestSerializerInterface')->disableOriginalConstructor()->getMock(); $serializerMock->expects($this->once())->method('replaceTransformers')->with($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY)); $transformersNames = array('sobolan.restnegotiator.transformer.list'); $serializerFactory = new RestSerializerFactory(); $serializerFactory->setContainer($this->container); $serializerFactory->overwriteTransformers($serializerMock, $transformersNames); }
private function restoreDefaultTransformers() { /** * If a subrequest is made or if the {@link getResponse} method is called, * then the transformers overwritten above can not be present within the Serializer. * * This is because there may be a different version value in the "Accept" header, * a version which does not overwrite all the transformers which were overwritten above. * It would lead to inconsistent / incorrect outputs. * * In order to solve this, the default transformers are restored to the Serializer. * This way, when a subrequest or a call to {@link getResponse} is made, those executions * will have the freedom to overwrite their own transformers. */ $this->serializerFactory->overwriteTransformers($this->serializer, $this->defaultTransformersNames); }