Skip to content

Commit 8ab499e

Browse files
committed
Cleanup code and use real app
1 parent 0651fef commit 8ab499e

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function findAllFilesForTag(): array
7171
}
7272

7373
/**
74-
* @param \Symfony\Component\Finder\SplFileInfo[] $search
74+
* @param \Symfony\Component\Finder\SplFileInfo[] $search
7575
* @return array<string, string>
7676
*/
7777
protected function mapPublishableFiles(array $search): array

packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
namespace Hyde\Framework\Testing\Unit;
66

7-
use Hyde\Console\Helpers\InteractivePublishCommandHelper;
8-
use Hyde\Foundation\Providers\ViewServiceProvider;
7+
use Hyde\Testing\CreatesApplication;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Mockery;
910
use Hyde\Hyde;
1011
use Hyde\Testing\UnitTestCase;
12+
use Hyde\Foundation\Providers\ViewServiceProvider;
13+
use Hyde\Console\Helpers\InteractivePublishCommandHelper;
1114
use Illuminate\Container\Container;
1215
use Illuminate\Support\Facades\Blade;
1316
use Illuminate\Support\Facades\Facade;
1417
use Illuminate\Support\Facades\File;
15-
use Mockery;
1618
use Symfony\Component\Finder\SplFileInfo;
1719

1820
/**
@@ -22,30 +24,30 @@
2224
*/
2325
class InteractivePublishCommandHelperTest extends UnitTestCase
2426
{
25-
protected static bool $needsKernel = true;
27+
use CreatesApplication;
2628

27-
/** @var \Illuminate\Filesystem\Filesystem&\Mockery\MockInterface */
28-
protected $filesystem;
29+
protected static bool $needsKernel = true;
2930

30-
protected $originalApp;
31+
protected Filesystem|Mockery\MockInterface $filesystem;
3132

3233
protected function setUp(): void
3334
{
35+
$app = $this->createApplication();
36+
Container::setInstance($app);
37+
3438
$this->filesystem = $this->mockFilesystemStrict();
3539

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

39-
$app = $this->setupMockApplication();
40-
4143
(new ViewServiceProvider($app))->boot();
4244
}
4345

4446
protected function tearDown(): void
4547
{
4648
$this->verifyMockeryExpectations();
4749

48-
Container::setInstance($this->originalApp);
50+
Container::setInstance();
4951
Facade::clearResolvedInstances();
5052
}
5153

@@ -80,8 +82,8 @@ public function testHandle()
8082
$this->filesystem->shouldReceive('copy')->twice();
8183

8284
$helper->handle([
83-
"resources/views/vendor/hyde/layouts/app.blade.php",
84-
"resources/views/vendor/hyde/layouts/page.blade.php",
85+
'resources/views/vendor/hyde/layouts/app.blade.php',
86+
'resources/views/vendor/hyde/layouts/page.blade.php',
8587
]);
8688

8789
$this->filesystem->shouldHaveReceived('ensureDirectoryExists')
@@ -98,16 +100,4 @@ public function testHandle()
98100
Hyde::path('resources/views/vendor/hyde/layouts/page.blade.php')
99101
)->once();
100102
}
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) => "resources/$path");
108-
109-
Container::setInstance($app);
110-
111-
return $app;
112-
}
113103
}

0 commit comments

Comments
 (0)