Skip to content

[5.7] Adjust mix missing asset exceptions #26431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,14 @@ function mix($path, $manifestDirectory = '')
$manifest = $manifests[$manifestPath];

if (! isset($manifest[$path])) {
report(new Exception("Unable to locate Mix file: {$path}."));
$exception = new Exception("Unable to locate Mix file: {$path}.");

if (! app('config')->get('app.debug')) {
report($exception);

return $path;
} else {
throw $exception;
}
}

Expand Down
33 changes: 28 additions & 5 deletions tests/Integration/Foundation/FoundationHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Route;
use Illuminate\Contracts\Debug\ExceptionHandler;

/**
Expand Down Expand Up @@ -47,8 +48,8 @@ public function testMixReportsExceptionWhenAssetIsMissingFromManifest()

mix('missing.js');

$this->assertInstanceOf(Exception::class, $handler->reported);
$this->assertSame('Unable to locate Mix file: /missing.js.', $handler->reported->getMessage());
$this->assertInstanceOf(Exception::class, $handler->reported[0]);
$this->assertSame('Unable to locate Mix file: /missing.js.', $handler->reported[0]->getMessage());

unlink($manifest);
}
Expand All @@ -67,7 +68,7 @@ public function testMixSilentlyFailsWhenAssetIsMissingFromManifestWhenNotInDebug

/**
* @expectedException \Exception
* @expectedExceptionMessage Undefined index: /missing.js
* @expectedExceptionMessage Unable to locate Mix file: /missing.js.
*/
public function testMixThrowsExceptionWhenAssetIsMissingFromManifestWhenInDebugMode()
{
Expand All @@ -83,6 +84,23 @@ public function testMixThrowsExceptionWhenAssetIsMissingFromManifestWhenInDebugM
}
}

public function testMixOnlyThrowsAndReportsOneExceptionWhenAssetIsMissingFromManifestWhenInDebugMode()
{
$handler = new FakeHandler;
$this->app->instance(ExceptionHandler::class, $handler);
$this->app['config']->set('app.debug', true);
$manifest = $this->makeManifest();
Route::get('test-route', function () {
mix('missing.js');
});

$this->get('/test-route');

$this->assertCount(1, $handler->reported);

unlink($manifest);
}

protected function makeManifest($directory = '')
{
$this->app->singleton('path.public', function () {
Expand All @@ -105,10 +123,15 @@ protected function makeManifest($directory = '')

class FakeHandler
{
public $reported;
public $reported = [];

public function report($exception)
{
$this->reported = $exception;
$this->reported[] = $exception;
}

public function render($exception)
{
//
}
}