Skip to content

Commit

Permalink
tests: Refactored ResponseSubscriberTest to use correct event class…
Browse files Browse the repository at this point in the history
… and new `Version` service.
  • Loading branch information
tarlepp committed Sep 18, 2019
1 parent f657c4f commit cf137b5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tests/Integration/EventSubscriber/ResponseSubscriberTest.php
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit cf137b5

Please sign in to comment.