Added AsyncEventListenerTest

This commit is contained in:
Alejandro Celaya 2019-07-19 21:06:34 +02:00
parent af4ee8f7ec
commit 7e8126a421
2 changed files with 42 additions and 1 deletions

View File

@ -21,7 +21,7 @@ class TaskRunnerTest extends TestCase
private $logger;
/** @var ObjectProphecy */
private $container;
/** @var ObjectProphecy */
/** @var HttpServer */
private $server;
/** @var ObjectProphecy */
private $task;

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\EventDispatcher\Listener;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\EventDispatcher\Listener\AsyncEventListener;
use Shlinkio\Shlink\EventDispatcher\Listener\EventListenerTask;
use stdClass;
use Swoole\Http\Server as HttpServer;
class AsyncEventListenerTest extends TestCase
{
/** @var AsyncEventListener */
private $eventListener;
/** @var HttpServer */
private $server;
/** @var string */
private $regularListenerName;
public function setUp(): void
{
$this->regularListenerName = 'the_regular_listener';
$this->server = $this->createMock(HttpServer::class);
$this->eventListener = new AsyncEventListener($this->server, $this->regularListenerName);
}
/** @test */
public function enqueuesTaskWhenInvoked(): void
{
$event = new stdClass();
$this->server
->expects($this->once())
->method('task')
->with(new EventListenerTask($this->regularListenerName, $event));
($this->eventListener)($event);
}
}