@@ -123,6 +123,36 @@ public function testTransactionLevelNotIncrementedOnTransactionException()
123
123
}
124
124
}
125
125
126
+ public function testBeginTransactionMethodRetriesOnFailure ()
127
+ {
128
+ $ pdo = $ this ->getMock ('DatabaseConnectionTestMockPDO ' );
129
+ $ pdo ->expects ($ this ->exactly (2 ))->method ('beginTransaction ' );
130
+ $ pdo ->expects ($ this ->at (0 ))->method ('beginTransaction ' )->will ($ this ->throwException (new ErrorException ('server has gone away ' )));
131
+ $ connection = $ this ->getMockConnection (['reconnect ' ], $ pdo );
132
+ $ connection ->expects ($ this ->once ())->method ('reconnect ' );
133
+ $ connection ->beginTransaction ();
134
+ $ this ->assertEquals (1 , $ connection ->transactionLevel ());
135
+ }
136
+
137
+ public function testBeginTransactionMethodNeverRetriesIfWithinTransaction ()
138
+ {
139
+ $ pdo = $ this ->getMock ('DatabaseConnectionTestMockPDO ' );
140
+ $ pdo ->expects ($ this ->once ())->method ('beginTransaction ' );
141
+ $ pdo ->expects ($ this ->once ())->method ('exec ' )->will ($ this ->throwException (new Exception ));
142
+ $ connection = $ this ->getMockConnection ([], $ pdo );
143
+ $ queryGrammar = $ this ->getMock ('Illuminate\Database\Query\Grammars\Grammar ' );
144
+ $ queryGrammar ->expects ($ this ->once ())->method ('supportsSavepoints ' )->will ($ this ->returnValue (true ));
145
+ $ connection ->setQueryGrammar ($ queryGrammar );
146
+ $ connection ->expects ($ this ->never ())->method ('reconnect ' );
147
+ $ connection ->beginTransaction ();
148
+ $ this ->assertEquals (1 , $ connection ->transactionLeve
7D7D
l ());
149
+ try {
150
+ $ connection ->beginTransaction ();
151
+ } catch (Exception $ e ) {
152
+ $ this ->assertEquals (1 , $ connection ->transactionLevel ());
153
+ }
154
+ }
155
+
126
156
/**
127
157
* @expectedException RuntimeException
128
158
*/
0 commit comments