File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
tests/Integration/Database Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -82,11 +82,15 @@ public function fetch(BuildsQuery|Query $query): array
8282
8383 $ bindings = $ this ->resolveBindings ($ query );
8484
85- $ pdoQuery = $ this ->connection ->prepare ($ query ->toSql ());
85+ try {
86+ $ pdoQuery = $ this ->connection ->prepare ($ query ->toSql ());
8687
87- $ pdoQuery ->execute ($ bindings );
88+ $ pdoQuery ->execute ($ bindings );
8889
89- return $ pdoQuery ->fetchAll (PDO ::FETCH_NAMED );
90+ return $ pdoQuery ->fetchAll (PDO ::FETCH_NAMED );
91+ } catch (PDOException $ pdoException ) {
92+ throw new QueryWasInvalid ($ query , $ bindings , $ pdoException );
93+ }
9094 }
9195
9296 public function fetchFirst (BuildsQuery |Query $ query ): ?array
Original file line number Diff line number Diff line change 66
77use Exception ;
88use Tempest \Database \Database ;
9+ use Tempest \Database \Exceptions \QueryWasInvalid ;
910use Tempest \Database \Migrations \CreateMigrationsTable ;
1011use Tempest \Database \Query ;
1112use Tests \Tempest \Fixtures \Migrations \CreateAuthorTable ;
@@ -67,4 +68,18 @@ public function test_query_with_semicolons(): void
6768
6869 $ this ->assertSame (1 , query (Publisher::class)->count ()->execute ());
6970 }
71+
72+ public function test_query_was_invalid_exception_is_thrown_on_fetch (): void
73+ {
74+ $ this ->assertException (QueryWasInvalid::class, function () {
75+ query ('books ' )->select ()->orderBy ('title DES ' )->first ();
76+ });
77+ }
78+
79+ public function test_query_was_invalid_exception_is_thrown_on_execute (): void
80+ {
81+ $ this ->assertException (QueryWasInvalid::class, function () {
82+ query ('books ' )->update (title: 'Timeline Taxi ' )->where ('title = ? ' )->execute ();
83+ });
84+ }
7085}
You can’t perform that action at this time.
0 commit comments