-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
DoctrineCloseConnectionMiddlewareTest.php
69 lines (55 loc) · 2.28 KB
/
DoctrineCloseConnectionMiddlewareTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Doctrine\Tests\Messenger;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Messenger\DoctrineCloseConnectionMiddleware;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase;
class DoctrineCloseConnectionMiddlewareTest extends MiddlewareTestCase
{
private $connection;
private $entityManager;
private $managerRegistry;
private $middleware;
private $entityManagerName = 'default';
protected function setUp(): void
{
$this->connection = $this->createMock(Connection::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->entityManager->method('getConnection')->willReturn($this->connection);
$this->managerRegistry = $this->createMock(ManagerRegistry::class);
$this->managerRegistry->method('getManager')->willReturn($this->entityManager);
$this->middleware = new DoctrineCloseConnectionMiddleware(
$this->managerRegistry,
$this->entityManagerName
);
}
public function testMiddlewareCloseConnection()
{
$this->connection->expects($this->once())
->method('close')
;
$this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock());
}
public function testInvalidEntityManagerThrowsException()
{
$managerRegistry = $this->createMock(ManagerRegistry::class);
$managerRegistry
->method('getManager')
->with('unknown_manager')
->will($this->throwException(new \InvalidArgumentException()));
$middleware = new DoctrineCloseConnectionMiddleware($managerRegistry, 'unknown_manager');
$this->expectException(UnrecoverableMessageHandlingException::class);
$middleware->handle(new Envelope(new \stdClass()), $this->getStackMock(false));
}
}