Skip to content

Commit

Permalink
qa: remove prophecy usage
Browse files Browse the repository at this point in the history
Substitute phpunit mock objects for all usage of Prophecy in unit tests.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
  • Loading branch information
weierophinney committed Feb 18, 2021
1 parent 58dad1a commit 8f6c6fd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 58 additions & 26 deletions test/AdapterPluginManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2()

public function testConfiguresSerializerServicesWhenFound()
{
$serializer = $this->prophesize(AdapterInterface::class)->reveal();
$serializer = $this->createMock(AdapterInterface::class);
$config = [
'serializers' => [
'aliases' => [
Expand All @@ -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'));
Expand All @@ -110,7 +119,7 @@ public function testConfiguresSerializerServicesWhenFound()

public function testDoesNotConfigureSerializerServicesWhenServiceListenerPresent()
{
$serializer = $this->prophesize(AdapterInterface::class)->reveal();
$serializer = $this->createMock(AdapterInterface::class);
$config = [
'serializers' => [
'aliases' => [
Expand All @@ -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'));
Expand All @@ -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'));
Expand Down

0 comments on commit 8f6c6fd

Please sign in to comment.