generated from pestphp/pest-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleUsageTest.php
75 lines (53 loc) · 1.8 KB
/
ExampleUsageTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
use JHWelch\PestLaravelMigrations\App\Models\User;
use JHWelch\PestLaravelMigrations\Tests\TestCase;
use function JHWelch\PestLaravelMigrations\migration;
use function JHWelch\PestLaravelMigrations\migrationFunctions;
uses(TestCase::class);
it('combines first_name and last_name into full_name', function () {
[$up] = migrationFunctions('2024_09_12_000000_update_users_table_combine_names');
$user = User::create([
'first_name' => 'John',
'last_name' => 'Doe',
]);
$up();
expect($user->fresh())
->full_name->toEqual('John Doe');
});
it('combines first_name and last_name into full_name and can revert', function () {
[$up, $down] = migrationFunctions('2024_09_12_000000_update_users_table_combine_names');
$user = User::create([
'first_name' => 'John',
'last_name' => 'Doe',
]);
$up();
expect($user->fresh())
->full_name->toEqual('John Doe');
$down();
expect($user->fresh())
->first_name->toEqual('John')
->last_name->toEqual('Doe');
});
// migration('2024_09_12_000000_update_users_table_combine_names', function ($up) {
// [$up] = migrationFunctions('2024_09_12_000000_update_users_table_combine_names');
// $user = User::create([
// 'first_name' => 'John',
// 'last_name' => 'Doe',
// ]);
// $up();
// expect($user->fresh())
// ->full_name->toEqual('John Doe');
// });
migration('2024_09_12_000000_update_users_table_combine_names', function ($up, $down) {
$user = User::create([
'first_name' => 'John',
'last_name' => 'Doe',
]);
$up();
expect($user->fresh())
->full_name->toEqual('John Doe');
$down();
expect($user->fresh())
->first_name->toEqual('John')
->last_name->toEqual('Doe');
});