Skip to content

Commit b0c913a

Browse files
committed
wip
1 parent 53a55b0 commit b0c913a

15 files changed

+59
-31
lines changed

tests/Fixtures/Migrations/CreateAuthorTable.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66

77
use Tempest\Database\DatabaseMigration;
88
use Tempest\Database\QueryStatement;
9-
use Tempest\Database\QueryStatements\BelongsToStatement;
109
use Tempest\Database\QueryStatements\CreateTableStatement;
1110
use Tempest\Database\QueryStatements\DropTableStatement;
12-
use Tempest\Database\QueryStatements\PrimaryKeyStatement;
13-
use Tempest\Database\QueryStatements\TextStatement;
1411
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1512

1613
final class CreateAuthorTable implements DatabaseMigration
1714
{
18-
private(set) string $name = '0000-00-00_create_authors_table';
15+
private(set) string $name = '0000-00-01_create_authors_table';
1916

2017
public function up(): QueryStatement
2118
{

tests/Fixtures/Migrations/CreateBookTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
final class CreateBookTable implements DatabaseMigration
1414
{
15-
private(set) string $name = '0000-00-00_create_books_table';
15+
private(set) string $name = '0000-00-02_create_books_table';
1616

1717
public function up(): QueryStatement
1818
{

tests/Fixtures/Migrations/CreateChapterTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class CreateChapterTable implements DatabaseMigration
1515
{
16-
private(set) string $name = '0000-00-00_create_chapters_table';
16+
private(set) string $name = '0000-00-03_create_chapters_table';
1717

1818
public function up(): QueryStatement
1919
{

tests/Fixtures/Migrations/CreateIsbnTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class CreateIsbnTable implements DatabaseMigration
1515
{
16-
private(set) string $name = '0000-00-00_create_isbns_table';
16+
private(set) string $name = '0000-00-04_create_isbns_table';
1717

1818
public function up(): QueryStatement
1919
{

tests/Fixtures/Modules/Books/Models/Chapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class Chapter
1212

1313
public string $title;
1414

15-
public string $contents;
15+
public ?string $contents;
1616

1717
public Book $book;
1818
}

tests/Integration/Database/Builder/DeleteQueryBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Tempest\Database\Id;
77
use Tempest\Database\Migrations\CreateMigrationsTable;
88
use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable;
9+
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
910
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1011
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
1112

@@ -102,7 +103,7 @@ public function test_delete_on_plain_table_with_conditions(): void
102103

103104
public function test_delete_with_non_object_model(): void
104105
{
105-
$this->migrate(CreateMigrationsTable::class, CreateAuthorTable::class);
106+
$this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
106107

107108
query('authors')->insert(
108109
['id' => 1, 'name' => 'Brent'],

tests/Integration/Database/Builder/InsertQueryBuilderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable;
1111
use Tests\Tempest\Fixtures\Migrations\CreateBookTable;
1212
use Tests\Tempest\Fixtures\Migrations\CreateChapterTable;
13+
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
1314
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1415
use Tests\Tempest\Fixtures\Modules\Books\Models\AuthorType;
1516
use Tests\Tempest\Fixtures\Modules\Books\Models\Book;
@@ -183,7 +184,7 @@ public function test_inserting_has_one_via_parent_model_throws_exception(): void
183184

184185
public function test_then_method(): void
185186
{
186-
$this->migrate(CreateMigrationsTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class);
187+
$this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class);
187188

188189
$id = query(Book::class)
189190
->insert(title: 'Timeline Taxi')
@@ -208,7 +209,7 @@ public function test_then_method(): void
208209

209210
public function test_insert_with_non_object_model(): void
210211
{
211-
$this->migrate(CreateMigrationsTable::class, CreateAuthorTable::class);
212+
$this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
212213

213214
query('authors')->insert(
214215
['id' => 1, 'name' => 'Brent'],

tests/Integration/Database/Builder/SelectQueryBuilderTest.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Tests\Tempest\Fixtures\Migrations\CreateBookTable;
1111
use Tests\Tempest\Fixtures\Migrations\CreateChapterTable;
1212
use Tests\Tempest\Fixtures\Migrations\CreateIsbnTable;
13+
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
1314
use Tests\Tempest\Fixtures\Models\AWithEager;
1415
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1516
use 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
}

tests/Integration/Database/Builder/UpdateQueryBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Tempest\Database\Migrations\CreateMigrationsTable;
1212
use Tempest\Database\Query;
1313
use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable;
14+
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
1415
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1516
use Tests\Tempest\Fixtures\Modules\Books\Models\AuthorType;
1617
use Tests\Tempest\Fixtures\Modules\Books\Models\Book;
@@ -265,7 +266,7 @@ public function test_update_on_plain_table_with_conditions(): void
265266

266267
public function test_update_with_non_object_model(): void
267268
{
268-
$this->migrate(CreateMigrationsTable::class, CreateAuthorTable::class);
269+
$this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
269270

270271
query('authors')->insert(
271272
['id' => 1, 'name' => 'Brent'],

tests/Integration/Database/GenericDatabaseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Tempest\Database\Migrations\CreateMigrationsTable;
1010
use Tempest\Database\Migrations\Migration;
1111
use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable;
12+
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
1213
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1314
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
1415

@@ -33,7 +34,7 @@ public function test_execute_with_fail_works_correctly(): void
3334
{
3435
$database = $this->container->get(Database::class);
3536

36-
$this->migrate(CreateMigrationsTable::class, CreateAuthorTable::class);
37+
$this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class);
3738

3839
$database->withinTransaction(function (): never {
3940
new Author(name: 'test')->save();

0 commit comments

Comments
 (0)