class Fast404EventSubscriberTest in Fast 404 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/Fast404EventSubscriberTest.php \Drupal\Tests\fast404\Unit\Fast404EventSubscriberTest
Tests the fast404 event subscriber logic.
@coversDefaultClass \Drupal\fast404\EventSubscriber\Fast404EventSubscriber @group fast404
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\fast404\Unit\Fast404EventSubscriberTest
Expanded class hierarchy of Fast404EventSubscriberTest
File
- tests/
src/ Unit/ Fast404EventSubscriberTest.php, line 18
Namespace
Drupal\Tests\fast404\UnitView source
class Fast404EventSubscriberTest extends UnitTestCase {
/**
* The event.
*
* @var \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
*/
protected $event;
/**
* {@inheritdoc}
*/
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());
}
/**
* Tests event handling for kernel requests.
*
* @covers ::onKernelRequest
*/
// public function testOnKernelRequest() {}
/**
* Tests event handling for not found exceptions.
*
* @covers ::onNotFoundException
*/
public function testOnNotFoundException() {
$subscriber = $this
->getFast404EventSubscriber();
$subscriber
->onNotFoundException($this->event);
$e = $this->event
->getException();
$this
->assertTrue($e instanceof NotFoundHttpException);
}
/**
* Creates a Fast404EventSubscriber object to test.
*
* @return \Drupal\fast404\EventSubscriber\Fast404EventSubscriber
* A mock Fast404EventSubscriber object to test.
*/
protected function getFast404EventSubscriber() {
$requestStackStub = $this
->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->getMock();
$subscriber = $this
->getMockBuilder('\\Drupal\\fast404\\EventSubscriber\\Fast404EventSubscriber')
->setConstructorArgs([
$requestStackStub,
])
->getMock();
return $subscriber;
}
/**
* Tests event listener registration.
*
* @covers ::getSubscribedEvents
*/
public function testGetSubscribedEvents() {
$this
->assertEquals([
'kernel.request' => [
[
'onKernelRequest',
100,
],
],
'kernel.exception' => [
[
'onNotFoundException',
0,
],
],
], Fast404EventSubscriber::getSubscribedEvents());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Fast404EventSubscriberTest:: |
protected | property | The event. | |
Fast404EventSubscriberTest:: |
protected | function | Creates a Fast404EventSubscriber object to test. | |
Fast404EventSubscriberTest:: |
protected | function |
Overrides UnitTestCase:: |
|
Fast404EventSubscriberTest:: |
public | function | Tests event listener registration. | |
Fast404EventSubscriberTest:: |
public | function | Tests event handling for not found exceptions. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |