diff --git a/Classes/EventListener/WebpCreator.php b/Classes/EventListener/WebpCreator.php index bfa9086..5d1c2ca 100644 --- a/Classes/EventListener/WebpCreator.php +++ b/Classes/EventListener/WebpCreator.php @@ -4,6 +4,7 @@ namespace Netlogix\Nximageoptimizer\EventListener; +use PHPUnit\Framework\Attributes\CodeCoverageIgnore; use TYPO3\CMS\Core\Resource\Driver\DriverInterface; use TYPO3\CMS\Core\Resource\Event\AfterFileProcessingEvent; use TYPO3\CMS\Core\Resource\ProcessedFile; @@ -37,9 +38,7 @@ public function createWebpVersion(AfterFileProcessingEvent $event): void $this->createWebpImage($event->getProcessedFile(), $event->getDriver()); } - /** - * @codeCoverageIgnore This method is only used for substitution in tests - */ + #[CodeCoverageIgnore] protected function isCwebpInstalled(): bool { return (bool) CommandUtility::checkCommand('cwebp'); diff --git a/Tests/Unit/EventListener/ImageOptimizerTest.php b/Tests/Unit/EventListener/ImageOptimizerTest.php index 076657d..0d32802 100644 --- a/Tests/Unit/EventListener/ImageOptimizerTest.php +++ b/Tests/Unit/EventListener/ImageOptimizerTest.php @@ -21,7 +21,7 @@ class ImageOptimizerTest extends UnitTestCase { - public function tearDown(): void + protected function tearDown(): void { unset($GLOBALS['TYPO3_REQUEST']); parent::tearDown(); @@ -31,7 +31,7 @@ public function tearDown(): void public function constructShouldSetConfiguration(): void { $configuration = [ - 'disableAutomaticWebpCreation' => 0 + 'disableAutomaticWebpCreation' => 0, ]; $container = $this->initContainer(); @@ -192,7 +192,9 @@ public function execShouldLogOutputToErrorLog(): void $logger = $this->createMock(LoggerInterface::class); $logger->expects(self::once()) ->method('error') - ->with('sample output', ['command' => 'echo "sample output"']); + ->with('sample output', [ + 'command' => 'echo "sample output"', + ]); $subject = $this->getAccessibleMock(ImageOptimizer::class, null); $subject->setLogger($logger); diff --git a/Tests/Unit/EventListener/WebpCreatorTest.php b/Tests/Unit/EventListener/WebpCreatorTest.php index 6f87995..acc44eb 100644 --- a/Tests/Unit/EventListener/WebpCreatorTest.php +++ b/Tests/Unit/EventListener/WebpCreatorTest.php @@ -24,7 +24,7 @@ public function createWebpVersionShouldNotCreateWebpImageIfDisabledViaConfigurat { $container = $this->initContainer(); $container->set(ExtensionConfiguration::class, $this->getExtensionConfigurationMock([ - 'disableAutomaticWebpCreation' => 1 + 'disableAutomaticWebpCreation' => 1, ])); $subject = $this->getAccessibleMock(WebpCreator::class, ['createWebpImage']); @@ -48,7 +48,7 @@ public function createWebpVersionShouldNotCreateWebpImageIfNotEnabled(): void { $container = $this->initContainer(); $container->set(ExtensionConfiguration::class, $this->getExtensionConfigurationMock([ - 'disableAutomaticWebpCreation' => 0 + 'disableAutomaticWebpCreation' => 0, ])); $subject = $this->getAccessibleMock(WebpCreator::class, ['isEnabled', 'createWebpImage']); @@ -76,7 +76,7 @@ public function createWebpVersionShouldNotCreateWebpImageIfSourceImageTypeIsNotS { $container = $this->initContainer(); $container->set(ExtensionConfiguration::class, $this->getExtensionConfigurationMock([ - 'disableAutomaticWebpCreation' => 0 + 'disableAutomaticWebpCreation' => 0, ])); $subject = $this->getAccessibleMock(WebpCreator::class, ['isEnabled', 'createWebpImage']); @@ -110,7 +110,7 @@ public function createWebpVersionShouldNotCreateWebpImageIfCwebpIsNotInstalled(s { $container = $this->initContainer(); $container->set(ExtensionConfiguration::class, $this->getExtensionConfigurationMock([ - 'disableAutomaticWebpCreation' => 0 + 'disableAutomaticWebpCreation' => 0, ])); $subject = $this->getAccessibleMock(WebpCreator::class, ['isEnabled', 'createWebpImage', 'isCwebpInstalled']); @@ -155,7 +155,7 @@ public function createWebpVersionShouldCreateWebpImage(string $mimeType): void { $container = $this->initContainer(); $container->set(ExtensionConfiguration::class, $this->getExtensionConfigurationMock([ - 'disableAutomaticWebpCreation' => 0 + 'disableAutomaticWebpCreation' => 0, ])); $subject = $this->getAccessibleMock(WebpCreator::class, ['isEnabled', 'createWebpImage', 'isCwebpInstalled']); @@ -192,10 +192,7 @@ public function createWebpVersionShouldCreateWebpImage(string $mimeType): void public static function mimeTypeDataProvider(): array { - return [ - ['image/jpeg'], - ['image/png'] - ]; + return [['image/jpeg'], ['image/png']]; } private function getExtensionConfigurationMock(array $configuration): ExtensionConfiguration diff --git a/Tests/Unit/Service/ImageServiceTest.php b/Tests/Unit/Service/ImageServiceTest.php index 77f7c78..b19977e 100644 --- a/Tests/Unit/Service/ImageServiceTest.php +++ b/Tests/Unit/Service/ImageServiceTest.php @@ -6,11 +6,9 @@ use Netlogix\Nximageoptimizer\Service\ImageService; use PHPUnit\Framework\Attributes\Test; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Resource\File; use TYPO3\CMS\Core\Resource\ProcessedFile; use TYPO3\CMS\Core\Resource\ResourceFactory; -use TYPO3\CMS\Extbase\Service\EnvironmentService; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class ImageServiceTest extends UnitTestCase