diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index 6fa2b6b2d..6fa92b795 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -125,20 +125,22 @@ class SSViewerTest extends SapphireTest { // exception thrown... good } - // secondly, make sure that requirements combine can handle this and continue safely + // secondly, make sure that requirements combine throws the correct warning, and only that warning @unlink($combinedTestFilePath); try{ - /* - * Use @ (ignore warning) because a warning would cause php unit to throw an exception and therefore change the execution - * process and mess up the next test. - */ - @Requirements::process_combined_files(); + Requirements::process_combined_files(); + }catch(PHPUnit_Framework_Error_Warning $e){ + if(strstr($e->getMessage(), 'Failed to minify') === false){ + $this->fail('Requirements::process_combined_files raised a warning, which is good, but this is not the expected warning ("Failed to minify..."): '.$e); + Requirements::set_backend($oldBackend); + return; + } }catch(Exception $e){ $this->fail('Requirements::process_combined_files did not catch exception caused by minifying bad js file: '.$e); Requirements::set_backend($oldBackend); return; } - + // and make sure the combined content matches the input content, i.e. no loss of functionality if(!file_exists($combinedTestFilePath)){ $this->fail('No combined file was created at expected path: '.$combinedTestFilePath); @@ -147,7 +149,6 @@ class SSViewerTest extends SapphireTest { } $combinedTestFileContents = file_get_contents($combinedTestFilePath); $this->assertContains($jsFileContents, $combinedTestFileContents); - // reset Requirements::set_backend($oldBackend); diff --git a/view/Requirements.php b/view/Requirements.php index 8952edf0a..a607eb88e 100644 --- a/view/Requirements.php +++ b/view/Requirements.php @@ -1129,6 +1129,7 @@ class Requirements_Backend { if(!$refresh) continue; + $failedToMinify = false; $combinedData = ""; foreach(array_diff($fileList, $this->blocked) as $file) { $fileContent = file_get_contents($base . $file); @@ -1136,8 +1137,7 @@ class Requirements_Backend { try{ $fileContent = $this->minifyFile($file, $fileContent); }catch(Exception $e){ - // failed to minify, use unminified - user_error('Failed to minify '.$file.', exception: '.$e->getMessage(), E_USER_WARNING); + $failedToMinify = true; } if ($this->write_header_comment) { @@ -1156,6 +1156,12 @@ class Requirements_Backend { fclose($fh); unset($fh); } + + if($failedToMinify){ + // Failed to minify, use unminified. This warning is raised at the end to allow code execution + // to complete in case this warning is caught inside a try-catch block. + user_error('Failed to minify '.$file.', exception: '.$e->getMessage(), E_USER_WARNING); + } // Unsuccessful write - just include the regular JS files, rather than the combined one if(!$successfulWrite) {