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; 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();
} }
} }