diff --git a/composer.json b/composer.json index 0688b0c..955552c 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,13 @@ "require": { "php": "^7.2", "symfony-cmf/resource-bundle": "^1.0", - "jms/serializer-bundle": "^1.0 | ^2.0 | ^3.0", + "jms/serializer-bundle": "^2.0 || ^3.0", "symfony/translation": "^2.8 || ^3.3 || ^4.0" }, "require-dev": { "symfony-cmf/testing": "^2.1@dev", "symfony/phpunit-bridge": "^5", "doctrine/phpcr-odm": "^1.4|^2.0", - "jms/serializer": "^1.2", "behat/behat": "^3.0.6", "imbo/behat-api-extension": "^2.1", "matthiasnoback/symfony-dependency-injection-test": "^4", @@ -54,6 +53,7 @@ } }, "conflict": { + "jms/serializer": "<2.2.0", "sebastian/environment": "<1.3.4", "sebastian/exporter": "<2.0.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9a3acab..742ed32 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -20,4 +20,9 @@ + + + + + diff --git a/src/Serializer/Jms/Handler/PhpcrNodeHandler.php b/src/Serializer/Jms/Handler/PhpcrNodeHandler.php index 017dacc..3e7c517 100644 --- a/src/Serializer/Jms/Handler/PhpcrNodeHandler.php +++ b/src/Serializer/Jms/Handler/PhpcrNodeHandler.php @@ -14,7 +14,7 @@ use JMS\Serializer\Context; use JMS\Serializer\GraphNavigator; use JMS\Serializer\Handler\SubscribingHandlerInterface; -use JMS\Serializer\JsonSerializationVisitor; +use JMS\Serializer\Visitor\SerializationVisitorInterface; use PHPCR\NodeInterface; /** @@ -40,7 +40,7 @@ public static function getSubscribingMethods() * @param NodeInterface $nodeInterface */ public function serializePhpcrNode( - JsonSerializationVisitor $visitor, + SerializationVisitorInterface $visitor, NodeInterface $node, array $type, Context $context diff --git a/src/Serializer/Jms/Handler/ResourceHandler.php b/src/Serializer/Jms/Handler/ResourceHandler.php index de137b9..2ae1757 100644 --- a/src/Serializer/Jms/Handler/ResourceHandler.php +++ b/src/Serializer/Jms/Handler/ResourceHandler.php @@ -14,7 +14,7 @@ use JMS\Serializer\Context; use JMS\Serializer\GraphNavigator; use JMS\Serializer\Handler\SubscribingHandlerInterface; -use JMS\Serializer\JsonSerializationVisitor; +use JMS\Serializer\Visitor\SerializationVisitorInterface; use PHPCR\NodeInterface; use PHPCR\Util\PathHelper; use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry; @@ -70,13 +70,13 @@ public static function getSubscribingMethods() * @param NodeInterface $resourceInterface */ public function serializeResource( - JsonSerializationVisitor $visitor, + SerializationVisitorInterface $visitor, PuliResource $resource, array $type, Context $context ) { $data = $this->doSerializeResource($resource); - $context->accept($data); + $context->getNavigator()->accept($data); } public function setMaxDepth($maxDepth) diff --git a/tests/Unit/DependencyInjection/CmfResourceRestExtensionTest.php b/tests/Unit/DependencyInjection/CmfResourceRestExtensionTest.php index 5440785..a3fc5c4 100644 --- a/tests/Unit/DependencyInjection/CmfResourceRestExtensionTest.php +++ b/tests/Unit/DependencyInjection/CmfResourceRestExtensionTest.php @@ -49,15 +49,13 @@ public function testExtension($config) $this->compile(); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The JMSSerializerBundle must be registered - */ public function testNoJmsSerializerBundleRegistered() { $this->container->setParameter('kernel.bundles', []); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The JMSSerializerBundle must be registered'); + $this->load([]); - $this->compile(); } } diff --git a/tests/Unit/Serializer/Jms/Handler/PhpcrNodeHandlerTest.php b/tests/Unit/Serializer/Jms/Handler/PhpcrNodeHandlerTest.php index 7f6c3cd..2ef2756 100644 --- a/tests/Unit/Serializer/Jms/Handler/PhpcrNodeHandlerTest.php +++ b/tests/Unit/Serializer/Jms/Handler/PhpcrNodeHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Unit\Serializer\Jms\Handler; +use JMS\Serializer\Visitor\SerializationVisitorInterface; use PHPUnit\Framework\TestCase; use Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\Jms\Handler\PhpcrNodeHandler; @@ -29,7 +30,7 @@ public function setUp(): void $this->node = $this->prophesize('PHPCR\NodeInterface'); $this->property1 = $this->prophesize('PHPCR\PropertyInterface'); $this->property2 = $this->prophesize('PHPCR\PropertyInterface'); - $this->visitor = $this->prophesize('JMS\Serializer\JsonSerializationVisitor'); + $this->visitor = $this->prophesize(SerializationVisitorInterface::class); $this->context = $this->prophesize('JMS\Serializer\Context'); $this->handler = new PhpcrNodeHandler(); } diff --git a/tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php b/tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php index 93eded3..e6aae33 100644 --- a/tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php +++ b/tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php @@ -12,7 +12,8 @@ namespace Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Unit\Serializer\Jms\Handler; use JMS\Serializer\Context; -use JMS\Serializer\JsonSerializationVisitor; +use JMS\Serializer\GraphNavigatorInterface; +use JMS\Serializer\Visitor\SerializationVisitorInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry; @@ -45,16 +46,19 @@ class ResourceHandlerTest extends TestCase private $description; + private $navigator; + protected function setUp(): void { $this->repositoryRegistry = $this->prophesize(RepositoryRegistryInterface::class); $this->payloadAliasRegistry = $this->prophesize(PayloadAliasRegistry::class); - $this->visitor = $this->prophesize(JsonSerializationVisitor::class); + $this->visitor = $this->prophesize(SerializationVisitorInterface::class); $this->resource = $this->prophesize(CmfResource::class); $this->childResource = $this->prophesize(CmfResource::class); $this->repository = $this->prophesize(ResourceRepository::class); $this->context = $this->prophesize(Context::class); + $this->navigator = $this->prophesize(GraphNavigatorInterface::class); $this->description = $this->prophesize(Description::class); $this->description->all()->willReturn([]); @@ -118,7 +122,8 @@ public function testHandler() 'descriptors' => [], ]; - $this->context->accept($expected)->shouldBeCalled(); + $this->context->getNavigator()->willReturn($this->navigator); + $this->navigator->accept($expected)->willReturn($this->context); $this->handler->serializeResource( $this->visitor->reveal(),