1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
/*
* This file is part of the Mercure Component project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Symfony\Component\Mercure\Tests\EventSubscriber;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Mercure\EventSubscriber\SetCookieSubscriber;
/**
* @author Kévin Dunglas <kevin@dunglas.fr>
*/
class SetCookieSubscriberTest extends TestCase
{
public function testOnKernelResponse(): void
{
$subscriber = new SetCookieSubscriber();
$kernel = $this->createMock(HttpKernelInterface::class);
$request = Request::create('/');
$cookies = ['' => Cookie::create('mercureAuthorization')];
$request->attributes->set('_mercure_authorization_cookies', $cookies);
$response = new Response();
$event = new ResponseEvent($kernel, $request, 1 /*HttpKernelInterface::MAIN_REQUEST*/, $response);
$subscriber->onKernelResponse($event);
$this->assertFalse($request->attributes->has('_mercure_authorization_cookies'));
$this->assertSame(array_values($cookies), $response->headers->getCookies());
}
public function testWiring(): void
{
$this->assertInstanceOf(EventSubscriberInterface::class, new SetCookieSubscriber());
$this->assertArrayHasKey(KernelEvents::RESPONSE, SetCookieSubscriber::getSubscribedEvents());
}
}
|