@@ -154,33 +154,37 @@ public function testExecuteRunsInvalidQuery()
154
154
$ this ->
query ->
execute (
'foo ' ,
'[email protected] ' ,
'US ' );
155
155
}
156
156
157
- public function testDeallocatePreparedQuery ()
157
+ public function testDeallocatePreparedQueryThenTryToExecute ()
158
158
{
159
159
$ this ->query = $ this ->db ->prepare (static fn ($ db ) => $ db ->table ('user ' )->insert ([
160
160
'name ' => 'a ' ,
161
161
162
162
'country ' => 'x ' ,
163
163
]));
164
164
165
- $ this ->
query ->
execute (
'foo ' ,
'[email protected] ' ,
'US ' );
166
-
167
165
$ this ->query ->close ();
168
166
169
167
// Try to execute a non-existing prepared statement
170
- try {
171
- $ this ->
query ->
execute (
'bar ' ,
'[email protected] ' ,
'GB ' );
172
- } catch (BadMethodCallException $ e ) {
173
- $ this ->assertSame ('You must call prepare before trying to execute a prepared statement. ' , $ e ->getMessage ());
174
- }
168
+ $ this ->expectException (BadMethodCallException::class);
169
+ $ this ->expectExceptionMessage ('You must call prepare before trying to execute a prepared statement. ' );
170
+
171
+ $ this ->
query ->
execute (
'bar ' ,
'[email protected] ' ,
'GB ' );
172
+ }
173
+
174
+ public function testDeallocatePreparedQueryThenTryToClose ()
175
+ {
176
+ $ this ->query = $ this ->db ->prepare (static fn ($ db ) => $ db ->table ('user ' )->insert ([
177
+ 'name ' => 'a ' ,
178
+
179
+ 'country ' => 'x ' ,
180
+ ]));
181
+
182
+ $ this ->query ->close ();
175
183
176
184
// Try to close a non-existing prepared statement
177
- try {
178
- $ this ->query ->close ();
179
- } catch (BadMethodCallException $ e ) {
180
- $ this ->assertSame ('Cannot call close on a non-existing prepared statement. ' , $ e ->getMessage ());
181
- }
185
+ $ this ->expectException (BadMethodCallException::class);
186
+ $ this ->expectExceptionMessage ('Cannot call close on a non-existing prepared statement. ' );
182
187
183
- $ this ->
seeInDatabase (
$ this ->
db ->
DBPrefix .
'user ' , [
'name ' =>
'foo ' ,
'email ' =>
'[email protected] ' ]);
184
- $ this ->
dontSeeInDatabase (
$ this ->
db ->
DBPrefix .
'user ' , [
'name ' =>
'bar ' ,
'email ' =>
'[email protected] ' ]);
188
+ $ this ->query ->close ();
185
189
}
186
190
}
0 commit comments