HandlerRegistryTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace JMS\Serializer\Tests\Handler;
  3. use JMS\Serializer\GraphNavigator;
  4. use JMS\Serializer\Handler\HandlerRegistry;
  5. class HandlerRegistryTest extends \PHPUnit_Framework_TestCase
  6. {
  7. protected $handlerRegistry;
  8. protected function setUp()
  9. {
  10. $this->handlerRegistry = $this->createHandlerRegistry();
  11. }
  12. public function testRegisteredHandlersCanBeRetrieved()
  13. {
  14. $jsonSerializationHandler = new DummyHandler();
  15. $this->handlerRegistry->registerHandler(GraphNavigator::DIRECTION_SERIALIZATION, '\stdClass', 'json', $jsonSerializationHandler);
  16. $jsonDeserializationHandler = new DummyHandler();
  17. $this->handlerRegistry->registerHandler(GraphNavigator::DIRECTION_DESERIALIZATION, '\stdClass', 'json', $jsonDeserializationHandler);
  18. $xmlSerializationHandler = new DummyHandler();
  19. $this->handlerRegistry->registerHandler(GraphNavigator::DIRECTION_SERIALIZATION, '\stdClass', 'xml', $xmlSerializationHandler);
  20. $xmlDeserializationHandler = new DummyHandler();
  21. $this->handlerRegistry->registerHandler(GraphNavigator::DIRECTION_DESERIALIZATION, '\stdClass', 'xml', $xmlDeserializationHandler);
  22. $this->assertSame($jsonSerializationHandler, $this->handlerRegistry->getHandler(GraphNavigator::DIRECTION_SERIALIZATION, '\stdClass', 'json'));
  23. $this->assertSame($jsonDeserializationHandler, $this->handlerRegistry->getHandler(GraphNavigator::DIRECTION_DESERIALIZATION, '\stdClass', 'json'));
  24. $this->assertSame($xmlSerializationHandler, $this->handlerRegistry->getHandler(GraphNavigator::DIRECTION_SERIALIZATION, '\stdClass', 'xml'));
  25. $this->assertSame($xmlDeserializationHandler, $this->handlerRegistry->getHandler(GraphNavigator::DIRECTION_DESERIALIZATION, '\stdClass', 'xml'));
  26. }
  27. protected function createHandlerRegistry()
  28. {
  29. return new HandlerRegistry();
  30. }
  31. }
  32. class DummyHandler
  33. {
  34. public function __call($name, $arguments)
  35. {
  36. }
  37. }