From a49d879e3d62b89ebcc74f3f7787e0983cb8265f Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Tue, 4 Oct 2022 12:13:33 +0200 Subject: [PATCH] [Symfony 6] Remove setting services for test as public --- .../Symfony6PrivateServicesPass.php | 6 ------ tests/Api/Shop/OrdersTest.php | 10 +++++----- tests/Api/Shop/PaymentMethodsTest.php | 6 +++--- tests/Api/Shop/ShippingMethodsTest.php | 2 +- tests/Api/Utils/OrderPlacerTrait.php | 2 +- tests/Controller/SessionAwareAjaxTest.php | 4 ++-- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/BackwardsCompatibility/Symfony6PrivateServicesPass.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/BackwardsCompatibility/Symfony6PrivateServicesPass.php index 543d733f0ca..1e5864dc722 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/BackwardsCompatibility/Symfony6PrivateServicesPass.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/BackwardsCompatibility/Symfony6PrivateServicesPass.php @@ -20,12 +20,6 @@ public function process(ContainerBuilder $container): void $this->makeServicePublic('security.csrf.token_manager', $container); $this->makeServicePublic('security.token_storage', $container); $this->makeServicePublic('validator', $container); - - if (str_starts_with((string) $container->getParameter('kernel.environment'), 'test')) { - $this->makeServicePublic('filesystem', $container); - $this->makeServicePublic('session.factory', $container); - $this->makeServicePublic('sylius.command_bus', $container); - } } private function makeServicePublic(string $serviceId, ContainerBuilder $container): void diff --git a/tests/Api/Shop/OrdersTest.php b/tests/Api/Shop/OrdersTest.php index 0a3cee15cb6..36da75c7baa 100644 --- a/tests/Api/Shop/OrdersTest.php +++ b/tests/Api/Shop/OrdersTest.php @@ -38,7 +38,7 @@ public function it_gets_an_order(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue); $pickupCartCommand->setChannelCode('WEB'); @@ -74,7 +74,7 @@ public function it_gets_order_items(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue); $pickupCartCommand->setChannelCode('WEB'); @@ -99,7 +99,7 @@ public function it_gets_order_adjustments(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue); $pickupCartCommand->setChannelCode('WEB'); @@ -123,7 +123,7 @@ public function it_gets_order_item_adjustments(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue); $pickupCartCommand->setChannelCode('WEB'); @@ -162,7 +162,7 @@ public function it_allows_to_add_items_to_order(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue); $pickupCartCommand->setChannelCode('WEB'); diff --git a/tests/Api/Shop/PaymentMethodsTest.php b/tests/Api/Shop/PaymentMethodsTest.php index eb407139c85..9bf2f3d46e4 100644 --- a/tests/Api/Shop/PaymentMethodsTest.php +++ b/tests/Api/Shop/PaymentMethodsTest.php @@ -29,7 +29,7 @@ public function it_gets_available_payment_methods_from_payments(): void $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue, 'en_US'); $pickupCartCommand->setChannelCode('WEB'); @@ -62,7 +62,7 @@ public function it_gets_empty_response_if_only_payment_id_is_set_in_filter(): vo $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue, 'en_US'); $pickupCartCommand->setChannelCode('WEB'); @@ -95,7 +95,7 @@ public function it_gets_empty_response_if_only_cart_token_is_set_in_filter(): vo $tokenValue = 'nAWw2jewpA'; /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue, 'en_US'); $pickupCartCommand->setChannelCode('WEB'); diff --git a/tests/Api/Shop/ShippingMethodsTest.php b/tests/Api/Shop/ShippingMethodsTest.php index 0901fc4aa46..78e79fd5ae7 100644 --- a/tests/Api/Shop/ShippingMethodsTest.php +++ b/tests/Api/Shop/ShippingMethodsTest.php @@ -190,7 +190,7 @@ public function it_returns_empty_list_of_available_shipping_methods_for_not_exis private function getCartAndPutItemForCustomer(string $tokenValue, string $customer): void { /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue, 'en_US'); $pickupCartCommand->setChannelCode('WEB'); diff --git a/tests/Api/Utils/OrderPlacerTrait.php b/tests/Api/Utils/OrderPlacerTrait.php index 8971c6cea21..9cf91d9b932 100644 --- a/tests/Api/Utils/OrderPlacerTrait.php +++ b/tests/Api/Utils/OrderPlacerTrait.php @@ -30,7 +30,7 @@ trait OrderPlacerTrait protected function placeOrder(string $tokenValue, string $email = 'sylius@example.com'): void { /** @var MessageBusInterface $commandBus */ - $commandBus = $this->get('sylius.command_bus'); + $commandBus = self::getContainer()->get('sylius.command_bus'); $pickupCartCommand = new PickupCart($tokenValue, 'en_US'); $pickupCartCommand->setChannelCode('WEB'); diff --git a/tests/Controller/SessionAwareAjaxTest.php b/tests/Controller/SessionAwareAjaxTest.php index 5a948825ef1..1cf66624f33 100644 --- a/tests/Controller/SessionAwareAjaxTest.php +++ b/tests/Controller/SessionAwareAjaxTest.php @@ -14,11 +14,11 @@ protected function setUp(): void { parent::setUp(); - $requestStack = self::$kernel->getContainer()->get('request_stack'); + $requestStack = self::getContainer()->get('request_stack'); try { $requestStack->getSession(); } catch (SessionNotFoundException) { - $session = self::$kernel->getContainer()->get('session.factory')->createSession(); + $session = self::getContainer()->get('session.factory')->createSession(); $request = new Request(); $request->setSession($session); $requestStack->push($request);