|
10 | 10 | $connection = Mockery::mock(Connection::class);
|
11 | 11 |
|
12 | 12 | test()->grammar = new PostgresGrammar($connection);
|
| 13 | + test()->entity = new UserView(); |
13 | 14 | });
|
14 | 15 |
|
15 |
| -it('compiles view create', function () { |
16 |
| - $sql = test()->grammar->compileCreate(new UserView()); |
| 16 | +describe('create', function () { |
| 17 | + it('compiles view create', function () { |
| 18 | + $sql = test()->grammar->compileCreate(test()->entity); |
17 | 19 |
|
18 |
| - expect($sql)->toBe(<<<'SQL' |
19 |
| - CREATE VIEW user_view AS |
20 |
| - SELECT id, name FROM users |
21 |
| - SQL); |
| 20 | + expect($sql)->toBe(<<<'SQL' |
| 21 | + CREATE VIEW user_view AS |
| 22 | + SELECT id, name FROM users |
| 23 | + |
| 24 | + SQL); |
| 25 | + }); |
| 26 | + |
| 27 | + it('compiles recursive', function () { |
| 28 | + test()->entity->recursive = true; |
| 29 | + |
| 30 | + $sql = test()->grammar->compileCreate(test()->entity); |
| 31 | + |
| 32 | + expect($sql)->toBe(<<<SQL |
| 33 | + CREATE RECURSIVE VIEW user_view AS |
| 34 | + SELECT id, name FROM users |
| 35 | +
|
| 36 | + SQL); |
| 37 | + }); |
| 38 | + |
| 39 | + it('compiles columns', function (array $columns, string $expected) { |
| 40 | + test()->entity->columns = $columns; |
| 41 | + |
| 42 | + $sql = test()->grammar->compileCreate(test()->entity); |
| 43 | + |
| 44 | + expect($sql)->toBe(<<<SQL |
| 45 | + CREATE VIEW user_view{$expected} AS |
| 46 | + SELECT id, name FROM users |
| 47 | +
|
| 48 | + SQL); |
| 49 | + })->with([ |
| 50 | + 'one column' => [['id'], ' (id)'], |
| 51 | + 'two columns' => [['id', 'name'], ' (id, name)'], |
| 52 | + ]); |
| 53 | + |
| 54 | + it('compiles check option', function (string|bool $option, string $expected) { |
| 55 | + test()->entity->checkOption = $option; |
| 56 | + |
| 57 | + $sql = test()->grammar->compileCreate(test()->entity); |
| 58 | + |
| 59 | + expect($sql)->toBe(<<<SQL |
| 60 | + CREATE VIEW user_view AS |
| 61 | + SELECT id, name FROM users |
| 62 | + {$expected} |
| 63 | + SQL); |
| 64 | + })->with([ |
| 65 | + 'local' => ['local', 'WITH LOCAL CHECK OPTION'], |
| 66 | + 'cascaded' => ['cascaded', 'WITH CASCADED CHECK OPTION'], |
| 67 | + 'true' => [true, 'WITH CHECK OPTION'], |
| 68 | + ]); |
22 | 69 | });
|
23 | 70 |
|
24 | 71 | it('compiles view drop', function () {
|
25 |
| - $sql = test()->grammar->compileDrop(new UserView()); |
| 72 | + $sql = test()->grammar->compileDrop(test()->entity); |
26 | 73 |
|
27 | 74 | expect($sql)->toBe(<<<'SQL'
|
28 | 75 | DROP VIEW IF EXISTS user_view CASCADE
|
|
0 commit comments