|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -namespace Spatie\ViewModels\Tests; |
4 |
| - |
5 | 3 | use Illuminate\Support\Facades\Artisan;
|
6 | 4 | use Illuminate\Support\Facades\File;
|
7 | 5 |
|
8 |
| -class ViewModelMakeCommandTest extends TestCase |
9 |
| -{ |
10 |
| - /** @test */ |
11 |
| - public function it_can_create_a_view_model() |
12 |
| - { |
13 |
| - $exitCode = Artisan::call('make:view-model', [ |
14 |
| - 'name' => 'HomeViewModel', |
15 |
| - '--force' => true, |
16 |
| - ]); |
17 |
| - |
18 |
| - $this->assertEquals(0, $exitCode); |
19 |
| - |
20 |
| - $this->assertMatchesRegularExpression('~ViewModel( \[.+\])? created successfully~', Artisan::output()); |
21 |
| - |
22 |
| - $shouldOutputFilePath = $this->app['path'].'/ViewModels/HomeViewModel.php'; |
23 |
| - |
24 |
| - $this->assertTrue(File::exists($shouldOutputFilePath), 'File exists in default app/ViewModels folder'); |
25 |
| - |
26 |
| - $contents = File::get($shouldOutputFilePath); |
| 6 | +use function PHPUnit\Framework\assertTrue; |
27 | 7 |
|
28 |
| - $this->assertStringContainsString('namespace App\ViewModels;', $contents); |
| 8 | +it('can create a view model', function () { |
| 9 | + $exitCode = Artisan::call('make:view-model', [ |
| 10 | + 'name' => 'HomeViewModel', |
| 11 | + '--force' => true, |
| 12 | + ]); |
29 | 13 |
|
30 |
| - $this->assertStringContainsString('class HomeViewModel extends ViewModel', $contents); |
31 |
| - } |
| 14 | + expect($exitCode)->toEqual(0) |
| 15 | + ->and(Artisan::output())->toMatch('~ViewModel( \[.+\])? created successfully~'); |
32 | 16 |
|
33 |
| - /** @test */ |
34 |
| - public function it_can_create_a_view_model_with_a_custom_namespace() |
35 |
| - { |
36 |
| - $exitCode = Artisan::call('make:view-model', [ |
37 |
| - 'name' => 'Blog/PostsViewModel', |
38 |
| - '--force' => true, |
39 |
| - ]); |
| 17 | + $shouldOutputFilePath = $this->app['path'] . '/ViewModels/HomeViewModel.php'; |
40 | 18 |
|
41 |
| - $this->assertEquals(0, $exitCode); |
| 19 | + assertTrue(File::exists($shouldOutputFilePath), 'File exists in default app/ViewModels folder'); |
42 | 20 |
|
43 |
| - $this->assertMatchesRegularExpression('~ViewModel( \[.+\])? created successfully~', Artisan::output()); |
| 21 | + expect(File::get($shouldOutputFilePath)) |
| 22 | + ->toContain('namespace App\ViewModels;') |
| 23 | + ->toContain('class HomeViewModel extends ViewModel'); |
| 24 | +}); |
44 | 25 |
|
45 |
| - $shouldOutputFilePath = $this->app['path'].'/ViewModels/Blog/PostsViewModel.php'; |
| 26 | +it('can create a view model with a custom namespace', function () { |
| 27 | + $exitCode = Artisan::call('make:view-model', [ |
| 28 | + 'name' => 'Blog/PostsViewModel', |
| 29 | + '--force' => true, |
| 30 | + ]); |
46 | 31 |
|
47 |
| - $this->assertTrue(File::exists($shouldOutputFilePath), 'File exists in custom app/Blog folder'); |
| 32 | + expect($exitCode)->toEqual(0) |
| 33 | + ->and(Artisan::output())->toMatch('~ViewModel( \[.+\])? created successfully~'); |
48 | 34 |
|
49 |
| - $contents = File::get($shouldOutputFilePath); |
| 35 | + $shouldOutputFilePath = $this->app['path'] . '/ViewModels/Blog/PostsViewModel.php'; |
50 | 36 |
|
51 |
| - $this->assertStringContainsString('namespace App\ViewModels\Blog;', $contents); |
| 37 | + assertTrue(File::exists($shouldOutputFilePath), 'File exists in custom app/Blog folder'); |
52 | 38 |
|
53 |
| - $this->assertStringContainsString('class PostsViewModel extends ViewModel', $contents); |
54 |
| - } |
55 |
| -} |
| 39 | + expect(File::get($shouldOutputFilePath)) |
| 40 | + ->toContain('namespace App\ViewModels\Blog;') |
| 41 | + ->toContain('class PostsViewModel extends ViewModel'); |
| 42 | +}); |
0 commit comments