diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b94bbe..d62b4a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,5 @@ name: HTMLMinTests -on: [push, pull_request] +on: [push] jobs: htmlmin: name: PHP ${{ matrix.php-versions }} @@ -33,4 +33,3 @@ jobs: env: PHP_VERSION: ${{ matrix.php-versions }} run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml - continue-on-error: true diff --git a/.gitignore b/.gitignore index e39e94f..0d83a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock phpunit.xml vendor -/.idea \ No newline at end of file +/.idea +/.phpunit.cache \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bd51815..57c3b36 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,13 @@ - - - - ./tests - - - - - ./src - - + + + + ./tests + + + + + ./src + + diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index 7eed413..5aa38a1 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -184,7 +184,7 @@ protected function registerMinifyCompiler() $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler, $this->previousCompiler->getCustomDirectives()); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler, $this->previousCompiler?->getCustomDirectives() ?? []); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index cd75a82..d9966a2 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -22,14 +22,7 @@ */ abstract class AbstractTestCase extends AbstractPackageTestCase { - /** - * Get the service provider class. - * - * @param \Illuminate\Contracts\Foundation\Application $app - * - * @return string - */ - protected function getServiceProviderClass() + protected static function getServiceProviderClass(): string { return HTMLMinServiceProvider::class; } diff --git a/tests/Compilers/MinifyCompilerTest.php b/tests/Compilers/MinifyCompilerTest.php index afd9a99..420a6fc 100644 --- a/tests/Compilers/MinifyCompilerTest.php +++ b/tests/Compilers/MinifyCompilerTest.php @@ -23,9 +23,9 @@ * * @author Graham Campbell */ -class MinifyCompilerTest extends AbstractTestCase +final class MinifyCompilerTest extends AbstractTestCase { - public function testMinify() + public function testMinify(): void { $compiler = $this->getCompiler(); @@ -37,7 +37,7 @@ public function testMinify() $this->assertSame('abc', $return); } - public function testMinifyIgnored() + public function testMinifyIgnored(): void { $blade = Mockery::mock(BladeMinifier::class); $files = Mockery::mock(Filesystem::class); @@ -57,7 +57,7 @@ public function testMinifyIgnored() $this->assertSame($html, $return); } - public function testCompilers() + public function testCompilers(): void { $compiler = $this->getCompiler(); diff --git a/tests/Facades/HTMLMinTest.php b/tests/Facades/HTMLMinTest.php index 71c7672..32fce2c 100644 --- a/tests/Facades/HTMLMinTest.php +++ b/tests/Facades/HTMLMinTest.php @@ -28,30 +28,24 @@ class HTMLMinTest extends AbstractTestCase /** * Get the facade accessor. - * - * @return string */ - protected function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'htmlmin'; } /** * Get the facade class. - * - * @return string */ - protected function getFacadeClass() + protected static function getFacadeClass(): string { return Facade::class; } /** * Get the facade root. - * - * @return string */ - protected function getFacadeRoot() + protected static function getFacadeRoot(): string { return HTMLMin::class; } diff --git a/tests/Functional/BladeEnabledTest.php b/tests/Functional/BladeEnabledTest.php index b80cc25..bd521c0 100644 --- a/tests/Functional/BladeEnabledTest.php +++ b/tests/Functional/BladeEnabledTest.php @@ -19,23 +19,21 @@ * * @author Graham Campbell */ -class BladeEnabledTest extends AbstractFunctionalTestCase +final class BladeEnabledTest extends AbstractFunctionalTestCase { /** * Setup the application environment. * * @param \Illuminate\Contracts\Foundation\Application $app - * - * @return void */ - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { parent::getEnvironmentSetUp($app); $app->config->set('htmlmin.blade', true); } - public function testNewSetup() + public function testNewSetup(): void { $this->app->view->addNamespace('stubs', realpath(__DIR__.'/stubs')); diff --git a/tests/Functional/ComponentsTest.php b/tests/Functional/ComponentsTest.php index 2313fc3..2c1e42e 100644 --- a/tests/Functional/ComponentsTest.php +++ b/tests/Functional/ComponentsTest.php @@ -5,21 +5,19 @@ use HTMLMin\HTMLMin\Compilers\MinifyCompiler; use HTMLMin\Tests\HTMLMin\Functional\Provider\TestComponentsProvider; -class ComponentsTest extends AbstractFunctionalTestCase +final class ComponentsTest extends AbstractFunctionalTestCase { /** * Get the required service providers. * - * @param \Illuminate\Contracts\Foundation\Application $app - * * @return string[] */ - protected function getRequiredServiceProviders($app) + protected static function getRequiredServiceProviders(): array { return [TestComponentsProvider::class]; } - public function testUseComponents() + public function testUseComponents(): void { if (version_compare($this->app->version(), '7.0', '<')) { $this->markTestSkipped('Class components were released in Laravel version 7.0.0'); diff --git a/tests/Functional/DirectivesTest.php b/tests/Functional/DirectivesTest.php index 45f3369..2432d04 100644 --- a/tests/Functional/DirectivesTest.php +++ b/tests/Functional/DirectivesTest.php @@ -6,21 +6,19 @@ use HTMLMin\Tests\HTMLMin\Functional\Provider\TestDirectivesProvider; use HTMLMin\Tests\HTMLMin\Mock\MinifyCompilerMock; -class DirectivesTest extends AbstractFunctionalTestCase +final class DirectivesTest extends AbstractFunctionalTestCase { /** * Get the required service providers. * - * @param \Illuminate\Contracts\Foundation\Application $app - * * @return string[] */ - protected function getRequiredServiceProviders($app) + protected static function getRequiredServiceProviders(): array { return [TestDirectivesProvider::class]; } - public function testUseDirectives() + public function testUseDirectives(): void { /** @var MinifyCompiler $minifyCompiler */ $minifyCompiler = $this->app->make('view') diff --git a/tests/Functional/MiddlewareTest.php b/tests/Functional/MiddlewareTest.php index 1690e37..8141315 100644 --- a/tests/Functional/MiddlewareTest.php +++ b/tests/Functional/MiddlewareTest.php @@ -22,23 +22,21 @@ * * @author Graham Campbell */ -class MiddlewareTest extends AbstractFunctionalTestCase +final class MiddlewareTest extends AbstractFunctionalTestCase { /** * Setup the application environment. * * @param \Illuminate\Contracts\Foundation\Application $app - * - * @return void */ - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { parent::getEnvironmentSetUp($app); $app->config->set('htmlmin.live', true); } - public function testNewSetup() + public function testNewSetup(): void { $this->app->view->addNamespace('stubs', realpath(__DIR__.'/stubs')); @@ -53,7 +51,7 @@ public function testNewSetup() $this->assertSameIgnoreLineEndings($expected, $actual); } - public function testRedirect() + public function testRedirect(): void { $this->app->router->get('htmlmin-test-route', ['middleware' => MinifyMiddleware::class, function () { return Redirect::to('foo'); @@ -64,7 +62,7 @@ public function testRedirect() $this->assertSame($this->app->url->to('foo'), $response->headers->get('Location')); } - public function testJson() + public function testJson(): void { $this->app->router->get('htmlmin-test-route', ['middleware' => MinifyMiddleware::class, function () { return Response::json(['foo' => 'bar', ['baz']], 200, [], JSON_PRETTY_PRINT); diff --git a/tests/Functional/Provider/TestDirectivesProvider.php b/tests/Functional/Provider/TestDirectivesProvider.php index e9b4896..cb8f05f 100644 --- a/tests/Functional/Provider/TestDirectivesProvider.php +++ b/tests/Functional/Provider/TestDirectivesProvider.php @@ -5,11 +5,10 @@ use Illuminate\Support\ServiceProvider; use Illuminate\View\Compilers\BladeCompiler; -class TestDirectivesProvider extends ServiceProvider +final class TestDirectivesProvider extends ServiceProvider { - public static function testDirective() + public static function testDirective(): void { - return 'test content'; } public function register() diff --git a/tests/Functional/SkipMinificationTest.php b/tests/Functional/SkipMinificationTest.php index 74a7e41..a41f9d7 100644 --- a/tests/Functional/SkipMinificationTest.php +++ b/tests/Functional/SkipMinificationTest.php @@ -19,7 +19,7 @@ * * @author Graham Campbell */ -class SkipMinificationTest extends AbstractFunctionalTestCase +final class SkipMinificationTest extends AbstractFunctionalTestCase { /** * Setup the application environment. @@ -27,17 +27,15 @@ class SkipMinificationTest extends AbstractFunctionalTestCase * Ensure that blade is on. * * @param \Illuminate\Contracts\Foundation\Application $app - * - * @return void */ - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { parent::getEnvironmentSetUp($app); $app->config->set('htmlmin.blade', true); } - public function testNewSkipHMTL() + public function testNewSkipHMTL(): void { $this->app->view->addNamespace('stubs', realpath(__DIR__.'/stubs')); @@ -48,7 +46,7 @@ public function testNewSkipHMTL() $this->assertSameIgnoreLineEndings($expected, $actual); } - public function testMarkDown() + public function testMarkDown(): void { $this->app->view->addNamespace('stubs', realpath(__DIR__.'/stubs')); diff --git a/tests/HTMLMinTest.php b/tests/HTMLMinTest.php index 3740eb6..683d4bc 100644 --- a/tests/HTMLMinTest.php +++ b/tests/HTMLMinTest.php @@ -12,6 +12,7 @@ namespace HTMLMin\Tests\HTMLMin; +use PHPUnit\Framework\Attributes\DataProvider; use GrahamCampbell\TestBench\AbstractTestCase as AbstractTestBenchTestCase; use HTMLMin\HTMLMin\HTMLMin; use HTMLMin\HTMLMin\Minifiers\BladeMinifier; @@ -25,9 +26,9 @@ * * @author Graham Campbell */ -class HTMLMinTest extends AbstractTestBenchTestCase +final class HTMLMinTest extends AbstractTestBenchTestCase { - public function methodProvider() + public static function methodProvider(): array { return [ ['blade', 'getBladeMinifier'], @@ -37,10 +38,8 @@ public function methodProvider() ]; } - /** - * @dataProvider methodProvider - */ - public function testMethods($method, $class) + #[DataProvider('methodProvider')] + public function testMethods($method, $class): void { $htmlmin = $this->getHTMLMin(); diff --git a/tests/Minifiers/BladeMinifierTest.php b/tests/Minifiers/BladeMinifierTest.php index 936a5a8..c7d0b56 100644 --- a/tests/Minifiers/BladeMinifierTest.php +++ b/tests/Minifiers/BladeMinifierTest.php @@ -12,6 +12,7 @@ namespace HTMLMin\Tests\HTMLMin\Minifiers; +use PHPUnit\Framework\Attributes\DataProvider; use GrahamCampbell\TestBench\AbstractTestCase; use HTMLMin\HTMLMin\Minifiers\BladeMinifier; @@ -20,9 +21,9 @@ * * @author Graham Campbell */ -class BladeMinifierTest extends AbstractTestCase +final class BladeMinifierTest extends AbstractTestCase { - public function testRenderEnabled() + public function testRenderEnabled(): void { $blade = $this->getBladeMinifier(); @@ -35,7 +36,7 @@ public function testRenderEnabled() $this->assertSame('test
', $return); } - public function tagProvider() + public static function tagProvider(): array { return [ ['textarea'], @@ -44,10 +45,8 @@ public function tagProvider() ]; } - /** - * @dataProvider tagProvider - */ - public function testRenderHtmlDisabled($tag) + #[DataProvider('tagProvider')] + public function testRenderHtmlDisabled($tag): void { $blade = $this->getBladeMinifier(); @@ -56,7 +55,7 @@ public function testRenderHtmlDisabled($tag) $this->assertSame("test <$tag>", $return); } - public function testRenderCommentDisabled() + public function testRenderCommentDisabled(): void { $blade = $this->getBladeMinifier(); @@ -65,10 +64,8 @@ public function testRenderCommentDisabled() $this->assertSame('test getBladeMinifier(true); diff --git a/tests/Minifiers/CssMinifierTest.php b/tests/Minifiers/CssMinifierTest.php index eb3010b..9316bd2 100644 --- a/tests/Minifiers/CssMinifierTest.php +++ b/tests/Minifiers/CssMinifierTest.php @@ -20,9 +20,9 @@ * * @author Graham Campbell */ -class CssMinifierTest extends AbstractTestCase +final class CssMinifierTest extends AbstractTestCase { - public function testRender() + public function testRender(): void { $css = $this->getCssMinifier(); diff --git a/tests/Minifiers/HtmlMinifierTest.php b/tests/Minifiers/HtmlMinifierTest.php index 99fc9e4..89ee080 100644 --- a/tests/Minifiers/HtmlMinifierTest.php +++ b/tests/Minifiers/HtmlMinifierTest.php @@ -23,9 +23,9 @@ * * @author Graham Campbell */ -class HtmlMinifierTest extends AbstractTestCase +final class HtmlMinifierTest extends AbstractTestCase { - public function testRenderQuick() + public function testRenderQuick(): void { $html = $this->getHtmlMinifier(); @@ -34,7 +34,7 @@ public function testRenderQuick() $this->assertSame('test', $return); } - public function testRenderFull() + public function testRenderFull(): void { $html = $this->getHtmlMinifier(); $text = 'test'; diff --git a/tests/Minifiers/JsMinifierTest.php b/tests/Minifiers/JsMinifierTest.php index 6b77787..57f98d5 100644 --- a/tests/Minifiers/JsMinifierTest.php +++ b/tests/Minifiers/JsMinifierTest.php @@ -20,9 +20,9 @@ * * @author Graham Campbell */ -class JsMinifierTest extends AbstractTestCase +final class JsMinifierTest extends AbstractTestCase { - public function testRender() + public function testRender(): void { $js = $this->getJsMinifier(); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 8af4817..b4d3c6f 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -25,36 +25,36 @@ * * @author Graham Campbell */ -class ServiceProviderTest extends AbstractTestCase +final class ServiceProviderTest extends AbstractTestCase { use ServiceProviderTrait; - public function testCssMinifierIsInjectable() + public function testCssMinifierIsInjectable(): void { $this->assertIsInjectable(CssMinifier::class); } - public function testJsMinifierIsInjectable() + public function testJsMinifierIsInjectable(): void { $this->assertIsInjectable(JsMinifier::class); } - public function testHtmlMinifierIsInjectable() + public function testHtmlMinifierIsInjectable(): void { $this->assertIsInjectable(HtmlMinifier::class); } - public function testBladeMinifierIsInjectable() + public function testBladeMinifierIsInjectable(): void { $this->assertIsInjectable(BladeMinifier::class); } - public function testCompilerIsInjectable() + public function testCompilerIsInjectable(): void { $this->assertIsInjectable(MinifyCompiler::class); } - public function testHTMLMinIsInjectable() + public function testHTMLMinIsInjectable(): void { $this->assertIsInjectable(HTMLMin::class); }