@@ -61,7 +61,7 @@ public function testExecuteWithParams() {
61
61
->with ($ this ->logicalAnd (
62
62
$ this ->isInstanceOf ('\Cake\Database\Log\LoggedQuery ' ),
63
63
$ this ->attributeEqualTo ('query ' , 'SELECT bar FROM foo ' ),
64
- $ this ->attributeEqualTo ('took ' , 5 , 5 ),
64
+ $ this ->attributeEqualTo ('took ' , 5 , 200 ),
65
65
$ this ->attributeEqualTo ('numRows ' , 4 ),
66
66
$ this ->attributeEqualTo ('params ' , ['a ' => 1 , 'b ' => 2 ])
67
67
));
@@ -85,7 +85,7 @@ public function testExecuteWithBinding() {
85
85
->with ($ this ->logicalAnd (
86
86
$ this ->isInstanceOf ('\Cake\Database\Log\LoggedQuery ' ),
87
87
$ this ->attributeEqualTo ('query ' , 'SELECT bar FROM foo ' ),
88
- $ this ->attributeEqualTo ('took ' , 5 , 5 ),
88
+ $ this ->attributeEqualTo ('took ' , 5 , 200 ),
89
89
$ this ->attributeEqualTo ('numRows ' , 4 ),
90
90
$ this ->attributeEqualTo ('params ' , ['a ' => 1 , 'b ' => '2013-01-01 ' ])
91
91
));
@@ -94,7 +94,7 @@ public function testExecuteWithBinding() {
94
94
->with ($ this ->logicalAnd (
95
95
$ this ->isInstanceOf ('\Cake\Database\Log\LoggedQuery ' ),
96
96
$ this ->attributeEqualTo ('query ' , 'SELECT bar FROM foo ' ),
97
- $ this ->attributeEqualTo ('took ' , 5 , 5 ),
97
+ $ this ->attributeEqualTo ('took ' , 5 , 200 ),
98
98
$ this ->attributeEqualTo ('numRows ' , 4 ),
99
99
$ this ->attributeEqualTo ('params ' , ['a ' => 1 , 'b ' => '2014-01-01 ' ])
100
100
));
@@ -112,4 +112,31 @@ public function testExecuteWithBinding() {
112
112
$ st ->execute ();
113
113
}
114
114
115
+ /**
116
+ * Tests that queries are logged despite database errors
117
+ *
118
+ * @expectedException \LogicException
119
+ * @expectedExceptionMessage This is bad
120
+ * @return void
121
+ */
122
+ public function testExecuteWithError () {
123
+ $ exception = new \LogicException ('This is bad ' );
124
+ $ inner = $ this ->getMock ('PDOStatement ' );
125
+ $ inner ->expects ($ this ->once ())->method ('execute ' )
126
+ ->will ($ this ->throwException ($ exception ));
127
+ $ logger = $ this ->getMock ('\Cake\Database\Log\QueryLogger ' );
128
+ $ logger ->expects ($ this ->once ())
129
+ ->method ('log ' )
130
+ ->with ($ this ->logicalAnd (
131
+ $ this ->isInstanceOf ('\Cake\Database\Log\LoggedQuery ' ),
132
+ $ this ->attributeEqualTo ('query ' , 'SELECT bar FROM foo ' ),
133
+ $ this ->attributeEqualTo ('took ' , 5 , 200 ),
134
+ $ this ->attributeEqualTo ('params ' , []),
135
+ $ this ->attributeEqualTo ('error ' , $ exception )
136
+ ));
137
+ $ st = new LoggingStatement ($ inner );
138
+ $ st ->queryString = 'SELECT bar FROM foo ' ;
139
+ $ st ->logger ($ logger );
140
+ $ st ->execute ();
141
+ }
115
142
}
0 commit comments