Skip to content

Commit

Permalink
Update InteractivePublishCommandHelperTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 22, 2024
1 parent 9f7a2e7 commit c0013d8
Showing 1 changed file with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\File;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Symfony\Component\Finder\SplFileInfo;

/**
Expand All @@ -23,5 +24,90 @@
*/
class InteractivePublishCommandHelperTest extends UnitTestCase
{

use MockeryPHPUnitIntegration;
protected static bool $needsKernel = true;

protected Filesystem|Mockery\MockInterface $filesystem;

protected \Illuminate\Contracts\Container\Container $originalApp;

protected function setUp(): void
{
$this->filesystem = $this->mockFilesystemStrict();

File::swap($this->filesystem);
Blade::partialMock()->shouldReceive('component');

$app = $this->setupMockApplication();

(new ViewServiceProvider($app))->boot();
}

protected function tearDown(): void
{
Container::setInstance($this->originalApp);
Facade::clearResolvedInstances();
}

public function testGetFileChoices()
{
$this->filesystem->shouldReceive('allFiles')->andReturn([
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), '', 'app.blade.php'),
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/page.blade.php'), '', 'page.blade.php'),
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/post.blade.php'), '', 'post.blade.php'),
]);

$helper = new InteractivePublishCommandHelper('hyde-layouts');

$this->assertSame([
'resources/views/vendor/hyde/layouts/app.blade.php' => 'app.blade.php',
'resources/views/vendor/hyde/layouts/page.blade.php' => 'page.blade.php',
'resources/views/vendor/hyde/layouts/post.blade.php' => 'post.blade.php',
], $helper->getFileChoices());
}

public function testHandle()
{
$this->filesystem->shouldReceive('allFiles')->andReturn([
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), '', 'app.blade.php'),
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/page.blade.php'), '', 'page.blade.php'),
new SplFileInfo(Hyde::path('packages/framework/resources/views/layouts/post.blade.php'), '', 'post.blade.php'),
]);

$helper = new InteractivePublishCommandHelper('hyde-layouts');

$this->filesystem->shouldReceive('ensureDirectoryExists')->twice();
$this->filesystem->shouldReceive('copy')->twice();

$helper->handle([
'resources/views/vendor/hyde/layouts/app.blade.php',
'resources/views/vendor/hyde/layouts/page.blade.php',
]);

$this->filesystem->shouldHaveReceived('ensureDirectoryExists')
->with(Hyde::path('resources/views/vendor/hyde/layouts'))
->twice();

$this->filesystem->shouldHaveReceived('copy')->with(
Hyde::path('packages/framework/resources/views/layouts/app.blade.php'),
Hyde::path('resources/views/vendor/hyde/layouts/app.blade.php')
)->once();

$this->filesystem->shouldHaveReceived('copy')->with(
Hyde::path('packages/framework/resources/views/layouts/page.blade.php'),
Hyde::path('resources/views/vendor/hyde/layouts/page.blade.php')
)->once();
}

protected function setupMockApplication(): Container
{
$this->originalApp = Container::getInstance();

$app = Mockery::mock(app())->makePartial();
$app->shouldReceive('resourcePath')->andReturnUsing(fn (string $path): string => "resources/$path");

Container::setInstance($app);

return $app;
}
}

0 comments on commit c0013d8

Please sign in to comment.