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); + } +}