Fast404EventSubscriberTest.php in Fast 404 8.2
File
tests/src/Unit/Fast404EventSubscriberTest.php
View source
<?php
namespace Drupal\Tests\fast404\Unit;
use Drupal\fast404\EventSubscriber\Fast404EventSubscriber;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class Fast404EventSubscriberTest extends UnitTestCase {
protected $event;
protected function setUp() {
parent::setUp();
$kernel = $this
->createMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$request = new Request();
$this->event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException());
}
public function testOnNotFoundException() {
$subscriber = $this
->getFast404EventSubscriber();
$subscriber
->onNotFoundException($this->event);
$e = $this->event
->getException();
$this
->assertInstanceOf(NotFoundHttpException::class, $e);
}
protected function getFast404EventSubscriber() {
$requestStackStub = $this
->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->getMock();
$subscriber = $this
->getMockBuilder('\\Drupal\\fast404\\EventSubscriber\\Fast404EventSubscriber')
->setConstructorArgs([
$requestStackStub,
])
->getMock();
return $subscriber;
}
public function testGetSubscribedEvents() {
$this
->assertEquals([
'kernel.request' => [
[
'onKernelRequest',
100,
],
],
'kernel.exception' => [
[
'onNotFoundException',
0,
],
],
], Fast404EventSubscriber::getSubscribedEvents());
}
}