diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ec23cd..9e2d747 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,17 +11,17 @@ jobs: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga + - uses: actions/checkout@v4 + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga build: name: Build - runs-on: Ubuntu-20.04 + runs-on: Ubuntu-22.04 strategy: fail-fast: false matrix: - php: ['7.1', '7.2', '7.3', '7.4', '8.0'] + php: ['8.1', '8.2', '8.3'] composer: [''] phpunit: [''] deprecation: [''] @@ -29,35 +29,30 @@ jobs: stability: [''] include: # Minimum supported dependencies with the latest and oldest PHP version - - php: 8.0 - composer: --prefer-stable --prefer-lowest - deprecation: max[direct]=0 - - php: 7.1 + - php: 8.1 composer: --prefer-stable --prefer-lowest deprecation: max[direct]=0 # symfony version - - php: 8.0 - symfony: '^3.0' - - php: 8.0 - symfony: '^4.0' - - php: 8.0 - symfony: '^5.0' + - php: 8.3 + symfony: '^6.4' + - php: 8.3 + symfony: '^7.0' # dev - - php: 8.0 + - php: 8.3 stability: 'dev' steps: - name: Set up PHP - uses: shivammathur/setup-php@2.7.0 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} coverage: none tools: flex - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup stability if: matrix.stability != '' @@ -79,10 +74,10 @@ jobs: - name: Validate run: | - composer validate --strict --no-check-lock + composer validate --strict --no-check-lock - name: Run tests env: SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: 1 run: | - ${{ matrix.phpunit }} ./vendor/bin/simple-phpunit + ${{ matrix.phpunit }} ./vendor/bin/simple-phpunit \ No newline at end of file diff --git a/Command/NotifyDeploymentCommand.php b/Command/NotifyDeploymentCommand.php index d6e5ab7..6bc9085 100644 --- a/Command/NotifyDeploymentCommand.php +++ b/Command/NotifyDeploymentCommand.php @@ -25,15 +25,13 @@ class NotifyDeploymentCommand extends Command public const EXIT_UNAUTHORIZED = 2; public const EXIT_HTTP_ERROR = 3; - protected static $defaultName = 'newrelic:notify-deployment'; - private $newrelic; public function __construct(Config $newrelic) { $this->newrelic = $newrelic; - parent::__construct(); + parent::__construct('newrelic:notify-deployment'); } protected function configure(): void @@ -171,4 +169,4 @@ private function createPayload(string $appName, InputInterface $input): string return http_build_query($content_array); } -} +} \ No newline at end of file diff --git a/EkinoNewRelicBundle.php b/EkinoNewRelicBundle.php index 3c2b092..aecd441 100644 --- a/EkinoNewRelicBundle.php +++ b/EkinoNewRelicBundle.php @@ -20,14 +20,14 @@ class EkinoNewRelicBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); $container->addCompilerPass(new MonologHandlerPass()); } - public function boot() + public function boot(): void { parent::boot(); @@ -36,7 +36,7 @@ public function boot() } } - public function shutdown() + public function shutdown(): void { if ($this->container->has(DeprecationListener::class)) { $this->container->get(DeprecationListener::class)->unregister(); @@ -44,4 +44,4 @@ public function shutdown() parent::shutdown(); } -} +} \ No newline at end of file diff --git a/Listener/ExceptionListener.php b/Listener/ExceptionListener.php index c083859..55c88f0 100644 --- a/Listener/ExceptionListener.php +++ b/Listener/ExceptionListener.php @@ -16,7 +16,6 @@ use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -44,7 +43,7 @@ public static function getSubscribedEvents(): array */ public function onKernelException(KernelExceptionEvent $event): void { - $exception = method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException(); + $exception = $event->getThrowable(); if (!$exception instanceof HttpExceptionInterface) { $this->interactor->noticeThrowable($exception); } @@ -52,9 +51,5 @@ public function onKernelException(KernelExceptionEvent $event): void } if (!class_exists(KernelExceptionEvent::class)) { - if (class_exists(ExceptionEvent::class)) { - class_alias(ExceptionEvent::class, KernelExceptionEvent::class); - } else { - class_alias(GetResponseForExceptionEvent::class, KernelExceptionEvent::class); - } -} + class_alias(ExceptionEvent::class, KernelExceptionEvent::class); +} \ No newline at end of file diff --git a/Listener/RequestListener.php b/Listener/RequestListener.php index f8fa6a8..2372f8c 100644 --- a/Listener/RequestListener.php +++ b/Listener/RequestListener.php @@ -17,7 +17,6 @@ use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; use Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -51,9 +50,9 @@ public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => [ - ['setApplicationName', 255], - ['setIgnoreTransaction', 31], - ['setTransactionName', -10], + ['setApplicationName', 255], + ['setIgnoreTransaction', 31], + ['setTransactionName', -10], ], ]; } @@ -112,14 +111,10 @@ public function setIgnoreTransaction(KernelRequestEvent $event): void */ private function isEventValid(KernelRequestEvent $event): bool { - return HttpKernelInterface::MASTER_REQUEST === $event->getRequestType(); + return HttpKernelInterface::MAIN_REQUEST === $event->getRequestType(); } } if (!class_exists(KernelRequestEvent::class)) { - if (class_exists(RequestEvent::class)) { - class_alias(RequestEvent::class, KernelRequestEvent::class); - } else { - class_alias(GetResponseEvent::class, KernelRequestEvent::class); - } -} + class_alias(RequestEvent::class, KernelRequestEvent::class); +} \ No newline at end of file diff --git a/Listener/ResponseListener.php b/Listener/ResponseListener.php index a299abc..61670af 100644 --- a/Listener/ResponseListener.php +++ b/Listener/ResponseListener.php @@ -18,30 +18,18 @@ use Ekino\NewRelicBundle\Twig\NewRelicExtension; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\StreamedResponse; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; class ResponseListener implements EventSubscriberInterface { - private $newRelic; - private $interactor; - private $instrument; - private $symfonyCache; - private $newRelicTwigExtension; - public function __construct( - Config $newRelic, - NewRelicInteractorInterface $interactor, - bool $instrument = false, - bool $symfonyCache = false, - NewRelicExtension $newRelicTwigExtension = null + private Config $newRelic, + private NewRelicInteractorInterface $interactor, + private bool $instrument = false, + private bool $symfonyCache = false, + private ?NewRelicExtension $newRelicTwigExtension = null, ) { - $this->newRelic = $newRelic; - $this->interactor = $interactor; - $this->instrument = $instrument; - $this->symfonyCache = $symfonyCache; - $this->newRelicTwigExtension = $newRelicTwigExtension; } public static function getSubscribedEvents(): array @@ -55,7 +43,7 @@ public static function getSubscribedEvents(): array public function onKernelResponse(KernelResponseEvent $event): void { - $isMainRequest = method_exists($event, 'isMainRequest') ? $event->isMainRequest() : $event->isMasterRequest(); + $isMainRequest = $event->isMainRequest(); if (!$isMainRequest) { return; @@ -113,9 +101,5 @@ public function onKernelResponse(KernelResponseEvent $event): void } if (!class_exists(KernelResponseEvent::class)) { - if (class_exists(ResponseEvent::class)) { - class_alias(ResponseEvent::class, KernelResponseEvent::class); - } else { - class_alias(FilterResponseEvent::class, KernelResponseEvent::class); - } -} + class_alias(ResponseEvent::class, KernelResponseEvent::class); +} \ No newline at end of file diff --git a/Tests/AppKernel.php b/Tests/AppKernel.php index 9e3b397..e26c3e7 100644 --- a/Tests/AppKernel.php +++ b/Tests/AppKernel.php @@ -89,7 +89,7 @@ public function registerBundles(): iterable * (From MicroKernelTrait) * {@inheritdoc} */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(function (ContainerBuilder $container) { $container->loadFromExtension('framework', [ @@ -100,21 +100,19 @@ public function registerContainerConfiguration(LoaderInterface $loader) ], ]); - // Not setting the router to utf8 is deprecated in symfony 5.1 - if (Kernel::VERSION_ID >= 50100) { + // Fix deprecations in symfony 6 + if (Kernel::VERSION_ID >= 60100) { $container->loadFromExtension('framework', [ - 'router' => ['utf8' => true], - ]); - } - - // Not setting the "framework.session.storage_factory_id" configuration option is deprecated in symfony 5.3 - if (Kernel::VERSION_ID >= 50300) { - $container->loadFromExtension('framework', [ - 'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'], - ]); - } else { - $container->loadFromExtension('framework', [ - 'session' => ['storage_id' => 'session.storage.mock_file'], + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'session' => [ + 'cookie_secure' => 'auto', + 'cookie_samesite' => 'lax', + 'handler_id' => null, + ], + 'php_errors' => [ + 'log' => true, + ], ]); } @@ -140,7 +138,7 @@ protected function buildContainer(): ContainerBuilder $container = parent::buildContainer(); $container->addCompilerPass(new class() implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $id => $definition) { if (preg_match('|Ekino.*|i', $id)) { @@ -158,4 +156,4 @@ public function process(ContainerBuilder $container) return $container; } -} +} \ No newline at end of file diff --git a/Tests/BundleInitializationTest.php b/Tests/BundleInitializationTest.php index 27a07a0..256717b 100644 --- a/Tests/BundleInitializationTest.php +++ b/Tests/BundleInitializationTest.php @@ -27,12 +27,12 @@ */ class BundleInitializationTest extends TestCase { - protected function getBundleClass() + protected function getBundleClass(): string { return EkinoNewRelicBundle::class; } - public function testInitBundle() + public function testInitBundle(): void { $kernel = new AppKernel(uniqid('cache')); $kernel->boot(); diff --git a/Tests/Listener/CommandListenerTest.php b/Tests/Listener/CommandListenerTest.php index 9e250bf..af0c79d 100644 --- a/Tests/Listener/CommandListenerTest.php +++ b/Tests/Listener/CommandListenerTest.php @@ -28,7 +28,7 @@ class CommandListenerTest extends TestCase { - public function testCommandMarkedAsBackgroundJob() + public function testCommandMarkedAsBackgroundJob(): void { if (!class_exists('Symfony\Component\Console\Event\ConsoleCommandEvent')) { $this->markTestSkipped('Console Events is only available from Symfony 2.3'); @@ -68,7 +68,7 @@ public function testCommandMarkedAsBackgroundJob() $listener->onConsoleCommand($event); } - public function testIgnoreBackgroundJob() + public function testIgnoreBackgroundJob(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->never())->method('startTransaction'); @@ -84,7 +84,7 @@ public function testIgnoreBackgroundJob() $listener->onConsoleCommand($event); } - public function testConsoleError() + public function testConsoleError(): void { $exception = new \Exception('', 1); @@ -103,7 +103,7 @@ public function testConsoleError() $listener->onConsoleError($event); } - public function testConsoleErrorsWithThrowable() + public function testConsoleErrorsWithThrowable(): void { $exception = new \Error(); diff --git a/Tests/Listener/DeprecationListenerTest.php b/Tests/Listener/DeprecationListenerTest.php index 5354bcf..169f45d 100644 --- a/Tests/Listener/DeprecationListenerTest.php +++ b/Tests/Listener/DeprecationListenerTest.php @@ -20,7 +20,7 @@ class DeprecationListenerTest extends TestCase { - public function testDeprecationIsReported() + public function testDeprecationIsReported(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('noticeThrowable')->with( @@ -39,7 +39,7 @@ public function testDeprecationIsReported() } } - public function testDeprecationIsReportedRegardlessErrorReporting() + public function testDeprecationIsReportedRegardlessErrorReporting(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('noticeThrowable'); @@ -58,7 +58,7 @@ public function testDeprecationIsReportedRegardlessErrorReporting() } } - public function testOtherErrorAreIgnored() + public function testOtherErrorAreIgnored(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->never())->method('noticeThrowable'); @@ -75,7 +75,7 @@ public function testOtherErrorAreIgnored() } } - public function testInitialHandlerIsCalled() + public function testInitialHandlerIsCalled(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('noticeThrowable'); @@ -95,7 +95,7 @@ public function testInitialHandlerIsCalled() } } - public function testUnregisterRemovesHandler() + public function testUnregisterRemovesHandler(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->never())->method('noticeThrowable'); @@ -112,7 +112,7 @@ public function testUnregisterRemovesHandler() } } - public function testUnregisterRestorePreviousHandler() + public function testUnregisterRestorePreviousHandler(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); diff --git a/Tests/Listener/ExceptionListenerTest.php b/Tests/Listener/ExceptionListenerTest.php index a1b59f1..259ff2d 100644 --- a/Tests/Listener/ExceptionListenerTest.php +++ b/Tests/Listener/ExceptionListenerTest.php @@ -34,14 +34,14 @@ public function testOnKernelException() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); - $eventClass = class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class; + $eventClass = ExceptionEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception); $listener = new ExceptionListener($interactor); $listener->onKernelException($event); } - public function testOnKernelExceptionWithHttp() + public function testOnKernelExceptionWithHttp(): void { $exception = new BadRequestHttpException('Boom'); @@ -51,10 +51,10 @@ public function testOnKernelExceptionWithHttp() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); - $eventClass = class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class; + $eventClass = ExceptionEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception); $listener = new ExceptionListener($interactor); $listener->onKernelException($event); } -} +} \ No newline at end of file diff --git a/Tests/Listener/RequestListenerTest.php b/Tests/Listener/RequestListenerTest.php index 72a4bd4..e875263 100644 --- a/Tests/Listener/RequestListenerTest.php +++ b/Tests/Listener/RequestListenerTest.php @@ -26,7 +26,7 @@ class RequestListenerTest extends TestCase { - public function testSubRequest() + public function testSubRequest(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->never())->method('setTransactionName'); @@ -35,14 +35,13 @@ public function testSubRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, new Response()); + $event = new RequestEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); $listener->setApplicationName($event); } - public function testMasterRequest() + public function testMasterRequest(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('setTransactionName'); @@ -54,14 +53,14 @@ public function testMasterRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); $listener->setTransactionName($event); } - public function testPathIsIgnored() + public function testPathIsIgnored(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('ignoreTransaction'); @@ -71,14 +70,14 @@ public function testPathIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], [], [], [], ['REQUEST_URI' => '/ignored_path']); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], ['/ignored_path'], $namingStrategy); $listener->setIgnoreTransaction($event); } - public function testRouteIsIgnored() + public function testRouteIsIgnored(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('ignoreTransaction'); @@ -88,14 +87,14 @@ public function testRouteIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], ['_route' => 'ignored_route']); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, ['ignored_route'], [], $namingStrategy); $listener->setIgnoreTransaction($event); } - public function testSymfonyCacheEnabled() + public function testSymfonyCacheEnabled(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->once())->method('startTransaction'); @@ -104,14 +103,14 @@ public function testSymfonyCacheEnabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, true); $listener->setApplicationName($event); } - public function testSymfonyCacheDisabled() + public function testSymfonyCacheDisabled(): void { $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); $interactor->expects($this->never())->method('startTransaction'); @@ -120,10 +119,10 @@ public function testSymfonyCacheDisabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, false); $listener->setApplicationName($event); } -} +} \ No newline at end of file diff --git a/Tests/Listener/ResponseListenerTest.php b/Tests/Listener/ResponseListenerTest.php index b8107d7..3094779 100644 --- a/Tests/Listener/ResponseListenerTest.php +++ b/Tests/Listener/ResponseListenerTest.php @@ -18,14 +18,21 @@ use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; use Ekino\NewRelicBundle\Twig\NewRelicExtension; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; class ResponseListenerTest extends TestCase { + private NewRelicInteractorInterface $interactor; + + private Config $newRelic; + + private NewRelicExtension $extension; + protected function setUp(): void { $this->interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); @@ -39,7 +46,7 @@ protected function setUp(): void ->getMock(); } - public function testOnKernelResponseOnlyMasterRequestsAreProcessed() + public function testOnKernelResponseOnlyMasterRequestsAreProcessed(): void { $event = $this->createFilterResponseEventDummy(null, null, HttpKernelInterface::SUB_REQUEST); @@ -49,7 +56,7 @@ public function testOnKernelResponseOnlyMasterRequestsAreProcessed() $this->newRelic->expects($this->never())->method('getCustomMetrics'); } - public function testOnKernelResponseWithOnlyCustomMetricsAndParameters() + public function testOnKernelResponseWithOnlyCustomMetricsAndParameters(): void { $events = [ 'WidgetSale' => [ @@ -103,7 +110,7 @@ public function testOnKernelResponseWithOnlyCustomMetricsAndParameters() $object->onKernelResponse($event); } - public function testOnKernelResponseInstrumentDisabledInRequest() + public function testOnKernelResponseInstrumentDisabledInRequest(): void { $this->setupNoCustomMetricsOrParameters(); @@ -115,7 +122,7 @@ public function testOnKernelResponseInstrumentDisabledInRequest() $object->onKernelResponse($event); } - public function testSymfonyCacheEnabled() + public function testSymfonyCacheEnabled(): void { $this->setupNoCustomMetricsOrParameters(); @@ -127,7 +134,7 @@ public function testSymfonyCacheEnabled() $object->onKernelResponse($event); } - public function testSymfonyCacheDisabled() + public function testSymfonyCacheDisabled(): void { $this->setupNoCustomMetricsOrParameters(); @@ -142,7 +149,7 @@ public function testSymfonyCacheDisabled() /** * @dataProvider providerOnKernelResponseOnlyInstrumentHTMLResponses */ - public function testOnKernelResponseOnlyInstrumentHTMLResponses($content, $expectsSetContent, $contentType) + public function testOnKernelResponseOnlyInstrumentHTMLResponses($content, $expectsSetContent, $contentType): void { $this->setupNoCustomMetricsOrParameters(); @@ -157,7 +164,7 @@ public function testOnKernelResponseOnlyInstrumentHTMLResponses($content, $expec $object->onKernelResponse($event); } - public function providerOnKernelResponseOnlyInstrumentHTMLResponses() + public function providerOnKernelResponseOnlyInstrumentHTMLResponses(): array { return [ // unsupported content types @@ -179,7 +186,7 @@ public function providerOnKernelResponseOnlyInstrumentHTMLResponses() ]; } - public function testInteractionWithTwigExtensionHeader() + public function testInteractionWithTwigExtensionHeader(): void { $this->newRelic->expects($this->never())->method('getCustomMetrics'); $this->newRelic->expects($this->never())->method('getCustomParameters'); @@ -201,7 +208,7 @@ public function testInteractionWithTwigExtensionHeader() $object->onKernelResponse($event); } - public function testInteractionWithTwigExtensionFooter() + public function testInteractionWithTwigExtensionFooter(): void { $this->newRelic->expects($this->never())->method('getCustomMetrics'); $this->newRelic->expects($this->never())->method('getCustomParameters'); @@ -223,7 +230,7 @@ public function testInteractionWithTwigExtensionFooter() $object->onKernelResponse($event); } - public function testInteractionWithTwigExtensionHeaderFooter() + public function testInteractionWithTwigExtensionHeaderFooter(): void { $this->newRelic->expects($this->never())->method('getCustomMetrics'); $this->newRelic->expects($this->never())->method('getCustomParameters'); @@ -245,7 +252,7 @@ public function testInteractionWithTwigExtensionHeaderFooter() $object->onKernelResponse($event); } - private function setUpNoCustomMetricsOrParameters() + private function setUpNoCustomMetricsOrParameters(): void { $this->newRelic->expects($this->once())->method('getCustomEvents')->willReturn([]); $this->newRelic->expects($this->once())->method('getCustomMetrics')->willReturn([]); @@ -256,24 +263,27 @@ private function setUpNoCustomMetricsOrParameters() $this->interactor->expects($this->never())->method('addCustomParameter'); } - private function createRequestMock($instrumentEnabled = true) + private function createRequestMock($instrumentEnabled = true): Request { $mock = $this->getMockBuilder(Request::class) ->setMethods(['get']) ->getMock(); - $mock->attributes = $mock; + $mock->attributes = new ParameterBag(['_instrument' => $instrumentEnabled]); $mock->expects($this->any())->method('get')->willReturn($instrumentEnabled); return $mock; } - private function createResponseMock($content = null, $expectsSetContent = null, $contentType = 'text/html') - { + private function createResponseMock( + $content = null, + $expectsSetContent = null, + $contentType = 'text/html', + ): Response { $mock = $this->getMockBuilder(Response::class) ->setMethods(['get', 'getContent', 'setContent']) ->getMock(); - $mock->headers = $mock; + $mock->headers = new ResponseHeaderBag(['Content-Type' => $contentType]); $mock->expects($this->any())->method('get')->willReturn($contentType); $mock->expects($content ? $this->any() : $this->never())->method('getContent')->willReturn($content ?? false); @@ -287,13 +297,13 @@ private function createResponseMock($content = null, $expectsSetContent = null, return $mock; } - private function createFilterResponseEventDummy(Request $request = null, Response $response = null, int $requestType = HttpKernelInterface::MASTER_REQUEST) - { + private function createFilterResponseEventDummy( + Request $request = null, + Response $response = null, + int $requestType = HttpKernelInterface::MAIN_REQUEST, + ): ResponseEvent { $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(ResponseEvent::class) ? ResponseEvent::class : FilterResponseEvent::class; - $event = new $eventClass($kernel, $request ?? new Request(), $requestType, $response ?? new Response()); - - return $event; + return new ResponseEvent($kernel, $request ?? new Request(), $requestType, $response ?? new Response()); } -} +} \ No newline at end of file diff --git a/composer.json b/composer.json index 53e57a4..5425780 100644 --- a/composer.json +++ b/composer.json @@ -13,27 +13,23 @@ } ], "require": { - "php": "^7.1 | ^8.0", - "monolog/monolog": "^3.0", - "symfony/config": "^3.4|^4.0|^5.0|^6.0", - "symfony/console": "^3.4|^4.0|^5.0|^6.0", - "symfony/dependency-injection": "^3.4|^4.0|^5.0|^6.0", - "symfony/event-dispatcher": "^3.4|^4.0|^5.0|^6.0", - "symfony/http-kernel": "^3.4|^4.0|^5.0|^6.0" + "php": "^8.1", + "symfony/config": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/event-dispatcher": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "monolog/monolog": "^3.0" }, "require-dev": { - "matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0", - "symfony/framework-bundle": "^3.4|^4.0|^5.0|^6.0", - "symfony/phpunit-bridge": "^5.3", - "symfony/debug": ">3.4.21", - "twig/twig": "^1.32|^2.4", - "symfony/monolog-bundle": "^3.2" - }, - "conflict": { - "twig/twig": "<1.32" + "matthiasnoback/symfony-dependency-injection-test": "^4.3|^5.1", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/phpunit-bridge": "^5.3|^6.0|^7.0", + "twig/twig": "^1.32|^2.4|^3.0", + "symfony/monolog-bundle": "^3.10" }, "suggest": { - "symfony/monolog-bundle": "^3.2" + "symfony/monolog-bundle": "^3.10" }, "autoload": { "psr-4": { "Ekino\\NewRelicBundle\\": "" }, @@ -49,4 +45,4 @@ "dev-master": "2.0-dev" } } -} +} \ No newline at end of file