Skip to content
Permalink
Browse files

tests: Refactored `ResponseSubscriberTest` to use correct event class…

… and new `Version` service.
  • Loading branch information...
tarlepp committed Sep 18, 2019
1 parent f657c4f commit cf137b5038cfc8411e90374732a4ea4570bb1fc9
Showing with 18 additions and 6 deletions.
  1. +18 −6 tests/Integration/EventSubscriber/ResponseSubscriberTest.php
@@ -9,14 +9,15 @@
namespace App\Tests\Integration\EventSubscriber;
use App\EventSubscriber\ResponseSubscriber;
use App\Utils\JSON;
use App\Service\Version;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Throwable;
use function file_get_contents;
/**
* Class ResponseSubscriberTest
@@ -33,12 +34,23 @@ public function testThatSubscriberAddsHeader(): void
{
static::bootKernel();
/**
* @var MockObject|CacheInterface $cacheStub
*/
$cacheStub = $this->createMock(CacheInterface::class);
$cacheStub
->expects(static::once())
->method('get')
->willReturn('1.2.3');
$request = new Request();
$response = new Response();
$event = new FilterResponseEvent(static::$kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$event = new ResponseEvent(static::$kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$version = new Version(static::$kernel->getProjectDir(), $cacheStub);
$subscriber = new ResponseSubscriber();
$subscriber = new ResponseSubscriber($version);
$subscriber->onKernelResponse($event);
$response = $event->getResponse();
@@ -47,7 +59,7 @@ public function testThatSubscriberAddsHeader(): void
$version = $response->headers->get('X-API-VERSION');
static::assertNotNull($version);
static::assertSame(JSON::decode(file_get_contents(__DIR__ . '/../../../composer.json'))->version, $version);
static::assertSame('1.2.3', $version);
unset($response, $subscriber, $event, $request);
}

0 comments on commit cf137b5

Please sign in to comment.
You can’t perform that action at this time.