mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-26 00:41:35 -06:00
Created more tests
This commit is contained in:
parent
bc99ee6ebe
commit
37e286df48
@ -0,0 +1,46 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
48
module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php
Normal file
48
module/EventDispatcher/test/Async/TaskRunnerFactoryTest.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\EventDispatcher\Async;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\EventDispatcher\Async\TaskRunner;
|
||||
use Shlinkio\Shlink\EventDispatcher\Async\TaskRunnerFactory;
|
||||
|
||||
class TaskRunnerFactoryTest extends TestCase
|
||||
{
|
||||
/** @var TaskRunnerFactory */
|
||||
private $factory;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user