|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony WebpackEncoreBundle package. |
| 5 | + * (c) Fabien Potencier <[email protected]> |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Symfony\WebpackEncoreBundle\Tests\EventListener; |
| 11 | + |
| 12 | +use Symfony\Component\HttpFoundation\Request; |
| 13 | +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
| 14 | +use Symfony\Component\HttpKernel\HttpKernelInterface; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; |
| 17 | +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface; |
| 18 | +use Symfony\WebpackEncoreBundle\EventListener\ExceptionListener; |
| 19 | + |
| 20 | +class ExceptionListenerTest extends TestCase |
| 21 | +{ |
| 22 | + public function testItResetsAllEntrypointLookups() |
| 23 | + { |
| 24 | + /** @var EntrypointLookupInterface[]|Prophecy\Prophecy\ObjectProphecy[] $entrypointLookups */ |
| 25 | + $entrypointLookups = []; |
| 26 | + $entrypointLookupsValueMap = []; |
| 27 | + |
| 28 | + $buildNames = ['_default', '_test']; |
| 29 | + foreach ($buildNames as $buildName) { |
| 30 | + $entrypointLookups[$buildName] = $this->createMock(EntrypointLookupInterface::class); |
| 31 | + $entrypointLookups[$buildName]->expects($this->once())->method('reset'); |
| 32 | + |
| 33 | + $entrypointLookupsValueMap[] = [$buildName, $entrypointLookups[$buildName]]; |
| 34 | + } |
| 35 | + |
| 36 | + $entrypointLookupCollection = $this->createMock(EntrypointLookupCollection::class); |
| 37 | + $entrypointLookupCollection->method('getEntrypointLookup') |
| 38 | + ->willReturnMap($entrypointLookupsValueMap); |
| 39 | + |
| 40 | + $request = new Request(); |
| 41 | + $exception = new \Exception(); |
| 42 | + $event = new GetResponseForExceptionEvent( |
| 43 | + $this->createMock(HttpKernelInterface::class), |
| 44 | + $request, |
| 45 | + HttpKernelInterface::MASTER_REQUEST, |
| 46 | + $exception |
| 47 | + ); |
| 48 | + $listener = new ExceptionListener($entrypointLookupCollection, $buildNames); |
| 49 | + $listener->onKernelException($event); |
| 50 | + } |
| 51 | +} |
0 commit comments