File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -776,14 +776,26 @@ public function setDebugCollector(DatabaseCollector $collector) : static
776776 protected function addToDebug (Closure $ function ) : mixed
777777 {
778778 $ start = \microtime (true );
779- $ result = $ function ();
779+ try {
780+ $ result = $ function ();
781+ } catch (Exception $ exception ) {
782+ $ this ->finalizeAddToDebug ($ start );
783+ throw $ exception ;
784+ }
785+ $ this ->finalizeAddToDebug ($ start );
786+ return $ result ;
787+ }
788+
789+ protected function finalizeAddToDebug (float $ start ) : void
790+ {
780791 $ end = \microtime (true );
792+ $ rows = $ this ->mysqli ->affected_rows ;
793+ $ rows = $ rows < 0 ? $ rows . ' (failed) ' : $ rows ;
781794 $ this ->debugCollector ->addData ([
782795 'start ' => $ start ,
783796 'end ' => $ end ,
784797 'statement ' => $ this ->lastQuery (),
785- 'rows ' => $ this -> mysqli -> affected_rows ,
798+ 'rows ' => $ rows ,
786799 ]);
787- return $ result ;
788800 }
789801}
Original file line number Diff line number Diff line change @@ -120,4 +120,16 @@ protected function getHostInfo() : string
120120 self ::assertStringContainsString ('Socket: ' , $ collector ->getContents ());
121121 self ::assertStringNotContainsString ('Port: ' , $ collector ->getContents ());
122122 }
123+
124+ public function testFinalizeAddToDebug () : void
125+ {
126+ try {
127+ $ this ->makeDatabase ()->query ('Foo Bar ' );
128+ } catch (\Exception ) {
129+ }
130+ $ data = $ this ->collector ->getData ();
131+ $ data = $ data [\array_key_last ($ data )];
132+ self ::assertSame ('Foo Bar ' , $ data ['statement ' ]);
133+ self ::assertSame ('-1 (failed) ' , $ data ['rows ' ]);
134+ }
123135}
You can’t perform that action at this time.
0 commit comments