|
14 | 14 | use Illuminate\Support\Facades\Blade; |
15 | 15 | use Illuminate\Support\Facades\Facade; |
16 | 16 | use Illuminate\Support\Facades\File; |
| 17 | +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
17 | 18 | use Symfony\Component\Finder\SplFileInfo; |
18 | 19 |
|
19 | 20 | /** |
|
23 | 24 | */ |
24 | 25 | class InteractivePublishCommandHelperTest extends UnitTestCase |
25 | 26 | { |
26 | | - |
| 27 | + use MockeryPHPUnitIntegration; |
| 28 | + protected static bool $needsKernel = true; |
| 29 | + |
| 30 | + protected Filesystem|Mockery\MockInterface $filesystem; |
| 31 | + |
| 32 | + protected \Illuminate\Contracts\Container\Container $originalApp; |
| 33 | + |
| 34 | + protected function setUp(): void |
| 35 | + { |
| 36 | + $this->filesystem = $this->mockFilesystemStrict(); |
| 37 | + |
| 38 | + File::swap($this->filesystem); |
| 39 | + Blade::partialMock()->shouldReceive('component'); |
| 40 | + |
| 41 | + $app = $this->setupMockApplication(); |
| 42 | + |
| 43 | + (new ViewServiceProvider($app))->boot(); |
| 44 | + } |
| 45 | + |
| 46 | + protected function tearDown(): void |
| 47 | + { |
| 48 | + Container::setInstance($this->originalApp); |
| 49 | + Facade::clearResolvedInstances(); |
| 50 | + } |
| 51 | + |
| 52 | + public function testGetFileChoices() |
| 53 | + { |
| 54 | + $this->filesystem->shouldReceive('allFiles')->andReturn([ |
| 55 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), '', 'app.blade.php'), |
| 56 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/page.blade.php'), '', 'page.blade.php'), |
| 57 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/post.blade.php'), '', 'post.blade.php'), |
| 58 | + ]); |
| 59 | + |
| 60 | + $helper = new InteractivePublishCommandHelper('hyde-layouts'); |
| 61 | + |
| 62 | + $this->assertSame([ |
| 63 | + 'resources/views/vendor/hyde/layouts/app.blade.php' => 'app.blade.php', |
| 64 | + 'resources/views/vendor/hyde/layouts/page.blade.php' => 'page.blade.php', |
| 65 | + 'resources/views/vendor/hyde/layouts/post.blade.php' => 'post.blade.php', |
| 66 | + ], $helper->getFileChoices()); |
| 67 | + } |
| 68 | + |
| 69 | + public function testHandle() |
| 70 | + { |
| 71 | + $this->filesystem->shouldReceive('allFiles')->andReturn([ |
| 72 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), '', 'app.blade.php'), |
| 73 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/page.blade.php'), '', 'page.blade.php'), |
| 74 | + new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/post.blade.php'), '', 'post.blade.php'), |
| 75 | + ]); |
| 76 | + |
| 77 | + $helper = new InteractivePublishCommandHelper('hyde-layouts'); |
| 78 | + |
| 79 | + $this->filesystem->shouldReceive('ensureDirectoryExists')->twice(); |
| 80 | + $this->filesystem->shouldReceive('copy')->twice(); |
| 81 | + |
| 82 | + $helper->handle([ |
| 83 | + 'resources/views/vendor/hyde/layouts/app.blade.php', |
| 84 | + 'resources/views/vendor/hyde/layouts/page.blade.php', |
| 85 | + ]); |
| 86 | + |
| 87 | + $this->filesystem->shouldHaveReceived('ensureDirectoryExists') |
| 88 | + ->with(Hyde::path('resources/views/vendor/hyde/layouts')) |
| 89 | + ->twice(); |
| 90 | + |
| 91 | + $this->filesystem->shouldHaveReceived('copy')->with( |
| 92 | + Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), |
| 93 | + Hyde::path('resources/views/vendor/hyde/layouts/app.blade.php') |
| 94 | + )->once(); |
| 95 | + |
| 96 | + $this->filesystem->shouldHaveReceived('copy')->with( |
| 97 | + Hyde::path('packages/framework/resources/views/layouts/page.blade.php'), |
| 98 | + Hyde::path('resources/views/vendor/hyde/layouts/page.blade.php') |
| 99 | + )->once(); |
| 100 | + } |
| 101 | + |
| 102 | + protected function setupMockApplication(): Container |
| 103 | + { |
| 104 | + $this->originalApp = Container::getInstance(); |
| 105 | + |
| 106 | + $app = Mockery::mock(app())->makePartial(); |
| 107 | + $app->shouldReceive('resourcePath')->andReturnUsing(fn (string $path): string => "resources/$path"); |
| 108 | + |
| 109 | + Container::setInstance($app); |
| 110 | + |
| 111 | + return $app; |
| 112 | + } |
27 | 113 | } |
0 commit comments