@@ -56,19 +56,37 @@ public function testMiddlewareWrapsInTransactionAndFlushes()
56
56
57
57
public function testTransactionIsRolledBackOnException ()
58
58
{
59
- $ this ->connection ->expects ($ this ->once ())
60
- ->method ('beginTransaction ' )
61
- ;
62
- $ this ->connection ->expects ($ this ->once ())
63
- ->method ('rollBack ' )
64
- ;
59
+ $ this ->connection ->expects ($ this ->once ())->method ('beginTransaction ' );
60
+ $ this ->connection ->expects ($ this ->once ())->method ('isTransactionActive ' )->willReturn (true );
61
+ $ this ->connection ->expects ($ this ->once ())->method ('rollBack ' );
65
62
66
63
$ this ->expectException (\RuntimeException::class);
67
64
$ this ->expectExceptionMessage ('Thrown from next middleware. ' );
68
65
69
66
$ this ->middleware ->handle (new Envelope (new \stdClass ()), $ this ->getThrowingStackMock ());
70
67
}
71
68
69
+ public function testExceptionInRollBackDoesNotHidePreviousException ()
70
+ {
71
+ $ this ->connection ->expects ($ this ->once ())->method ('beginTransaction ' );
72
+ $ this ->connection ->expects ($ this ->once ())->method ('isTransactionActive ' )->willReturn (true );
73
+ $ this ->connection ->expects ($ this ->once ())->method ('rollBack ' )->willThrowException (new \RuntimeException ('Thrown from rollBack. ' ));
74
+
75
+ try {
76
+ $ this ->middleware ->handle (new Envelope (new \stdClass ()), $ this ->getThrowingStackMock ());
77
+ } catch (\Throwable $ exception ) {
78
+ }
79
+
80
+ self ::assertNotNull ($ exception );
81
+ self ::assertInstanceOf (\RuntimeException::class, $ exception );
82
+ self ::assertSame ('Thrown from rollBack. ' , $ exception ->getMessage ());
83
+
84
+ $ previous = $ exception ->getPrevious ();
85
+ self ::assertNotNull ($ previous );
86
+ self ::assertInstanceOf (\RuntimeException::class, $ previous );
87
+ self ::assertSame ('Thrown from next middleware. ' , $ previous ->getMessage ());
88
+ }
89
+
72
90
public function testInvalidEntityManagerThrowsException ()
73
91
{
74
92
$ managerRegistry = $ this ->createMock (ManagerRegistry::class);
0 commit comments