1010use Tests \Tempest \Fixtures \Migrations \CreateBookTable ;
1111use Tests \Tempest \Fixtures \Migrations \CreateChapterTable ;
1212use Tests \Tempest \Fixtures \Migrations \CreateIsbnTable ;
13+ use Tests \Tempest \Fixtures \Migrations \CreatePublishersTable ;
1314use Tests \Tempest \Fixtures \Models \AWithEager ;
1415use Tests \Tempest \Fixtures \Modules \Books \Models \Author ;
1516use Tests \Tempest \Fixtures \Modules \Books \Models \AuthorType ;
@@ -35,17 +36,17 @@ public function test_select_query(): void
3536
3637 $ expected = <<<SQL
3738 SELECT title, index
38- FROM ` chapters`
39- WHERE ` title` = ?
40- AND ` index` <> ?
41- OR ` createdAt` > ?
42- ORDER BY ` index` ASC
39+ FROM chapters
40+ WHERE title = ?
41+ AND index <> ?
42+ OR createdAt > ?
43+ ORDER BY index ASC
4344 SQL ;
4445
4546 $ sql = $ query ->toSql ();
4647 $ bindings = $ query ->bindings ;
4748
48- $ this ->assertSame ($ expected , $ sql );
49+ $ this ->assertSameWithoutBackticks ($ expected , $ sql );
4950 $ this ->assertSame (['Timeline Taxi ' , '1 ' , '2025-01-01 ' ], $ bindings );
5051 }
5152
@@ -60,7 +61,7 @@ public function test_select_without_any_fields_specified(): void
6061 FROM `chapters`
6162 SQL ;
6263
63- $ this ->assertSame ($ expected , $ sql );
64+ $ this ->assertSameWithoutBackticks ($ expected , $ sql );
6465 }
6566
6667 public function test_select_from_model (): void
@@ -74,13 +75,14 @@ public function test_select_from_model(): void
7475 FROM `authors`
7576 SQL ;
7677
77- $ this ->assertSame ($ expected , $ sql );
78+ $ this ->assertSameWithoutBackticks ($ expected , $ sql );
7879 }
7980
8081 public function test_where_statement (): void
8182 {
8283 $ this ->migrate (
8384 CreateMigrationsTable::class,
85+ CreatePublishersTable::class,
8486 CreateAuthorTable::class,
8587 CreateBookTable::class,
8688 );
@@ -99,6 +101,7 @@ public function test_join(): void
99101 {
100102 $ this ->migrate (
101103 CreateMigrationsTable::class,
104+ CreatePublishersTable::class,
102105 CreateAuthorTable::class,
103106 CreateBookTable::class,
104107 );
@@ -121,6 +124,7 @@ public function test_order_by(): void
121124 {
122125 $ this ->migrate (
123126 CreateMigrationsTable::class,
127+ CreatePublishersTable::class,
124128 CreateAuthorTable::class,
125129 CreateBookTable::class,
126130 );
@@ -139,6 +143,7 @@ public function test_limit(): void
139143 {
140144 $ this ->migrate (
141145 CreateMigrationsTable::class,
146+ CreatePublishersTable::class,
142147 CreateAuthorTable::class,
143148 CreateBookTable::class,
144149 );
@@ -159,6 +164,7 @@ public function test_offset(): void
159164 {
160165 $ this ->migrate (
161166 CreateMigrationsTable::class,
167+ CreatePublishersTable::class,
162168 CreateAuthorTable::class,
163169 CreateBookTable::class,
164170 );
@@ -182,6 +188,7 @@ public function test_chunk(): void
182188 {
183189 $ this ->migrate (
184190 CreateMigrationsTable::class,
191+ CreatePublishersTable::class,
185192 CreateAuthorTable::class,
186193 CreateBookTable::class,
187194 );
@@ -208,6 +215,7 @@ public function test_raw(): void
208215 {
209216 $ this ->migrate (
210217 CreateMigrationsTable::class,
218+ CreatePublishersTable::class,
211219 CreateAuthorTable::class,
212220 CreateBookTable::class,
213221 );
@@ -253,13 +261,13 @@ public function test_select_query_with_conditions(): void
253261 $ sql = $ query ->toSql ();
254262 $ bindings = $ query ->bindings ;
255263
256- $ this ->assertSame ($ expected , $ sql );
264+ $ this ->assertSameWithoutBackticks ($ expected , $ sql );
257265 $ this ->assertSame (['Timeline Taxi ' , '1 ' , '2025-01-01 ' ], $ bindings );
258266 }
259267
260268 public function test_select_first_with_non_object_model (): void
261269 {
262- $ this ->migrate (CreateMigrationsTable::class, CreateAuthorTable::class);
270+ $ this ->migrate (CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
263271
264272 query ('authors ' )->insert (
265273 ['id ' => 1 , 'name ' => 'Brent ' ],
@@ -276,7 +284,7 @@ public function test_select_first_with_non_object_model(): void
276284
277285 public function test_select_all_with_non_object_model (): void
278286 {
279- $ this ->migrate (CreateMigrationsTable::class, CreateAuthorTable::class);
287+ $ this ->migrate (CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
280288
281289 query ('authors ' )->insert (
282290 ['id ' => 1 , 'name ' => 'Brent ' , 'type ' => AuthorType::B],
@@ -299,7 +307,7 @@ public function test_select_includes_belongs_to(): void
299307 {
300308 $ query = query (Book::class)->select ();
301309
302- $ this ->assertSame (<<<SQL
310+ $ this ->assertSameWithoutBackticks (<<<SQL
303311 SELECT books.title AS `books.title`, books.author_id AS `books.author_id`, books.id AS `books.id`
304312 FROM `books`
305313 SQL , $ query ->build ()->toSql ());
@@ -312,7 +320,7 @@ public function test_with_belongs_to_relation(): void
312320 ->with ('author ' , 'chapters ' , 'isbn ' )
313321 ->build ();
314322
315- $ this ->assertSame (<<<SQL
323+ $ this ->assertSameWithoutBackticks (<<<SQL
316324 SELECT books.title AS `books.title`, books.author_id AS `books.author_id`, books.id AS `books.id`, authors.name AS `author.name`, authors.type AS `author.type`, authors.publisher_id AS `author.publisher_id`, authors.id AS `author.id`, chapters.title AS `chapters.title`, chapters.contents AS `chapters.contents`, chapters.book_id AS `chapters.book_id`, chapters.id AS `chapters.id`, isbns.value AS `isbn.value`, isbns.book_id AS `isbn.book_id`, isbns.id AS `isbn.id`
317325 FROM `books`
318326 LEFT JOIN authors ON authors.id = books.author_id
@@ -351,7 +359,7 @@ public function test_eager_loads_combined_with_manual_loads(): void
351359 {
352360 $ query = AWithEager::select ()->with ('b.c ' )->toSql ();
353361
354- $ this ->assertSame (<<<SQL
362+ $ this ->assertSameWithoutBackticks (<<<SQL
355363 SELECT a.b_id AS `a.b_id`, a.id AS `a.id`, b.c_id AS `b.c_id`, b.id AS `b.id`, c.name AS `b.c.name`, c.id AS `b.c.id`
356364 FROM `a`
357365 LEFT JOIN b ON b.id = a.b_id
@@ -363,6 +371,7 @@ private function seed(): void
363371 {
364372 $ this ->migrate (
365373 CreateMigrationsTable::class,
374+ CreatePublishersTable::class,
366375 CreateAuthorTable::class,
367376 CreateBookTable::class,
368377 CreateChapterTable::class,
@@ -404,4 +413,12 @@ private function seed(): void
404413 ['title ' => 'Timeline Taxi Chapter 4 ' , 'book_id ' => 4 ],
405414 )->execute ();
406415 }
416+
417+ private function assertSameWithoutBackticks (string $ expected , string $ actual ): void
418+ {
419+ $ this ->assertSame (
420+ str_replace ('` ' , '' , $ expected ),
421+ str_replace ('` ' , '' , $ actual ),
422+ );
423+ }
407424}
0 commit comments