|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Spatie\DbSnapshots\Commands\Test; |
4 | | - |
5 | 3 | use Carbon\Carbon; |
6 | 4 | use Illuminate\Support\Facades\Artisan; |
7 | | -use Spatie\DbSnapshots\Test\TestCase; |
8 | | - |
9 | | -class CreateTest extends TestCase |
10 | | -{ |
11 | | - /** @test */ |
12 | | - public function it_can_create_a_snapshot_without_a_specific_name() |
13 | | - { |
14 | | - Artisan::call('snapshot:create'); |
15 | 5 |
|
16 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 6 | +it('can create a snapshot without a specific', function () { |
| 7 | + Artisan::call('snapshot:create'); |
17 | 8 |
|
18 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
19 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
20 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
21 | | - } |
| 9 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
22 | 10 |
|
23 | | - /** @test */ |
24 | | - public function it_can_create_a_snapshot_with_specific_name() |
25 | | - { |
26 | | - Artisan::call('snapshot:create', ['name' => 'test']); |
| 11 | + expect($fileName) |
| 12 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/') |
| 13 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 14 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
| 15 | +}); |
27 | 16 |
|
28 | | - $this->assertFileOnDiskPassesRegex('test.sql', '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
29 | | - } |
| 17 | +it('can create a snapshot with specific name') |
| 18 | + ->tap(fn () => Artisan::call('snapshot:create', ['name' => 'test'])) |
| 19 | + ->expect('test.sql') |
| 20 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
30 | 21 |
|
31 | | - /** @test */ |
32 | | - public function it_can_create_a_compressed_snapshot_from_cli_param() |
33 | | - { |
34 | | - Artisan::call('snapshot:create', ['--compress' => true]); |
| 22 | +it('can create a compressed snapshot from CLI param', function () { |
| 23 | + Artisan::call('snapshot:create', ['--compress' => true]); |
35 | 24 |
|
36 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql.gz'; |
| 25 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql.gz'; |
37 | 26 |
|
38 | | - $this->disk->assertExists($fileName); |
| 27 | + $this->disk->assertExists($fileName); |
39 | 28 |
|
40 | | - $this->assertNotEmpty(gzdecode($this->disk->get($fileName))); |
41 | | - } |
| 29 | + expect( |
| 30 | + gzdecode($this->disk->get($fileName)) |
| 31 | + )->not->toBeEmpty(); |
| 32 | +}); |
42 | 33 |
|
43 | | - /** @test */ |
44 | | - public function it_can_create_a_compressed_snapshot_from_config() |
45 | | - { |
46 | | - $this->app['config']->set('db-snapshots.compress', true); |
| 34 | +it('can create a compressed snapshot from config', function () { |
| 35 | + $this->app['config']->set('db-snapshots.compress', true); |
47 | 36 |
|
48 | | - Artisan::call('snapshot:create'); |
| 37 | + Artisan::call('snapshot:create'); |
49 | 38 |
|
50 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql.gz'; |
| 39 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql.gz'; |
51 | 40 |
|
52 | | - $this->disk->assertExists($fileName); |
| 41 | + $this->disk->assertExists($fileName); |
53 | 42 |
|
54 | | - $this->assertNotEmpty(gzdecode($this->disk->get($fileName))); |
55 | | - } |
| 43 | + expect(gzdecode($this->disk->get($fileName)))->not->toBeEmpty(); |
| 44 | +}); |
56 | 45 |
|
57 | | - /** @test */ |
58 | | - public function it_can_create_a_snapshot_with_specific_tables_specified_in_the_command_options() |
59 | | - { |
60 | | - Artisan::call('snapshot:create', ['--table' => ['users', 'posts']]); |
| 46 | +it('can create a snapshot with specific tables specified in the command options', function () { |
| 47 | + Artisan::call('snapshot:create', ['--table' => ['users', 'posts']]); |
61 | 48 |
|
62 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 49 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
63 | 50 |
|
64 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
65 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
66 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
67 | | - } |
| 51 | + expect($fileName) |
| 52 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 53 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 54 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 55 | +}); |
68 | 56 |
|
69 | | - /** @test */ |
70 | | - public function it_can_create_a_snapshot_with_specific_tables_specified_in_the_command_options_as_a_string() |
71 | | - { |
72 | | - Artisan::call('snapshot:create', ['--table' => 'users,posts']); |
| 57 | +it('can create a snapshot with specific tables specified in the command options as a string', function () { |
| 58 | + Artisan::call('snapshot:create', ['--table' => 'users,posts']); |
73 | 59 |
|
74 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 60 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
75 | 61 |
|
76 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
77 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
78 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
79 | | - } |
| 62 | + expect($fileName) |
| 63 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 64 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 65 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 66 | +}); |
80 | 67 |
|
81 | | - /** @test */ |
82 | | - public function it_can_create_a_snapshot_with_specific_tables_specified_in_the_config() |
83 | | - { |
84 | | - $this->app['config']->set('db-snapshots.tables', ['users', 'posts']); |
| 68 | +it('can create a snapshot with specific tables specified in the config', function () { |
| 69 | + $this->app['config']->set('db-snapshots.tables', ['users', 'posts']); |
85 | 70 |
|
86 | | - Artisan::call('snapshot:create'); |
| 71 | + Artisan::call('snapshot:create'); |
87 | 72 |
|
88 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 73 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
89 | 74 |
|
90 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
91 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
92 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
93 | | - } |
| 75 | + expect($fileName) |
| 76 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 77 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 78 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 79 | +}); |
94 | 80 |
|
95 | | - /** @test */ |
96 | | - public function it_can_create_a_snapshot_without_excluded_tables_specified_in_the_command_options() |
97 | | - { |
98 | | - Artisan::call('snapshot:create', ['--exclude' => ['users', 'posts']]); |
| 81 | +it('can create a snapshot without excluded tables specified in the command options', function () { |
| 82 | + Artisan::call('snapshot:create', ['--exclude' => ['users', 'posts']]); |
99 | 83 |
|
100 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 84 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
101 | 85 |
|
102 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
103 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
104 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
105 | | - } |
| 86 | + expect($fileName) |
| 87 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 88 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 89 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 90 | +}); |
106 | 91 |
|
107 | | - /** @test */ |
108 | | - public function it_can_create_a_snapshot_without_excluded_tables_specified_in_the_command_options_as_a_string() |
109 | | - { |
110 | | - Artisan::call('snapshot:create', ['--exclude' => 'users,posts']); |
| 92 | +it('can create a snapshot without excluded tables specified in the command options as a string', function () { |
| 93 | + Artisan::call('snapshot:create', ['--exclude' => 'users,posts']); |
111 | 94 |
|
112 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 95 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
113 | 96 |
|
114 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
115 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
116 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
117 | | - } |
| 97 | + expect($fileName) |
| 98 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 99 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 100 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 101 | +}); |
118 | 102 |
|
119 | | - /** @test */ |
120 | | - public function it_can_create_a_snapshot_without_excluded_tables_specified_in_the_config() |
121 | | - { |
122 | | - $this->app['config']->set('db-snapshots.exclude', ['users', 'posts']); |
| 103 | +it('can create a snapshot without excluded tables specified in the config', function () { |
| 104 | + $this->app['config']->set('db-snapshots.exclude', ['users', 'posts']); |
123 | 105 |
|
124 | | - Artisan::call('snapshot:create'); |
| 106 | + Artisan::call('snapshot:create'); |
125 | 107 |
|
126 | | - $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
| 108 | + $fileName = Carbon::now()->format('Y-m-d_H-i-s') . '.sql'; |
127 | 109 |
|
128 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/'); |
129 | | - $this->assertFileOnDiskFailsRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/'); |
130 | | - $this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
131 | | - } |
132 | | -} |
| 110 | + expect($fileName) |
| 111 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "users"/') |
| 112 | + ->fileOnDiskToFailRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "posts"/') |
| 113 | + ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); |
| 114 | +}); |
0 commit comments