Migrated CloseDbConnectionEventListenerDelegatorTest to use PHPUnit mocks

This commit is contained in:
Alejandro Celaya 2022-10-22 07:28:15 +02:00
parent 92ddd2eebe
commit 3608a6d068

View file

@ -4,23 +4,20 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Shlinkio\Shlink\Common\Doctrine\ReopeningEntityManagerInterface;
use Shlinkio\Shlink\Core\EventDispatcher\CloseDbConnectionEventListenerDelegator;
class CloseDbConnectionEventListenerDelegatorTest extends TestCase
{
use ProphecyTrait;
private CloseDbConnectionEventListenerDelegator $delegator;
private ObjectProphecy $container;
private MockObject $container;
protected function setUp(): void
{
$this->container = $this->prophesize(ContainerInterface::class);
$this->container = $this->createMock(ContainerInterface::class);
$this->delegator = new CloseDbConnectionEventListenerDelegator();
}
@ -35,12 +32,12 @@ class CloseDbConnectionEventListenerDelegatorTest extends TestCase
};
};
$em = $this->prophesize(ReopeningEntityManagerInterface::class);
$getEm = $this->container->get('em')->willReturn($em->reveal());
$this->container->expects($this->once())->method('get')->with($this->equalTo('em'))->willReturn(
$this->createMock(ReopeningEntityManagerInterface::class),
);
($this->delegator)($this->container->reveal(), '', $callback);
($this->delegator)($this->container, '', $callback);
self::assertTrue($callbackInvoked);
$getEm->shouldHaveBeenCalledOnce();
}
}