diff --git a/src/Task/Assets/ImageMinify.php b/src/Task/Assets/ImageMinify.php index 87c5a215..68c2bd75 100644 --- a/src/Task/Assets/ImageMinify.php +++ b/src/Task/Assets/ImageMinify.php @@ -216,15 +216,15 @@ public function run() } $amount = (count($files) == 1 ? 'image' : 'images'); - $message = "Minified {filecount} out of {filetotal} $amount into {destination}"; + $message = 'Minified {filecount} out of {filetotal} ' . $amount . ' into {destination}'; $context = ['filecount' => count($this->results['success']), 'filetotal' => count($files), 'destination' => $this->to]; - if (count($this->results['success']) == count($files)) { - $this->printTaskSuccess($message, $context); + $this->printTaskInfo($message, $context); - return Result::success($this, $message, $context); + if (count($this->results['success']) == count($files)) { + return Result::success($this, ucfirst($amount) . ' minified.'); } else { - return Result::error($this, $message, $context); + return Result::error($this, ucfirst($amount) . ' minification failed.'); } } @@ -389,6 +389,12 @@ protected function minify($files) $minifier = 'svgo'; break; } + + // Skip files without available minifier + if ($minifier === '') { + $this->results['error'][] = $from; + continue; + } } else { if (!in_array($this->minifier, $this->minifiers, true) && !is_callable(strtr($this->minifier, '-', '_')) diff --git a/tests/integration/AssetsTest.php b/tests/integration/AssetsTest.php index 6f45aeaa..b48407f6 100644 --- a/tests/integration/AssetsTest.php +++ b/tests/integration/AssetsTest.php @@ -76,4 +76,15 @@ public function testImageMinification() $this->assertLessThan($initialFileSize, $minifiedFileSize, 'Minified file is smaller than the source file'); $this->assertGreaterThan(0, $minifiedFileSize, 'Minified file is not empty'); } + + public function testImageMinificationErrors() + { + $this->fixtures->createAndCdToSandbox(); + + // fails because file is not an image + $result = $this->taskImageMinify($this->fixtures->dataFile('sample.css')) + ->to(realpath('') . '/dist') + ->run(); + $this->assertFalse($result->wasSuccessful(), $result->getMessage()); + } }