Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit378ca06

Browse files
committed
Fix DoctrineTransactionMiddleware after MiddlewareInterface bc-break
1 parent031762e commit378ca06

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

‎src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(ManagerRegistry $managerRegistry, ?string $entityMan
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
publicfunctionhandle(Envelope$envelope,StackInterface$stack):void
39+
publicfunctionhandle(Envelope$envelope,StackInterface$stack):Envelope
4040
{
4141
$entityManager =$this->managerRegistry->getManager($this->entityManagerName);
4242

@@ -46,9 +46,11 @@ public function handle(Envelope $envelope, StackInterface $stack): void
4646

4747
$entityManager->getConnection()->beginTransaction();
4848
try {
49-
$stack->next()->handle($envelope,$stack);
49+
$envelope =$stack->next()->handle($envelope,$stack);
5050
$entityManager->flush();
5151
$entityManager->getConnection()->commit();
52+
53+
return$envelope;
5254
}catch (\Throwable$exception) {
5355
$entityManager->getConnection()->rollBack();
5456

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespaceSymfony\Bridge\Doctrine\Tests\Fixtures\Messenger;
4+
5+
useSymfony\Component\Messenger\Envelope;
6+
useSymfony\Component\Messenger\Middleware\MiddlewareInterface;
7+
useSymfony\Component\Messenger\Middleware\StackInterface;
8+
9+
class DummyMiddlewareimplements MiddlewareInterface
10+
{
11+
publicfunctionhandle(Envelope$envelope,StackInterface$stack):Envelope
12+
{
13+
return$envelope;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespaceSymfony\Bridge\Doctrine\Tests\Fixtures\Messenger;
4+
5+
useSymfony\Component\Messenger\Envelope;
6+
useSymfony\Component\Messenger\Middleware\MiddlewareInterface;
7+
useSymfony\Component\Messenger\Middleware\StackInterface;
8+
9+
class ThrowingMiddlewareimplements MiddlewareInterface
10+
{
11+
publicfunctionhandle(Envelope$envelope,StackInterface$stack):Envelope
12+
{
13+
thrownew \RuntimeException('Thrown from middleware.');
14+
}
15+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\Doctrine\Tests\Messenger;
13+
14+
useDoctrine\Common\Persistence\ManagerRegistry;
15+
useDoctrine\DBAL\Connection;
16+
useDoctrine\ORM\EntityManagerInterface;
17+
usePHPUnit\Framework\TestCase;
18+
useSymfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
19+
useSymfony\Bridge\Doctrine\Tests\Fixtures\Messenger\DummyMiddleware;
20+
useSymfony\Bridge\Doctrine\Tests\Fixtures\Messenger\ThrowingMiddleware;
21+
useSymfony\Component\Messenger\Envelope;
22+
useSymfony\Component\Messenger\Middleware\StackInterface;
23+
24+
class DoctrineTransactionMiddlewareTestextends TestCase
25+
{
26+
private$connection;
27+
private$entityManager;
28+
private$middleware;
29+
private$stack;
30+
31+
publicfunctionsetUp()
32+
{
33+
$this->connection =$this->createMock(Connection::class);
34+
35+
$this->entityManager =$this->createMock(EntityManagerInterface::class);
36+
$this->entityManager->method('getConnection')->willReturn($this->connection);
37+
38+
$managerRegistry =$this->createMock(ManagerRegistry::class);
39+
$managerRegistry->method('getManager')->willReturn($this->entityManager);
40+
41+
$this->middleware =newDoctrineTransactionMiddleware($managerRegistry,null);
42+
43+
$this->stack =$this->createMock(StackInterface::class);
44+
}
45+
46+
publicfunctiontestMiddlewareWrapsInTransactionAndFlushes()
47+
{
48+
$this->connection->expects($this->once())
49+
->method('beginTransaction')
50+
;
51+
$this->connection->expects($this->once())
52+
->method('commit')
53+
;
54+
$this->entityManager->expects($this->once())
55+
->method('flush')
56+
;
57+
$this->stack
58+
->expects($this->once())
59+
->method('next')
60+
->willReturn(newDummyMiddleware())
61+
;
62+
63+
$this->middleware->handle(newEnvelope(new \stdClass()),$this->stack);
64+
}
65+
66+
publicfunctiontestTransactionIsRolledBackOnException()
67+
{
68+
$this->connection->expects($this->once())
69+
->method('beginTransaction')
70+
;
71+
$this->connection->expects($this->once())
72+
->method('rollBack')
73+
;
74+
$this->stack
75+
->expects($this->once())
76+
->method('next')
77+
->willReturn(newThrowingMiddleware())
78+
;
79+
$this->expectException(\RuntimeException::class);
80+
$this->expectExceptionMessage('Thrown from middleware.');
81+
82+
$this->middleware->handle(newEnvelope(new \stdClass()),$this->stack);
83+
}
84+
}

‎src/Symfony/Bridge/Doctrine/composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"symfony/dependency-injection":"~3.4|~4.0",
3030
"symfony/form":"~3.4|~4.0",
3131
"symfony/http-kernel":"~3.4|~4.0",
32+
"symfony/messenger":"~4.2",
3233
"symfony/property-access":"~3.4|~4.0",
3334
"symfony/property-info":"~3.4|~4.0",
3435
"symfony/proxy-manager-bridge":"~3.4|~4.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp