mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 13:49:03 +03:00
Migrated CloseDbConnectionEventListenerDelegatorTest to use PHPUnit mocks
This commit is contained in:
parent
92ddd2eebe
commit
3608a6d068
1 changed files with 7 additions and 10 deletions
|
@ -4,23 +4,20 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
|
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Shlinkio\Shlink\Common\Doctrine\ReopeningEntityManagerInterface;
|
use Shlinkio\Shlink\Common\Doctrine\ReopeningEntityManagerInterface;
|
||||||
use Shlinkio\Shlink\Core\EventDispatcher\CloseDbConnectionEventListenerDelegator;
|
use Shlinkio\Shlink\Core\EventDispatcher\CloseDbConnectionEventListenerDelegator;
|
||||||
|
|
||||||
class CloseDbConnectionEventListenerDelegatorTest extends TestCase
|
class CloseDbConnectionEventListenerDelegatorTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private CloseDbConnectionEventListenerDelegator $delegator;
|
private CloseDbConnectionEventListenerDelegator $delegator;
|
||||||
private ObjectProphecy $container;
|
private MockObject $container;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->container = $this->prophesize(ContainerInterface::class);
|
$this->container = $this->createMock(ContainerInterface::class);
|
||||||
$this->delegator = new CloseDbConnectionEventListenerDelegator();
|
$this->delegator = new CloseDbConnectionEventListenerDelegator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +32,12 @@ class CloseDbConnectionEventListenerDelegatorTest extends TestCase
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
$em = $this->prophesize(ReopeningEntityManagerInterface::class);
|
$this->container->expects($this->once())->method('get')->with($this->equalTo('em'))->willReturn(
|
||||||
$getEm = $this->container->get('em')->willReturn($em->reveal());
|
$this->createMock(ReopeningEntityManagerInterface::class),
|
||||||
|
);
|
||||||
|
|
||||||
($this->delegator)($this->container->reveal(), '', $callback);
|
($this->delegator)($this->container, '', $callback);
|
||||||
|
|
||||||
self::assertTrue($callbackInvoked);
|
self::assertTrue($callbackInvoked);
|
||||||
$getEm->shouldHaveBeenCalledOnce();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue