shlink/module/EventDispatcher/test/Async/TaskRunnerDelegatorTest.php
2019-07-20 10:47:12 +02:00

46 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\EventDispatcher\Async;
use Interop\Container\ContainerInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\EventDispatcher\Async\TaskRunner;
use Shlinkio\Shlink\EventDispatcher\Async\TaskRunnerDelegator;
use Swoole\Http\Server as HttpServer;
class TaskRunnerDelegatorTest extends TestCase
{
/** @var TaskRunnerDelegator */
private $delegator;
public function setUp(): void
{
$this->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();
}
}