1<?php 2 3declare(strict_types=1); 4 5namespace JMS\Serializer\Tests\Handler; 6 7use JMS\Serializer\GraphNavigatorInterface; 8use JMS\Serializer\Handler\HandlerRegistry; 9use PHPUnit\Framework\TestCase; 10 11class HandlerRegistryTest extends TestCase 12{ 13 protected $handlerRegistry; 14 15 protected function setUp() 16 { 17 $this->handlerRegistry = $this->createHandlerRegistry(); 18 } 19 20 public function testRegisteredHandlersCanBeRetrieved() 21 { 22 $jsonSerializationHandler = new DummyHandler(); 23 $this->handlerRegistry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, '\stdClass', 'json', $jsonSerializationHandler); 24 25 $jsonDeserializationHandler = new DummyHandler(); 26 $this->handlerRegistry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, '\stdClass', 'json', $jsonDeserializationHandler); 27 28 $xmlSerializationHandler = new DummyHandler(); 29 $this->handlerRegistry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, '\stdClass', 'xml', $xmlSerializationHandler); 30 31 $xmlDeserializationHandler = new DummyHandler(); 32 $this->handlerRegistry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, '\stdClass', 'xml', $xmlDeserializationHandler); 33 34 self::assertSame($jsonSerializationHandler, $this->handlerRegistry->getHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, '\stdClass', 'json')); 35 self::assertSame($jsonDeserializationHandler, $this->handlerRegistry->getHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, '\stdClass', 'json')); 36 self::assertSame($xmlSerializationHandler, $this->handlerRegistry->getHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, '\stdClass', 'xml')); 37 self::assertSame($xmlDeserializationHandler, $this->handlerRegistry->getHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, '\stdClass', 'xml')); 38 } 39 40 protected function createHandlerRegistry() 41 { 42 return new HandlerRegistry(); 43 } 44} 45 46class DummyHandler 47{ 48 public function __call($name, $arguments) 49 { 50 } 51} 52