-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…(tbmatuka) This PR was squashed before being merged into the master branch (closes #74). Discussion ---------- Reset default EntrypointLookup on exception to fix #21 and #73 Since @ckrack seems to be unavailable to continue working on #21, I figured this would be faster :) I don't like having `_default` hardcoded in the listener, but I see no other options right now. I thought about adding a `resetAll()` method to EntrypointLookupCollection, but there were a couple of issues with that: 1. It would either be a BC break if I added it to the interface, or an important method that isn't interfaced and I don't really like either of those. 2. I couldn't even implement it because the container that we get in the collection only has `has()` and `get()` methods, so I couldn't go through it. This would also have to be replaced (and break BC) to implement `resetAll()`. Fixes symfony/demo#910 Commits ------- da36629 Reset default EntrypointLookup on exception to fix #21 and #73
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\EventListener; | ||
|
||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; | ||
|
||
class ExceptionListener | ||
{ | ||
private $entrypointLookupCollection; | ||
|
||
private $buildNames; | ||
|
||
public function __construct(EntrypointLookupCollection $entrypointLookupCollection, array $buildNames) | ||
{ | ||
$this->entrypointLookupCollection = $entrypointLookupCollection; | ||
$this->buildNames = $buildNames; | ||
} | ||
|
||
public function onKernelException() | ||
{ | ||
foreach ($this->buildNames as $buildName) { | ||
$this->entrypointLookupCollection->getEntrypointLookup($buildName)->reset(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\Tests\EventListener; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; | ||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface; | ||
use Symfony\WebpackEncoreBundle\EventListener\ExceptionListener; | ||
|
||
class ExceptionListenerTest extends TestCase | ||
{ | ||
public function testItResetsAllEntrypointLookups() | ||
{ | ||
/** @var EntrypointLookupInterface[]|Prophecy\Prophecy\ObjectProphecy[] $entrypointLookups */ | ||
$entrypointLookups = []; | ||
$entrypointLookupsValueMap = []; | ||
|
||
$buildNames = ['_default', '_test']; | ||
foreach ($buildNames as $buildName) { | ||
$entrypointLookups[$buildName] = $this->createMock(EntrypointLookupInterface::class); | ||
$entrypointLookups[$buildName]->expects($this->once())->method('reset'); | ||
|
||
$entrypointLookupsValueMap[] = [$buildName, $entrypointLookups[$buildName]]; | ||
} | ||
|
||
$entrypointLookupCollection = $this->createMock(EntrypointLookupCollection::class); | ||
$entrypointLookupCollection->method('getEntrypointLookup') | ||
->willReturnMap($entrypointLookupsValueMap); | ||
|
||
$request = new Request(); | ||
$exception = new \Exception(); | ||
$event = new GetResponseForExceptionEvent( | ||
$this->createMock(HttpKernelInterface::class), | ||
$request, | ||
HttpKernelInterface::MASTER_REQUEST, | ||
$exception | ||
); | ||
$listener = new ExceptionListener($entrypointLookupCollection, $buildNames); | ||
$listener->onKernelException($event); | ||
} | ||
} |