From 37e286df48aeb6306482780b93270898c0bf81e2 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 20 Jul 2019 10:47:12 +0200 Subject: [PATCH] Created more tests --- .../test/Async/TaskRunnerDelegatorTest.php | 46 ++++++++++++++++++ .../test/Async/TaskRunnerFactoryTest.php | 48 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 module/EventDispatcher/test/Async/TaskRunnerDelegatorTest.php create mode 100644 module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php diff --git a/module/EventDispatcher/test/Async/TaskRunnerDelegatorTest.php b/module/EventDispatcher/test/Async/TaskRunnerDelegatorTest.php new file mode 100644 index 00000000..82c6b280 --- /dev/null +++ b/module/EventDispatcher/test/Async/TaskRunnerDelegatorTest.php @@ -0,0 +1,46 @@ +delegator = new TaskRunnerDelegator(); + } + + /** @test */ + public function serverIsFetchedFromCallbackAndDecorated(): void + { + $server = $this->createMock(HttpServer::class); + $server + ->expects($this->exactly(2)) + ->method('on'); + $callback = function () use ($server) { + return $server; + }; + + $container = $this->prophesize(ContainerInterface::class); + $getTaskRunner = $container->get(TaskRunner::class)->willReturn($this->prophesize(TaskRunner::class)->reveal()); + $getLogger = $container->get(LoggerInterface::class)->willReturn( + $this->prophesize(LoggerInterface::class)->reveal() + ); + + $result = ($this->delegator)($container->reveal(), '', $callback); + + $this->assertSame($server, $result); + $getTaskRunner->shouldHaveBeenCalledOnce(); + $getLogger->shouldHaveBeenCalledOnce(); + } +} diff --git a/module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php b/module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php new file mode 100644 index 00000000..418abe29 --- /dev/null +++ b/module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php @@ -0,0 +1,48 @@ +factory = new TaskRunnerFactory(); + } + + /** @test */ + public function properlyCreatesService(): void + { + $loggerMock = $this->prophesize(LoggerInterface::class); + $logger = $loggerMock->reveal(); + $containerMock = $this->prophesize(ContainerInterface::class); + $getLogger = $containerMock->get(LoggerInterface::class)->willReturn($logger); + $container = $containerMock->reveal(); + + $taskRunner = ($this->factory)($container, ''); + $loggerProp = $this->getPropertyFromTaskRunner($taskRunner, 'logger'); + $containerProp = $this->getPropertyFromTaskRunner($taskRunner, 'container'); + + $this->assertSame($container, $containerProp); + $this->assertSame($logger, $loggerProp); + $getLogger->shouldHaveBeenCalledOnce(); + } + + private function getPropertyFromTaskRunner(TaskRunner $taskRunner, string $propertyName) + { + $ref = new ReflectionObject($taskRunner); + $prop = $ref->getProperty($propertyName); + $prop->setAccessible(true); + return $prop->getValue($taskRunner); + } +}