Unverified Commit 67ceb1be authored by alexpott's avatar alexpott

Issue #3162031 by ravi.shankar, Hardik_Patel_12, longwave, catch: [Symfony...

Issue #3162031 by ravi.shankar, Hardik_Patel_12, longwave, catch: [Symfony 5.1] Class "Symfony\Component\HttpKernel\Event\ViewEvent" is declared "final" and cannot be mocked
parent fde0132b
......@@ -4,6 +4,10 @@
use Drupal\Tests\UnitTestCase;
use Drupal\Core\EventSubscriber\PsrResponseSubscriber;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* @coversDefaultClass \Drupal\Core\EventSubscriber\PsrResponseSubscriber
......@@ -48,12 +52,9 @@ protected function setUp(): void {
* @covers ::onKernelView
*/
public function testConvertsControllerResult() {
$event = $this->createEventMock($this->createMock('Psr\Http\Message\ResponseInterface'));
$event
->expects($this->once())
->method('setResponse')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Response'));
$event = $this->createEvent($this->createMock('Psr\Http\Message\ResponseInterface'));
$this->psrResponseSubscriber->onKernelView($event);
$this->assertInstanceOf(Response::class, $event->getResponse());
}
/**
......@@ -62,36 +63,31 @@ public function testConvertsControllerResult() {
* @covers ::onKernelView
*/
public function testDoesNotConvertControllerResult() {
$event = $this->createEventMock([]);
$event
->expects($this->never())
->method('setResponse');
$event = $this->createEvent([]);
$this->psrResponseSubscriber->onKernelView($event);
$event = $this->createEventMock(NULL);
$event
->expects($this->never())
->method('setResponse');
$this->assertNull($event->getResponse());
$event = $this->createEvent(NULL);
$this->psrResponseSubscriber->onKernelView($event);
$this->assertNull($event->getResponse());
}
/**
* Sets up an alias event that return $controllerResult.
* Sets up an event that returns $controllerResult.
*
* @param mixed $controller_result
* The return Object.
*
* @return \Symfony\Component\HttpKernel\Event\ViewEvent|\PHPUnit\Framework\MockObject\MockObject
* A mock object to test.
* @return \Symfony\Component\HttpKernel\Event\ViewEvent
* A ViewEvent object to test.
*/
protected function createEventMock($controller_result) {
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\ViewEvent')
->disableOriginalConstructor()
->getMock();
$event
->expects($this->once())
->method('getControllerResult')
->willReturn($controller_result);
return $event;
protected function createEvent($controller_result) {
return new ViewEvent(
$this->createMock(HttpKernelInterface::class),
$this->createMock(Request::class),
HttpKernelInterface::MASTER_REQUEST,
$controller_result
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment