From 8f6c6fdad63cf36f215901def95898861d9ceaf8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 18 Feb 2021 08:11:48 -0600 Subject: [PATCH] qa: remove prophecy usage Substitute phpunit mock objects for all usage of Prophecy in unit tests. Signed-off-by: Matthew Weier O'Phinney --- composer.lock | 2 +- test/AdapterPluginManagerFactoryTest.php | 84 ++++++++++++++++-------- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/composer.lock b/composer.lock index 4e2e84c..5dd0f00 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "207222214491ec77a97fd0991622db92", + "content-hash": "0762fa37181921b4ec3a9d7b3c13e6b0", "packages": [ { "name": "laminas/laminas-json", diff --git a/test/AdapterPluginManagerFactoryTest.php b/test/AdapterPluginManagerFactoryTest.php index 79e5e3f..362b2b5 100644 --- a/test/AdapterPluginManagerFactoryTest.php +++ b/test/AdapterPluginManagerFactoryTest.php @@ -77,7 +77,7 @@ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() public function testConfiguresSerializerServicesWhenFound() { - $serializer = $this->prophesize(AdapterInterface::class)->reveal(); + $serializer = $this->createMock(AdapterInterface::class); $config = [ 'serializers' => [ 'aliases' => [ @@ -91,15 +91,24 @@ public function testConfiguresSerializerServicesWhenFound() ], ]; - $container = $this->prophesize(ServiceLocatorInterface::class); - $container->willImplement(ContainerInterface::class); + $container = $this->createMock(ContainerInterface::class); + + $container + ->expects($this->atLeast(2)) + ->method('has') + ->will($this->returnValueMap([ + ['ServiceListener', false], + ['config', true] + ])); - $container->has('ServiceListener')->willReturn(false); - $container->has('config')->willReturn(true); - $container->get('config')->willReturn($config); + $container + ->expects($this->atLeastOnce()) + ->method('get') + ->with('config') + ->willReturn($config); $factory = new AdapterPluginManagerFactory(); - $serializers = $factory($container->reveal(), 'SerializerAdapterManager'); + $serializers = $factory($container, 'SerializerAdapterManager'); $this->assertInstanceOf(AdapterPluginManager::class, $serializers); $this->assertTrue($serializers->has('test')); @@ -110,7 +119,7 @@ public function testConfiguresSerializerServicesWhenFound() public function testDoesNotConfigureSerializerServicesWhenServiceListenerPresent() { - $serializer = $this->prophesize(AdapterInterface::class)->reveal(); + $serializer = $this->createMock(AdapterInterface::class); $config = [ 'serializers' => [ 'aliases' => [ @@ -124,15 +133,21 @@ public function testDoesNotConfigureSerializerServicesWhenServiceListenerPresent ], ]; - $container = $this->prophesize(ServiceLocatorInterface::class); - $container->willImplement(ContainerInterface::class); + $container = $this->createMock(ContainerInterface::class); + + $container + ->expects($this->atLeastOnce()) + ->method('has') + ->with('ServiceListener') + ->willReturn(true); - $container->has('ServiceListener')->willReturn(true); - $container->has('config')->shouldNotBeCalled(); - $container->get('config')->shouldNotBeCalled(); + $container + ->expects($this->never()) + ->method('get') + ->with('config'); $factory = new AdapterPluginManagerFactory(); - $serializers = $factory($container->reveal(), 'SerializerAdapterManager'); + $serializers = $factory($container, 'SerializerAdapterManager'); $this->assertInstanceOf(AdapterPluginManager::class, $serializers); $this->assertFalse($serializers->has('test')); @@ -141,30 +156,47 @@ public function testDoesNotConfigureSerializerServicesWhenServiceListenerPresent public function testDoesNotConfigureSerializerServicesWhenConfigServiceNotPresent() { - $container = $this->prophesize(ServiceLocatorInterface::class); - $container->willImplement(ContainerInterface::class); + $container = $this->createMock(ContainerInterface::class); + + $container + ->expects($this->atLeast(2)) + ->method('has') + ->will($this->returnValueMap([ + ['ServiceListener', false], + ['config', false] + ])); - $container->has('ServiceListener')->willReturn(false); - $container->has('config')->willReturn(false); - $container->get('config')->shouldNotBeCalled(); + $container + ->expects($this->never()) + ->method('get') + ->with('config'); $factory = new AdapterPluginManagerFactory(); - $serializers = $factory($container->reveal(), 'SerializerAdapterManager'); + $serializers = $factory($container, 'SerializerAdapterManager'); $this->assertInstanceOf(AdapterPluginManager::class, $serializers); } public function testDoesNotConfigureSerializerServicesWhenConfigServiceDoesNotContainSerializersConfig() { - $container = $this->prophesize(ServiceLocatorInterface::class); - $container->willImplement(ContainerInterface::class); + $container = $this->createMock(ContainerInterface::class); + + $container + ->expects($this->atLeast(2)) + ->method('has') + ->will($this->returnValueMap([ + ['ServiceListener', false], + ['config', true] + ])); - $container->has('ServiceListener')->willReturn(false); - $container->has('config')->willReturn(true); - $container->get('config')->willReturn(['foo' => 'bar']); + $container + ->expects($this->atLeastOnce()) + ->method('get') + ->with('config') + ->willReturn(['foo' => 'bar']); $factory = new AdapterPluginManagerFactory(); - $serializers = $factory($container->reveal(), 'SerializerAdapterManager'); + $serializers = $factory($container, 'SerializerAdapterManager'); $this->assertInstanceOf(AdapterPluginManager::class, $serializers); $this->assertFalse($serializers->has('foo'));