Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 22, 2024
1 parent 797828e commit 9f7a2e7
Showing 1 changed file with 1 addition and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,91 +23,5 @@
*/
class InteractivePublishCommandHelperTest extends UnitTestCase
{
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
{
$this->verifyMockeryExpectations();

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 9f7a2e7

Please sign in to comment.