diff --git a/packages/framework/tests/Unit/ColoredBlockquoteShortcodesTest.php b/packages/framework/tests/Unit/ColoredBlockquoteShortcodesTest.php index 22be79b83f0..a86b11db4b4 100644 --- a/packages/framework/tests/Unit/ColoredBlockquoteShortcodesTest.php +++ b/packages/framework/tests/Unit/ColoredBlockquoteShortcodesTest.php @@ -6,20 +6,15 @@ use Hyde\Markdown\Processing\ColoredBlockquotes; use Hyde\Testing\UnitTestCase; -use Illuminate\Contracts\View\Factory as FactoryContract; -use Illuminate\Events\Dispatcher; -use Illuminate\Filesystem\Filesystem; -use Illuminate\View\Compilers\BladeCompiler; -use Illuminate\View\Engines\CompilerEngine; -use Illuminate\View\Engines\EngineResolver; -use Illuminate\View\Factory; -use Illuminate\View\FileViewFinder; +use Hyde\Testing\UsesRealBladeInUnitTests; /** * @covers \Hyde\Markdown\Processing\ColoredBlockquotes */ class ColoredBlockquoteShortcodesTest extends UnitTestCase { + use UsesRealBladeInUnitTests; + protected static bool $needsKernel = true; protected static bool $needsConfig = true; @@ -116,25 +111,4 @@ public static function blockquoteProvider(): array ], ]; } - - // Todo: Extract trait for this and MarkdownHeadingRendererUnitTest - protected function createRealBladeCompilerEnvironment(): void - { - $resolver = new EngineResolver(); - $filesystem = new Filesystem(); - - $resolver->register('blade', function () use ($filesystem) { - return new CompilerEngine( - new BladeCompiler($filesystem, sys_get_temp_dir()) - ); - }); - - $finder = new FileViewFinder($filesystem, [realpath(__DIR__.'/../../resources/views')]); - $finder->addNamespace('hyde', realpath(__DIR__.'/../../resources/views')); - - $view = new Factory($resolver, $finder, new Dispatcher()); - - app()->instance('view', $view); - app()->instance(FactoryContract::class, $view); - } } diff --git a/packages/framework/tests/Unit/HeadingRendererUnitTest.php b/packages/framework/tests/Unit/HeadingRendererUnitTest.php index ef4fb697f0d..63a7bdc9aae 100644 --- a/packages/framework/tests/Unit/HeadingRendererUnitTest.php +++ b/packages/framework/tests/Unit/HeadingRendererUnitTest.php @@ -8,14 +8,7 @@ use Hyde\Pages\DocumentationPage; use Hyde\Pages\MarkdownPage; use Hyde\Testing\UnitTestCase; -use Illuminate\Contracts\View\Factory as FactoryContract; -use Illuminate\Events\Dispatcher; -use Illuminate\Filesystem\Filesystem; -use Illuminate\View\Compilers\BladeCompiler; -use Illuminate\View\Engines\CompilerEngine; -use Illuminate\View\Engines\EngineResolver; -use Illuminate\View\Factory; -use Illuminate\View\FileViewFinder; +use Hyde\Testing\UsesRealBladeInUnitTests; use InvalidArgumentException; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; use League\CommonMark\Node\Node; @@ -29,6 +22,8 @@ */ class HeadingRendererUnitTest extends UnitTestCase { + use UsesRealBladeInUnitTests; + protected static bool $needsConfig = true; protected static ?array $cachedConfig = null; @@ -238,26 +233,6 @@ public function testPostProcessHandlesNoHeadingTags() $this->assertSame('

Paragraph

', (new HeadingRenderer())->postProcess($html)); } - protected function createRealBladeCompilerEnvironment(): void - { - $resolver = new EngineResolver(); - $filesystem = new Filesystem(); - - $resolver->register('blade', function () use ($filesystem) { - return new CompilerEngine( - new BladeCompiler($filesystem, sys_get_temp_dir()) - ); - }); - - $finder = new FileViewFinder($filesystem, [realpath(__DIR__.'/../../resources/views')]); - $finder->addNamespace('hyde', realpath(__DIR__.'/../../resources/views')); - - $view = new Factory($resolver, $finder, new Dispatcher()); - - app()->instance('view', $view); - app()->instance(FactoryContract::class, $view); - } - protected function mockChildNodeRenderer(string $contents = 'Test Heading'): ChildNodeRendererInterface { $childRenderer = Mockery::mock(ChildNodeRendererInterface::class); diff --git a/packages/testing/src/UsesRealBladeInUnitTests.php b/packages/testing/src/UsesRealBladeInUnitTests.php index bffe4473a93..ec8ae942f71 100644 --- a/packages/testing/src/UsesRealBladeInUnitTests.php +++ b/packages/testing/src/UsesRealBladeInUnitTests.php @@ -4,7 +4,34 @@ namespace Hyde\Testing; +use Illuminate\Contracts\View\Factory as FactoryContract; +use Illuminate\Events\Dispatcher; +use Illuminate\Filesystem\Filesystem; +use Illuminate\View\Compilers\BladeCompiler; +use Illuminate\View\Engines\CompilerEngine; +use Illuminate\View\Engines\EngineResolver; +use Illuminate\View\Factory; +use Illuminate\View\FileViewFinder; + trait UsesRealBladeInUnitTests { - // + protected function createRealBladeCompilerEnvironment(): void + { + $resolver = new EngineResolver(); + $filesystem = new Filesystem(); + + $resolver->register('blade', function () use ($filesystem) { + return new CompilerEngine( + new BladeCompiler($filesystem, sys_get_temp_dir()) + ); + }); + + $finder = new FileViewFinder($filesystem, [realpath(__DIR__.'/../../resources/views')]); + $finder->addNamespace('hyde', realpath(__DIR__.'/../../resources/views')); + + $view = new Factory($resolver, $finder, new Dispatcher()); + + app()->instance('view', $view); + app()->instance(FactoryContract::class, $view); + } }