diff --git a/.gitignore b/.gitignore index c53cd4ce87..6275a012ab 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ yarn-error.log /assets/js/translations.json /assets/js/bundles + +/.phpunit.result.cache diff --git a/build/codeception.yml b/build/codeception.yml index 0f958716e2..21dca4ddb7 100644 --- a/build/codeception.yml +++ b/build/codeception.yml @@ -8,6 +8,5 @@ paths: params: - ../config/parameters_test.yml settings: - bootstrap: _bootstrap.php colors: true memory_limit: 1024M diff --git a/composer.json b/composer.json index f5ef4ffe0d..87fa2ea372 100644 --- a/composer.json +++ b/composer.json @@ -52,18 +52,17 @@ "incenteev/composer-parameter-handler": "^2.1.3", "intervention/image": "^2.3.14", "jms/serializer-bundle": "^2.4", - "jms/translation-bundle": "^1.4.1", + "jms/translation-bundle": "^1.4.4", "joschi127/doctrine-entity-override-bundle": "^0.7.2", "league/flysystem": "^1.0", "phing/phing": "^2.16.1", "presta/sitemap-bundle": "^1.5.3", "prezent/doctrine-translatable-bundle": "^1.0.3", - "sensio/framework-extra-bundle": "^3.0.29", - "sensio/generator-bundle": "^3.1.7", + "sensio/framework-extra-bundle": "^5.2", "sensiolabs/security-checker": "^6.0", "shopsys/doctrine-orm": "^2.6.2", "shopsys/google-cloud-bundle": "9.0.x-dev", - "shopsys/postgres-search-bundle": "^0.1", + "shopsys/postgres-search-bundle": "^0.2", "shopsys/migrations": "9.0.x-dev", "shopsys/form-types-bundle": "9.0.x-dev", "shopsys/framework": "9.0.x-dev", @@ -78,49 +77,50 @@ "stof/doctrine-extensions-bundle": "^1.3.0", "symfony-cmf/routing": "^2.0.3", "symfony-cmf/routing-bundle": "^2.0.3", - "symfony/debug": "^3.4", - "symfony/debug-bundle": "^3.4", - "symfony/dotenv": "^3.4", + "symfony/debug": "^4.4.0", + "symfony/debug-bundle": "^4.4.0", + "symfony/dotenv": "^4.4.0", "symfony/flex": "^1.4", - "symfony/form": "^3.4", - "symfony/monolog-bridge": "^3.0.0", - "symfony/monolog-bundle": "~3.4.0", - "symfony/property-info": "^3.4", - "symfony/proxy-manager-bridge": "^3.4", - "symfony/security-bundle": "^3.4", + "symfony/form": "^4.4.0", + "symfony/monolog-bridge": "^4.4.0", + "symfony/monolog-bundle": "~3.5.0", + "symfony/property-info": "^4.4.0", + "symfony/proxy-manager-bridge": "^4.4.0", + "symfony/security-bundle": "^4.4.0", "symfony/swiftmailer-bundle": "^3.2.2", - "symfony/templating": "^3.4", - "symfony/translation": "^3.4", - "symfony/twig-bundle": "^3.4", - "symfony/validator": "^3.4", - "symfony/web-link": "^3.4", - "symfony/web-profiler-bundle": "^3.4", - "symfony/web-server-bundle": "^3.4", + "symfony/translation": "^4.4.0", + "symfony/twig-bundle": "^4.4.0", + "symfony/validator": "^4.4.0", + "symfony/web-link": "^4.4.0", + "symfony/web-profiler-bundle": "^4.4.0", + "symfony/web-server-bundle": "^4.4.0", "symfony/webpack-encore-bundle": "^1.7", - "symfony/workflow": "^3.4", + "symfony/workflow": "^4.4.0", "tracy/tracy": "^2.4.13", "twig/extensions": "^1.5.1", - "twig/twig": "^2.4.8", - "vasek-purchart/console-errors-bundle": "^1.0.1", + "twig/twig": "^2.9", + "vasek-purchart/console-errors-bundle": "^3.0.0", "webmozart/assert": "^1.4" }, "require-dev": { "ext-pgsql": "*", "ext-zip": "*", - "codeception/codeception": "^2.4.0", - "phpstan/phpstan": "^0.11", - "symfony/var-dumper": "^3.4", - "phpunit/phpunit": "^7.0", + "codeception/codeception": "^4.1", + "codeception/module-db": "^1.0", + "codeception/module-webdriver": "^1.0", + "codeception/phpunit-wrapper": "^8.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-doctrine": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^8.0", "shopsys/coding-standards": "9.0.x-dev", "shopsys/http-smoke-testing": "9.0.x-dev", - "phpstan/phpstan-doctrine": "^0.11.2", - "phpstan/phpstan-phpunit": "^0.11.2", - "sspooky13/yaml-standards": "^4.2.5", - "zalas/phpunit-injector": "^1.2" + "sspooky13/yaml-standards": "^5.0.0", + "symfony/var-dumper": "^4.4.0", + "symfony/browser-kit": "^4.4.0", + "zalas/phpunit-injector": "^1.4" }, "conflict": { - "symfony/dependency-injection": "3.4.15|3.4.16", - "twig/twig": "2.6.1", "symfony/symfony": "*" }, "scripts": { @@ -160,7 +160,7 @@ }, "symfony": { "allow-contrib": true, - "require": "^3.4" + "require": "^4.4" }, "incenteev-parameters": [ { diff --git a/config/bundles.php b/config/bundles.php index ed86a76c22..9d6dcf19f7 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -16,7 +16,6 @@ Presta\SitemapBundle\PrestaSitemapBundle::class => ['all' => true], Prezent\Doctrine\TranslatableBundle\PrezentDoctrineTranslatableBundle::class => ['all' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], - Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle::class => ['all' => true], Shopsys\FormTypesBundle\ShopsysFormTypesBundle::class => ['all' => true], Shopsys\FrontendApiBundle\ShopsysFrontendApiBundle::class => ['all' => true], Shopsys\GoogleCloudBundle\ShopsysGoogleCloudBundle::class => ['all' => true], diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 57b7aea83c..04395720da 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -12,8 +12,12 @@ doctrine: # See \Doctrine\DBAL\Connection::getDatabasePlatformVersion(). server_version: "%database_server_version%" types: - money: \Shopsys\FrameworkBundle\Component\Doctrine\MoneyType - + money: + class: \Shopsys\FrameworkBundle\Component\Doctrine\MoneyType + commented: false + tsvector: + class: \Intaro\PostgresSearchBundle\DBAL\TsvectorType + commented: false orm: auto_generate_proxy_classes: false dql: diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 5f3547f1ec..b028642b2f 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -7,8 +7,6 @@ framework: form: ~ csrf_protection: ~ validation: { enable_annotations: true } - templating: - engines: ['twig'] trusted_hosts: ~ session: handler_id: snc_redis.session.handler @@ -22,3 +20,4 @@ framework: enabled: false collect: false assets: ~ + error_controller: 'App\Controller\Front\ErrorController::showAction' diff --git a/config/packages/framework_extra.yml b/config/packages/framework_extra.yml new file mode 100644 index 0000000000..1821ccc079 --- /dev/null +++ b/config/packages/framework_extra.yml @@ -0,0 +1,3 @@ +sensio_framework_extra: + router: + annotations: false diff --git a/config/packages/security.yml b/config/packages/security.yml index 0d8967ae22..da4247d25d 100644 --- a/config/packages/security.yml +++ b/config/packages/security.yml @@ -21,7 +21,6 @@ security: user_checker: Shopsys\FrameworkBundle\Model\Security\AdministratorChecker anonymous: ~ provider: administrators - logout_on_user_change: true access_denied_url: "/admin/access-denied/" form_login: check_path: admin_login_check @@ -42,7 +41,6 @@ security: pattern: ^/ anonymous: ~ provider: user_identities - logout_on_user_change: true form_login: check_path: front_login_check login_path: front_login diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 0b1d1f9a02..f51754f4ca 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,6 +1,6 @@ twig: debug: "%kernel.debug%" - exception_controller: 'App\Controller\Front\ErrorController::showAction' + exception_controller: null form_themes: - '@ShopsysFramework/Common/Form/theme.html.twig' - '@ShopsysFramework/Admin/Form/colorpickerFields.html.twig' diff --git a/config/services.yaml b/config/services.yaml index 3bd16b2521..a2fdbb064b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -96,3 +96,16 @@ services: App\Controller\Front\ErrorController: arguments: $environment: '%kernel.environment%' + + App\Controller\Front\RobotsController: + arguments: + $sitemapsUrlPrefix: '%shopsys.sitemaps_url_prefix%' + + Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory: ~ + + sensio_framework_extra.psr7.http_message_factory: + class: Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory + + Psr\Http\Message\ServerRequestInterface: + factory: ['@Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory', 'createRequest'] + arguments: ['@=service("request_stack").getMasterRequest()'] diff --git a/config/services_test.yml b/config/services_test.yml index 6ba10217c9..bb5f272d88 100644 --- a/config/services_test.yml +++ b/config/services_test.yml @@ -1,18 +1,15 @@ imports: - { resource: parameters_test.yml } +framework: + test: true + services: _defaults: autowire: true autoconfigure: true public: true - Shopsys\FrameworkBundle\Component\Localization\DateTimeFormatter: - factory: ['@Shopsys\FrameworkBundle\Model\Localization\CustomDateTimeFormatterFactory', create] - - CommerceGuys\Intl\Currency\CurrencyRepositoryInterface: - class: Shopsys\FrameworkBundle\Model\Localization\IntlCurrencyRepository - Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver: class: Tests\App\Functional\EntityExtension\OverwritableEntityNameResolver arguments: @@ -20,69 +17,54 @@ services: Tests\App\Functional\EntityExtension\OverwritableEntityNameResolver: '@Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver' - joschi127_doctrine_entity_override.event_subscriber.load_orm_metadata: - class: Tests\App\Functional\EntityExtension\OverwritableLoadORMMetadataSubscriber + Tests\App\Functional\EntityExtension\OverwritableLoadORMMetadataSubscriber: arguments: - "@service_container" - "%shopsys.entity_extension.map%" tags: - { name: doctrine.event_subscriber, priority: -10 } - League\Flysystem\FilesystemInterface: '@main_filesystem' - - Shopsys\FrameworkBundle\Model\Article\ArticleFactoryInterface: '@Shopsys\FrameworkBundle\Model\Article\ArticleFactory' - - Shopsys\FrameworkBundle\Model\Article\ArticleFactory: ~ + Symfony\Bridge\Twig\Extension\HttpKernelRuntime: + arguments: ['@fragment.handler'] - Shopsys\FrameworkBundle\Model\Article\ArticleDataFactoryInterface: '@App\Model\Article\ArticleDataFactory' - - Shopsys\FrameworkBundle\Model\Administrator\AdministratorDataFactoryInterface: '@App\Model\Administrator\AdministratorDataFactory' - - Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface: '@App\Model\Category\CategoryDataFactory' - - Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserDataFactoryInterface: '@App\Model\Customer\User\CustomerUserDataFactory' - - Shopsys\FrameworkBundle\Model\Order\Item\OrderItemDataFactoryInterface: '@App\Model\Order\Item\OrderItemDataFactory' - - Shopsys\FrameworkBundle\Model\Order\Item\OrderItemFactoryInterface: '@Shopsys\FrameworkBundle\Model\Order\Item\OrderItemFactory' + Shopsys\FrameworkBundle\Model\Pricing\PriceConverter: ~ - Shopsys\FrameworkBundle\Model\Order\OrderDataFactoryInterface: '@App\Model\Order\OrderDataFactory' + Shopsys\FrameworkBundle\Model\Localization\IntlCurrencyRepository: ~ - Shopsys\FrameworkBundle\Model\Transport\TransportDataFactoryInterface: '@App\Model\Transport\TransportDataFactory' + Shopsys\FrameworkBundle\Model\Feed\FeedFacade: ~ - Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityDataFactoryInterface: '@Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityDataFactory' + Shopsys\FrameworkBundle\Component\Router\Security\RouteCsrfProtector: ~ - Shopsys\FrameworkBundle\Model\Payment\PaymentDataFactoryInterface: '@App\Model\Payment\PaymentDataFactory' + Shopsys\FrameworkBundle\Component\DataFixture\PersistentReferenceFacade: ~ - Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface: '@App\Model\Product\ProductDataFactory' + Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory: + arguments: ['%router.resource%'] - Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityDataFactory: ~ + Shopsys\ReadModelBundle\Image\ImageViewFacade: ~ - Shopsys\FrameworkBundle\Model\Product\Elasticsearch\ProductExportRepository: ~ + Shopsys\ReadModelBundle\Product\Action\ProductActionViewFacade: ~ - Shopsys\FrameworkBundle\Model\Product\Brand\BrandDataFactoryInterface: '@App\Model\Product\Brand\BrandDataFactory' + Shopsys\FrameworkBundle\Component\Image\ImageFacade: + arguments: ['%shopsys.image_url_prefix%'] - Shopsys\ReadModelBundle\Product\Action\ProductActionViewFacade: ~ + Shopsys\FrameworkBundle\Component\Image\ImageLocator: + arguments: ['%shopsys.image_dir%'] - Shopsys\ReadModelBundle\Product\Listed\ListedProductViewFacade: ~ + League\Flysystem\FilesystemInterface: '@main_filesystem' - Shopsys\ReadModelBundle\Product\Listed\ListedProductViewFacadeInterface: '@Shopsys\ReadModelBundle\Product\Listed\ListedProductViewElasticFacade' + Shopsys\FrameworkBundle\Component\Router\CurrentDomainRouter: + tags: + - { name: router, priority: 70 } Shopsys\FrameworkBundle\Model\Localization\Localization: arguments: $adminLocale: '%shopsys.admin_locale%' - Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory: - arguments: ['%router.resource%'] + CommerceGuys\Intl\Currency\CurrencyRepositoryInterface: + class: Shopsys\FrameworkBundle\Model\Localization\IntlCurrencyRepository Shopsys\FrameworkBundle\Component\CurrencyFormatter\CurrencyFormatterFactory: ~ - Shopsys\FrameworkBundle\Model\Localization\IntlCurrencyRepository: ~ - Shopsys\FrameworkBundle\Twig\NumberFormatterExtension: ~ - Shopsys\FrameworkBundle\Model\Administration\AdministrationFacade: ~ - - Shopsys\FrameworkBundle\Model\Pricing\PriceConverter: ~ - Shopsys\FrameworkBundle\Model\Pricing\Rounding: ~ diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index ab6cddfc3c..9d49401dc5 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -51,3 +51,12 @@ parameters: Shopsys\CodingStandards\Sniffs\ForbiddenDoctrineInheritanceSniff: - '*/src/*' - '*/tests/App/*' + + PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff.Underscore: + - '*/tests/App/Test/Codeception/Helper/CloseNewlyOpenedWindowsHelper.php' + - '*/tests/App/Test/Codeception/Helper/DatabaseHelper.php' + - '*/tests/App/Test/Codeception/Helper/DomainHelper.php' + - '*/tests/App/Test/Codeception/Helper/LocalizationHelper.php' + - '*/tests/App/Test/Codeception/Helper/NumberFormatHelper.php' + - '*/tests/App/Test/Codeception/Helper/SymfonyHelper.php' + - '*/tests/App/Test/Codeception/Module/Db.php' diff --git a/phpstan.neon b/phpstan.neon index a119eddb4a..08b3972651 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,37 +1,24 @@ parameters: + + treatPhpDocTypesAsCertain: false + ignoreErrors: + - + # We need to have undefined variable for testing purposes + message: '#^Undefined variable: \$undefined$#' + path: %currentWorkingDirectory%/project-base/src/Controller/Test/ErrorHandlerController.php + - + # We need to have undefined variable for testing purposes + message: '#^Expression "\$undefined\[42\]" on a separate line does not do anything\.$#' + path: %currentWorkingDirectory%/project-base/src/Controller/Test/ErrorHandlerController.php - # Ignore annotations in generated code - message: '#^PHPDoc tag @(param|return) has invalid value (.|\n)+ expected TOKEN_IDENTIFIER at offset \d+$#' - path: %currentWorkingDirectory%/tests/App/Test/Codeception/_generated/AcceptanceTesterActions.php + message: '#^PHPDoc tag @(param|return) has invalid value (.|\n)+ expected type at offset \d+$#' + path: %currentWorkingDirectory%/project-base/tests/App/Test/Codeception/_generated/AcceptanceTesterActions.php - # Ignore annotations in generated code message: '#^PHPDoc tag @throws with type .+ is not subtype of Throwable$#' - path: %currentWorkingDirectory%/tests/App/Test/Codeception/_generated/AcceptanceTesterActions.php - - - # In data fixtures, we often access persistent references using $this->getReference() - message: '#^Property (App|Shopsys)\\.+::\$.+ \((App|Shopsys)\\.+\) does not accept object\.$#' - path: %currentWorkingDirectory%/src/DataFixtures/* - - - # In tests, we often grab services using $container->get() or access persistent references using $this->getReference() - message: '#^Property (Shopsys|Tests)\\.+::\$.+ \(.+\) does not accept (object|object\|null)\.$#' - path: %currentWorkingDirectory%/tests/App/* - - - # In tests, there are helper methods for grabbing services using $container->get() - message: '#^Method .+::.+\(\) should return .+ but returns (object|object\|null)\.$#' - path: %currentWorkingDirectory%/tests/App/* - - - # Actually, we are setting an array item using "$array[] = $this->getReference()" - message: '#^Array \(array<.+>\) does not accept object\.$#' - path: %currentWorkingDirectory%/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php - - - # Actually, we are setting an array item using "$array[] = $this->getReference()" - message: '#^Array \(array<.+>\) does not accept object\.$#' - path: %currentWorkingDirectory%/src/DataFixtures/Demo/ProductDataFixture.php - - - # We need to have undefined variable for testing purposes - message: '#^Undefined variable: \$undefined$#' - path: %currentWorkingDirectory%/src/Controller/Test/ErrorHandlerController.php + path: %currentWorkingDirectory%/project-base/tests/App/Test/Codeception/_generated/AcceptanceTesterActions.php includes: - vendor/phpstan/phpstan-doctrine/extension.neon - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/phpunit.xml b/phpunit.xml index d8dffdd1b6..a85f41f08c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,6 +15,8 @@ > + + diff --git a/src/Command/PerformanceDataCommand.php b/src/Command/PerformanceDataCommand.php index 3e7daf36ed..92f07d0ed1 100644 --- a/src/Command/PerformanceDataCommand.php +++ b/src/Command/PerformanceDataCommand.php @@ -8,6 +8,7 @@ use App\DataFixtures\Performance\CustomerUserDataFixture; use App\DataFixtures\Performance\OrderDataFixture; use App\DataFixtures\Performance\ProductDataFixture; +use Shopsys\FrameworkBundle\Command\CommandResultCodes; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -79,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->customerUserDataFixture->load($output); $output->writeln('loading ' . OrderDataFixture::class . ''); $this->orderDataFixture->load($output); + + return CommandResultCodes::RESULT_OK; } } diff --git a/src/Controller/Front/CartController.php b/src/Controller/Front/CartController.php index 27ea522fac..ea0182b0ce 100644 --- a/src/Controller/Front/CartController.php +++ b/src/Controller/Front/CartController.php @@ -122,7 +122,7 @@ public function indexAction(Request $request) } if ($invalidCart) { - $this->getFlashMessageSender()->addErrorFlash( + $this->addErrorFlash( t('Please make sure that you entered right quantity of all items in cart.') ); } @@ -233,18 +233,17 @@ public function addProductAction(Request $request) $this->sendAddProductResultFlashMessage($addProductResult); } catch (\Shopsys\FrameworkBundle\Model\Product\Exception\ProductNotFoundException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Selected product no longer available or doesn\'t exist.')); + $this->addErrorFlash(t('Selected product no longer available or doesn\'t exist.')); } catch (\Shopsys\FrameworkBundle\Model\Cart\Exception\InvalidQuantityException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Please enter valid quantity you want to add to cart.')); + $this->addErrorFlash(t('Please enter valid quantity you want to add to cart.')); } catch (\Shopsys\FrameworkBundle\Model\Cart\Exception\CartException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Unable to add product to cart')); + $this->addErrorFlash(t('Unable to add product to cart')); } } else { // Form errors list in flash message is temporary solution. // We need to determine couse of error when adding product to cart. - $flashMessageBag = $this->get('shopsys.shop.component.flash_message.bag.front'); - $formErrors = $this->errorExtractor->getAllErrorsAsArray($form, $flashMessageBag); - $this->getFlashMessageSender()->addErrorFlashTwig( + $formErrors = $this->errorExtractor->getAllErrorsAsArray($form, $this->getErrorMessages()); + $this->addErrorFlashTwig( t('Unable to add product to cart:
'), [ 'errors' => implode('
  • ', $formErrors), @@ -287,18 +286,17 @@ public function addProductAjaxAction(Request $request) 'ACCESSORIES_ON_BUY' => ModuleList::ACCESSORIES_ON_BUY, ]); } catch (\Shopsys\FrameworkBundle\Model\Product\Exception\ProductNotFoundException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Selected product no longer available or doesn\'t exist.')); + $this->addErrorFlash(t('Selected product no longer available or doesn\'t exist.')); } catch (\Shopsys\FrameworkBundle\Model\Cart\Exception\InvalidQuantityException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Please enter valid quantity you want to add to cart.')); + $this->addErrorFlash(t('Please enter valid quantity you want to add to cart.')); } catch (\Shopsys\FrameworkBundle\Model\Cart\Exception\CartException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Unable to add product to cart')); + $this->addErrorFlash(t('Unable to add product to cart')); } } else { // Form errors list in flash message is temporary solution. // We need to determine couse of error when adding product to cart. - $flashMessageBag = $this->get('shopsys.shop.component.flash_message.bag.front'); - $formErrors = $this->errorExtractor->getAllErrorsAsArray($form, $flashMessageBag); - $this->getFlashMessageSender()->addErrorFlashTwig( + $formErrors = $this->errorExtractor->getAllErrorsAsArray($form, $this->getErrorMessages()); + $this->addErrorFlashTwig( t('Unable to add product to cart:
    '), [ 'errors' => implode('
  • ', $formErrors), @@ -316,7 +314,7 @@ private function sendAddProductResultFlashMessage( AddProductResult $addProductResult ) { if ($addProductResult->getIsNew()) { - $this->getFlashMessageSender()->addSuccessFlashTwig( + $this->addSuccessFlashTwig( t('Product {{ name }} ({{ quantity|formatNumber }} {{ unitName }}) added to the cart'), [ 'name' => $addProductResult->getCartItem()->getName(), @@ -325,7 +323,7 @@ private function sendAddProductResultFlashMessage( ] ); } else { - $this->getFlashMessageSender()->addSuccessFlashTwig( + $this->addSuccessFlashTwig( t('Product {{ name }} added to the cart (total amount {{ quantity|formatNumber }} {{ unitName }})'), [ 'name' => $addProductResult->getCartItem()->getName(), @@ -351,15 +349,15 @@ public function deleteAction(Request $request, int $cartItemId): Response $this->cartFacade->deleteCartItem($cartItemId); - $this->getFlashMessageSender()->addSuccessFlashTwig( + $this->addSuccessFlashTwig( t('Product {{ name }} removed from cart'), ['name' => $productName] ); } catch (\Shopsys\FrameworkBundle\Model\Cart\Exception\InvalidCartItemException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Unable to remove item from cart. The item is probably already removed.')); + $this->addErrorFlash(t('Unable to remove item from cart. The item is probably already removed.')); } } else { - $this->getFlashMessageSender()->addErrorFlash( + $this->addErrorFlash( t('Unable to remove item from cart. The link for removing it probably expired, try it again.') ); } diff --git a/src/Controller/Front/ContactFormController.php b/src/Controller/Front/ContactFormController.php index 547cfffaf2..8167e7116b 100644 --- a/src/Controller/Front/ContactFormController.php +++ b/src/Controller/Front/ContactFormController.php @@ -68,9 +68,9 @@ public function indexAction(Request $request) try { $this->contactFormFacade->sendMail($contactFormData); - $this->getFlashMessageSender()->addSuccessFlash(t('Thank you, your message has been sent.')); + $this->addSuccessFlash(t('Thank you, your message has been sent.')); } catch (\Shopsys\FrameworkBundle\Model\Mail\Exception\MailException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Error occurred when sending email.')); + $this->addErrorFlash(t('Error occurred when sending email.')); } return $this->redirect($this->generateUrl('front_contact')); diff --git a/src/Controller/Front/CustomerController.php b/src/Controller/Front/CustomerController.php index e4e867d3a1..6b766f3e4a 100644 --- a/src/Controller/Front/CustomerController.php +++ b/src/Controller/Front/CustomerController.php @@ -86,7 +86,7 @@ public function __construct( public function editAction(Request $request) { if (!$this->isGranted(Roles::ROLE_LOGGED_CUSTOMER)) { - $this->getFlashMessageSender()->addErrorFlash(t('You have to be logged in to enter this page')); + $this->addErrorFlash(t('You have to be logged in to enter this page')); return $this->redirectToRoute('front_login'); } @@ -105,12 +105,12 @@ public function editAction(Request $request) $this->customerUserFacade->editByCustomerUser($customerUser->getId(), $customerUserUpdateData); - $this->getFlashMessageSender()->addSuccessFlash(t('Your data had been successfully updated')); + $this->addSuccessFlash(t('Your data had been successfully updated')); return $this->redirectToRoute('front_customer_edit'); } if ($form->isSubmitted() && !$form->isValid()) { - $this->getFlashMessageSender()->addErrorFlash(t('Please check the correctness of all data filled.')); + $this->addErrorFlash(t('Please check the correctness of all data filled.')); } return $this->render('Front/Content/Customer/edit.html.twig', [ @@ -121,7 +121,7 @@ public function editAction(Request $request) public function ordersAction() { if (!$this->isGranted(Roles::ROLE_LOGGED_CUSTOMER)) { - $this->getFlashMessageSender()->addErrorFlash(t('You have to be logged in to enter this page')); + $this->addErrorFlash(t('You have to be logged in to enter this page')); return $this->redirectToRoute('front_login'); } @@ -158,7 +158,7 @@ private function orderDetailAction($urlHash = null, $orderNumber = null) { if ($orderNumber !== null) { if (!$this->isGranted(Roles::ROLE_LOGGED_CUSTOMER)) { - $this->getFlashMessageSender()->addErrorFlash(t('You have to be logged in to enter this page')); + $this->addErrorFlash(t('You have to be logged in to enter this page')); return $this->redirectToRoute('front_login'); } @@ -167,7 +167,7 @@ private function orderDetailAction($urlHash = null, $orderNumber = null) /** @var \App\Model\Order\Order $order */ $order = $this->orderFacade->getByOrderNumberAndUser($orderNumber, $customerUser); } catch (\Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('Order not found')); + $this->addErrorFlash(t('Order not found')); return $this->redirectToRoute('front_customer_orders'); } } else { @@ -192,9 +192,7 @@ public function loginAsRememberedUserAction(Request $request) try { $this->loginAsUserFacade->loginAsRememberedUser($request); } catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\CustomerUserNotFoundException $e) { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessageSender $adminFlashMessageSender */ - $adminFlashMessageSender = $this->get('shopsys.shop.component.flash_message.sender.admin'); - $adminFlashMessageSender->addErrorFlash(t('User not found.')); + $this->addErrorFlash(t('User not found.')); return $this->redirectToRoute('admin_customer_list'); } catch (\Shopsys\FrameworkBundle\Model\Security\Exception\LoginAsRememberedUserException $e) { diff --git a/src/Controller/Front/CustomerPasswordController.php b/src/Controller/Front/CustomerPasswordController.php index 7d8f0b5787..c5f74997ab 100644 --- a/src/Controller/Front/CustomerPasswordController.php +++ b/src/Controller/Front/CustomerPasswordController.php @@ -58,7 +58,7 @@ public function resetPasswordAction(Request $request) try { $this->customerUserPasswordFacade->resetPassword($email, $this->domain->getId()); - $this->getFlashMessageSender()->addSuccessFlashTwig( + $this->addSuccessFlashTwig( t('Link to password reset sent to email {{ email }}.'), [ 'email' => $email, @@ -66,7 +66,7 @@ public function resetPasswordAction(Request $request) ); return $this->redirectToRoute('front_registration_reset_password'); } catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\CustomerUserNotFoundByEmailAndDomainException $ex) { - $this->getFlashMessageSender()->addErrorFlashTwig( + $this->addErrorFlashTwig( t('Customer with email address {{ email }} doesn\'t exist. ' . ' Register'), [ @@ -91,7 +91,7 @@ public function setNewPasswordAction(Request $request) $hash = $request->query->get('hash'); if (!$this->customerUserPasswordFacade->isResetPasswordHashValid($email, $this->domain->getId(), $hash)) { - $this->getFlashMessageSender()->addErrorFlash(t('The link to change your password expired.')); + $this->addErrorFlash(t('The link to change your password expired.')); return $this->redirectToRoute('front_homepage'); } @@ -108,7 +108,7 @@ public function setNewPasswordAction(Request $request) $this->authenticator->loginUser($customerUser, $request); } catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\CustomerUserNotFoundByEmailAndDomainException $ex) { - $this->getFlashMessageSender()->addErrorFlashTwig( + $this->addErrorFlashTwig( t('Customer with email address {{ email }} doesn\'t exist. ' . ' Register'), [ @@ -117,10 +117,10 @@ public function setNewPasswordAction(Request $request) ] ); } catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\InvalidResetPasswordHashUserException $ex) { - $this->getFlashMessageSender()->addErrorFlash(t('The link to change your password expired.')); + $this->addErrorFlash(t('The link to change your password expired.')); } - $this->getFlashMessageSender()->addSuccessFlash(t('Password successfully changed')); + $this->addSuccessFlash(t('Password successfully changed')); return $this->redirectToRoute('front_homepage'); } diff --git a/src/Controller/Front/ErrorController.php b/src/Controller/Front/ErrorController.php index 476a63cf86..0bc9920907 100644 --- a/src/Controller/Front/ErrorController.php +++ b/src/Controller/Front/ErrorController.php @@ -74,7 +74,7 @@ public function errorPageAction($code) $this->exceptionController->setDebug(false); $this->exceptionController->setShowErrorPagePrototype(); - throw new \Shopsys\FrameworkBundle\Component\Error\Exception\FakeHttpException($code); + throw new \Shopsys\FrameworkBundle\Component\Error\Exception\FakeHttpException((int)$code); } /** diff --git a/src/Controller/Front/FlashMessageController.php b/src/Controller/Front/FlashMessageController.php index 049183d324..068924bff5 100644 --- a/src/Controller/Front/FlashMessageController.php +++ b/src/Controller/Front/FlashMessageController.php @@ -8,13 +8,10 @@ class FlashMessageController extends FrontBaseController { public function indexAction() { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageBag */ - $flashMessageBag = $this->get('shopsys.shop.component.flash_message.bag.front'); - return $this->render('Front/Inline/FlashMessage/index.html.twig', [ - 'errorMessages' => $flashMessageBag->getErrorMessages(), - 'infoMessages' => $flashMessageBag->getInfoMessages(), - 'successMessages' => $flashMessageBag->getSuccessMessages(), + 'errorMessages' => $this->getErrorMessages(), + 'infoMessages' => $this->getInfoMessages(), + 'successMessages' => $this->getSuccessMessages(), ]); } } diff --git a/src/Controller/Front/FrontBaseController.php b/src/Controller/Front/FrontBaseController.php index 6d64087a37..7db16a7b5f 100644 --- a/src/Controller/Front/FrontBaseController.php +++ b/src/Controller/Front/FrontBaseController.php @@ -4,17 +4,10 @@ namespace App\Controller\Front; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessageTrait; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -class FrontBaseController extends Controller +class FrontBaseController extends AbstractController { - /** - * @return \Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessageSender - */ - public function getFlashMessageSender() - { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessageSender $flashMessageSender */ - $flashMessageSender = $this->get('shopsys.shop.component.flash_message.sender.front'); - return $flashMessageSender; - } + use FlashMessageTrait; } diff --git a/src/Controller/Front/OrderController.php b/src/Controller/Front/OrderController.php index 96d494acf7..13102db52e 100644 --- a/src/Controller/Front/OrderController.php +++ b/src/Controller/Front/OrderController.php @@ -169,9 +169,6 @@ public function __construct( public function indexAction() { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageBag */ - $flashMessageBag = $this->get('shopsys.shop.component.flash_message.bag.front'); - $cart = $this->cartFacade->findCartOfCurrentCustomerUser(); if ($cart === null) { return $this->redirectToRoute('front_cart'); @@ -216,7 +213,7 @@ public function indexAction() if ($isValid) { if ($orderFlow->nextStep()) { $form = $orderFlow->createForm(); - } elseif ($flashMessageBag->isEmpty()) { + } elseif ($this->isFlashMessageBagEmpty()) { $deliveryAddress = $orderData->deliveryAddressSameAsBillingAddress === false ? $frontOrderFormData->deliveryAddress : null; $order = $this->orderFacade->createOrderFromFront($orderData, $deliveryAddress); $this->orderFacade->sendHeurekaOrderInfo($order, $frontOrderFormData->disallowHeurekaVerifiedByCustomers); @@ -230,7 +227,7 @@ public function indexAction() try { $this->sendMail($order); } catch (\Shopsys\FrameworkBundle\Model\Mail\Exception\MailException $e) { - $this->getFlashMessageSender()->addErrorFlash( + $this->addErrorFlash( t('Unable to send some emails, please contact us for order verification.') ); } @@ -335,7 +332,7 @@ private function checkTransportAndPaymentChanges( ); if ($transportAndPaymentCheckResult->isTransportPriceChanged()) { - $this->getFlashMessageSender()->addInfoFlashTwig( + $this->addInfoFlashTwig( t('The price of shipping {{ transportName }} changed during ordering process. Check your order, please.'), [ 'transportName' => $orderData->transport->getName(), @@ -343,7 +340,7 @@ private function checkTransportAndPaymentChanges( ); } if ($transportAndPaymentCheckResult->isPaymentPriceChanged()) { - $this->getFlashMessageSender()->addInfoFlashTwig( + $this->addInfoFlashTwig( t('The price of payment {{ paymentName }} changed during ordering process. Check your order, please.'), [ 'paymentName' => $orderData->payment->getName(), diff --git a/src/Controller/Front/PersonalDataController.php b/src/Controller/Front/PersonalDataController.php index ac57ff3239..fbe5dc76b8 100644 --- a/src/Controller/Front/PersonalDataController.php +++ b/src/Controller/Front/PersonalDataController.php @@ -116,7 +116,7 @@ public function indexAction(Request $request) $this->domain->getId() ); $this->personalDataAccessMailFacade->sendMail($personalData); - $this->getFlashMessageSender()->addSuccessFlash(t('Email with a link to the page with your personal data was sent to your email address.')); + $this->addSuccessFlash(t('Email with a link to the page with your personal data was sent to your email address.')); } $content = $this->setting->getForDomain(Setting::PERSONAL_DATA_DISPLAY_SITE_CONTENT, $this->domain->getId()); @@ -146,7 +146,7 @@ public function exportAction(Request $request) $this->domain->getId() ); $this->personalDataAccessMailFacade->sendMail($personalData); - $this->getFlashMessageSender()->addSuccessFlash(t('Email with a link to the export of your personal data was sent to your email address.')); + $this->addSuccessFlash(t('Email with a link to the export of your personal data was sent to your email address.')); } $content = $this->setting->getForDomain(Setting::PERSONAL_DATA_EXPORT_SITE_CONTENT, $this->domain->getId()); diff --git a/src/Controller/Front/PromoCodeController.php b/src/Controller/Front/PromoCodeController.php index 06469a0500..efc12ee9e8 100644 --- a/src/Controller/Front/PromoCodeController.php +++ b/src/Controller/Front/PromoCodeController.php @@ -47,7 +47,7 @@ public function applyAction(Request $request) 'message' => t('Promo code invalid. Check it, please.'), ]); } - $this->getFlashMessageSender()->addSuccessFlash(t('Promo code added to order')); + $this->addSuccessFlash(t('Promo code added to order')); return new JsonResponse(['result' => true]); } @@ -55,7 +55,7 @@ public function applyAction(Request $request) public function removeAction() { $this->currentPromoCodeFacade->removeEnteredPromoCode(); - $this->getFlashMessageSender()->addSuccessFlash(t('Promo code removed from order')); + $this->addSuccessFlash(t('Promo code removed from order')); return $this->redirectToRoute('front_cart'); } diff --git a/src/Controller/Front/RegistrationController.php b/src/Controller/Front/RegistrationController.php index 75ac54d95c..2387f07273 100644 --- a/src/Controller/Front/RegistrationController.php +++ b/src/Controller/Front/RegistrationController.php @@ -93,12 +93,12 @@ public function registerAction(Request $request) $customerUser = $this->customerUserFacade->register($customerUserData); $this->authenticator->loginUser($customerUser, $request); - $this->getFlashMessageSender()->addSuccessFlash(t('You have been successfully registered.')); + $this->addSuccessFlash(t('You have been successfully registered.')); return $this->redirectToRoute('front_homepage'); } if ($form->isSubmitted() && !$form->isValid()) { - $this->getFlashMessageSender()->addErrorFlash(t('Please check the correctness of all data filled.')); + $this->addErrorFlash(t('Please check the correctness of all data filled.')); } return $this->render('Front/Content/Registration/register.html.twig', [ diff --git a/src/Controller/Front/RobotsController.php b/src/Controller/Front/RobotsController.php index abfa78c7c9..be5ae46436 100644 --- a/src/Controller/Front/RobotsController.php +++ b/src/Controller/Front/RobotsController.php @@ -21,23 +21,30 @@ class RobotsController extends FrontBaseController private $sitemapFilePrefixer; /** + * @var string + */ + private $sitemapsUrlPrefix; + + /** + * @param string $sitemapsUrlPrefix * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain * @param \Shopsys\FrameworkBundle\Model\Sitemap\SitemapFilePrefixer $sitemapFilePrefixer */ public function __construct( + string $sitemapsUrlPrefix, Domain $domain, SitemapFilePrefixer $sitemapFilePrefixer ) { + $this->sitemapsUrlPrefix = $sitemapsUrlPrefix; $this->domain = $domain; $this->sitemapFilePrefixer = $sitemapFilePrefixer; } public function indexAction() { - $sitemapsUrlPrefix = $this->get('service_container')->getParameter('shopsys.sitemaps_url_prefix'); $sitemapFilePrefix = $this->sitemapFilePrefixer->getSitemapFilePrefixForDomain($this->domain->getId()); - $sitemapUrl = $this->domain->getUrl() . $sitemapsUrlPrefix . '/' . $sitemapFilePrefix . '.xml'; + $sitemapUrl = $this->domain->getUrl() . $this->sitemapsUrlPrefix . '/' . $sitemapFilePrefix . '.xml'; $response = new Response(); $response->headers->set('Content-Type', 'text/plain'); diff --git a/src/Controller/Test/ErrorHandlerController.php b/src/Controller/Test/ErrorHandlerController.php index 4bc1627043..ea0b9e66ee 100644 --- a/src/Controller/Test/ErrorHandlerController.php +++ b/src/Controller/Test/ErrorHandlerController.php @@ -5,8 +5,8 @@ namespace App\Controller\Test; use App\Controller\Front\FrontBaseController; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; class ErrorHandlerController extends FrontBaseController { diff --git a/src/Form/Admin/AdministratorFormTypeExtension.php b/src/Form/Admin/AdministratorFormTypeExtension.php index 5457c08845..6eb48c2656 100644 --- a/src/Form/Admin/AdministratorFormTypeExtension.php +++ b/src/Form/Admin/AdministratorFormTypeExtension.php @@ -18,10 +18,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) } /** - * {@inheritdoc} + * {@inheritDoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return AdministratorFormType::class; + yield AdministratorFormType::class; } } diff --git a/src/Form/Admin/ArticleFormTypeExtension.php b/src/Form/Admin/ArticleFormTypeExtension.php index 27e39742f4..89faec3ba1 100644 --- a/src/Form/Admin/ArticleFormTypeExtension.php +++ b/src/Form/Admin/ArticleFormTypeExtension.php @@ -31,8 +31,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return ArticleFormType::class; + yield ArticleFormType::class; } } diff --git a/src/Form/Admin/BrandFormTypeExtension.php b/src/Form/Admin/BrandFormTypeExtension.php index 190383b964..3ec09edea4 100644 --- a/src/Form/Admin/BrandFormTypeExtension.php +++ b/src/Form/Admin/BrandFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return BrandFormType::class; + yield BrandFormType::class; } } diff --git a/src/Form/Admin/CategoryFormTypeExtension.php b/src/Form/Admin/CategoryFormTypeExtension.php index d326ff9791..ca069b822c 100644 --- a/src/Form/Admin/CategoryFormTypeExtension.php +++ b/src/Form/Admin/CategoryFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return CategoryFormType::class; + yield CategoryFormType::class; } } diff --git a/src/Form/Admin/CustomerUserFormTypeExtension.php b/src/Form/Admin/CustomerUserFormTypeExtension.php index 6b8ac240d7..fe6cb449f7 100644 --- a/src/Form/Admin/CustomerUserFormTypeExtension.php +++ b/src/Form/Admin/CustomerUserFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return CustomerUserFormType::class; + yield CustomerUserFormType::class; } } diff --git a/src/Form/Admin/OrderFormTypeExtension.php b/src/Form/Admin/OrderFormTypeExtension.php index 6d5c3f83fb..2f72792b26 100644 --- a/src/Form/Admin/OrderFormTypeExtension.php +++ b/src/Form/Admin/OrderFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return OrderFormType::class; + yield OrderFormType::class; } } diff --git a/src/Form/Admin/PaymentFormTypeExtension.php b/src/Form/Admin/PaymentFormTypeExtension.php index 30abb7bf4f..c3cb878659 100644 --- a/src/Form/Admin/PaymentFormTypeExtension.php +++ b/src/Form/Admin/PaymentFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return PaymentFormType::class; + yield PaymentFormType::class; } } diff --git a/src/Form/Admin/ProductFormTypeExtension.php b/src/Form/Admin/ProductFormTypeExtension.php index 0e2f7ae3d4..fffe28b1e0 100644 --- a/src/Form/Admin/ProductFormTypeExtension.php +++ b/src/Form/Admin/ProductFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return ProductFormType::class; + yield ProductFormType::class; } } diff --git a/src/Form/Admin/TransportFormTypeExtension.php b/src/Form/Admin/TransportFormTypeExtension.php index b971048504..a4a78e9389 100644 --- a/src/Form/Admin/TransportFormTypeExtension.php +++ b/src/Form/Admin/TransportFormTypeExtension.php @@ -20,8 +20,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return TransportFormType::class; + yield TransportFormType::class; } } diff --git a/src/Twig/FlagsExtension.php b/src/Twig/FlagsExtension.php index e74d727791..7f9288e616 100644 --- a/src/Twig/FlagsExtension.php +++ b/src/Twig/FlagsExtension.php @@ -5,16 +5,16 @@ namespace App\Twig; use Shopsys\ReadModelBundle\Flag\FlagsProvider; -use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; +use Twig\Environment; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class FlagsExtension extends AbstractExtension { /** - * @var \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface + * @var \Twig\Environment */ - protected $templating; + protected $twigEnvironment; /** * @var \Shopsys\ReadModelBundle\Flag\FlagsProvider @@ -23,13 +23,13 @@ class FlagsExtension extends AbstractExtension /** * @param \Shopsys\ReadModelBundle\Flag\FlagsProvider $flagsProvider - * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating + * @param \Twig\Environment $twigEnvironment */ public function __construct( FlagsProvider $flagsProvider, - EngineInterface $templating + Environment $twigEnvironment ) { - $this->templating = $templating; + $this->twigEnvironment = $twigEnvironment; $this->flagsProvider = $flagsProvider; } @@ -50,7 +50,7 @@ public function getFunctions(): array */ public function renderFlagsByIds(array $flagIds, string $classAddition = ''): string { - return $this->templating->render( + return $this->twigEnvironment->render( 'Front/Inline/Product/productFlags.html.twig', [ 'flags' => $this->flagsProvider->getFlagsByIds($flagIds), diff --git a/symfony.lock b/symfony.lock index 2a10c7ad9d..91ad7af99c 100644 --- a/symfony.lock +++ b/symfony.lock @@ -44,6 +44,15 @@ "tests/unit.suite.yml" ] }, + "codeception/lib-asserts": { + "version": "1.2.0" + }, + "codeception/module-db": { + "version": "1.0.1" + }, + "codeception/module-webdriver": { + "version": "1.0.5" + }, "codeception/phpunit-wrapper": { "version": "7.7.1" }, @@ -351,15 +360,24 @@ "nesbot/carbon": { "version": "2.26.0" }, + "nette/application": { + "version": "v3.0.4" + }, "nette/bootstrap": { "version": "v2.4.6" }, + "nette/component-model": { + "version": "v3.0.0" + }, "nette/di": { "version": "v2.4.15" }, "nette/finder": { "version": "v2.5.1" }, + "nette/http": { + "version": "v3.0.3" + }, "nette/neon": { "version": "v3.0.0" }, @@ -369,6 +387,9 @@ "nette/robot-loader": { "version": "v3.1.1" }, + "nette/routing": { + "version": "v3.0.0" + }, "nette/utils": { "version": "v2.5.3" }, @@ -419,9 +440,15 @@ "phing/phing": { "version": "2.16.1" }, + "php": { + "version": "7.2" + }, "php-cs-fixer/diff": { "version": "v1.3.0" }, + "php-webdriver/webdriver": { + "version": "1.8.2" + }, "phpcollection/phpcollection": { "version": "0.5.0" }, @@ -614,6 +641,9 @@ "shopsys/migrations": { "version": "dev-mg-weird-flex-but-ok" }, + "shopsys/ordered-form": { + "version": "4.0.0" + }, "shopsys/plugin-interface": { "version": "dev-mg-weird-flex-but-ok" }, @@ -704,6 +734,9 @@ "symfony/cache": { "version": "v3.4.33" }, + "symfony/cache-contracts": { + "version": "v1.1.7" + }, "symfony/class-loader": { "version": "v3.4.33" }, @@ -750,9 +783,15 @@ "symfony/dotenv": { "version": "v3.4.33" }, + "symfony/error-handler": { + "version": "v4.4.5" + }, "symfony/event-dispatcher": { "version": "v3.4.33" }, + "symfony/event-dispatcher-contracts": { + "version": "v1.1.7" + }, "symfony/expression-language": { "version": "v3.4.33" }, @@ -946,6 +985,9 @@ "translations/.gitignore" ] }, + "symfony/translation-contracts": { + "version": "v1.1.7" + }, "symfony/twig-bridge": { "version": "v3.4.33" }, @@ -969,6 +1011,9 @@ "symfony/var-dumper": { "version": "v3.4.33" }, + "symfony/var-exporter": { + "version": "v4.4.5" + }, "symfony/web-link": { "version": "v3.4.33" }, @@ -995,6 +1040,25 @@ "ref": "dae9b39fd6717970be7601101ce5aa960bf53d9a" } }, + "symfony/webpack-encore-bundle": { + "version": "1.6", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.6", + "ref": "69e1d805ad95964088bd510c05995e87dc391564" + }, + "files": [ + "assets/css/app.css", + "assets/js/app.js", + "config/packages/assets.yaml", + "config/packages/prod/webpack_encore.yaml", + "config/packages/test/webpack_encore.yaml", + "config/packages/webpack_encore.yaml", + "package.json", + "webpack.config.js" + ] + }, "symfony/workflow": { "version": "3.3", "recipe": { @@ -1010,6 +1074,12 @@ "symfony/yaml": { "version": "v3.4.33" }, + "symplify/auto-bind-parameter": { + "version": "v7.2.2" + }, + "symplify/autowire-array-parameter": { + "version": "v7.2.2" + }, "symplify/better-phpdoc-parser": { "version": "v5.4.16" }, @@ -1022,6 +1092,12 @@ "symplify/package-builder": { "version": "v5.4.16" }, + "symplify/set-config-resolver": { + "version": "v7.2.3" + }, + "symplify/smart-file-system": { + "version": "v7.2.3" + }, "symplify/token-runner": { "version": "v5.4.13" }, diff --git a/templates/Front/Content/Product/detail.html.twig b/templates/Front/Content/Product/detail.html.twig index a61098be96..415e863223 100644 --- a/templates/Front/Content/Product/detail.html.twig +++ b/templates/Front/Content/Product/detail.html.twig @@ -100,7 +100,7 @@ {% endif %} - {% spaceless %} + {% apply spaceless %}
    {% if product.brand %}
    @@ -142,7 +142,7 @@ {% endif %} {% endif %}
    - {% endspaceless %} + {% endapply %} diff --git a/templates/Front/Content/Product/filterFormTheme.html.twig b/templates/Front/Content/Product/filterFormTheme.html.twig index 8b6db9da1b..67e08587b7 100644 --- a/templates/Front/Content/Product/filterFormTheme.html.twig +++ b/templates/Front/Content/Product/filterFormTheme.html.twig @@ -17,7 +17,7 @@ {% endblock form_row %} {% block choice_widget_expanded %} - {% spaceless %} + {% apply spaceless %}
    {% for child in form %}
    @@ -32,12 +32,12 @@ {{ empty_message|default('Nothing to choose from.'|trans) }} {% endfor %}
    - {% endspaceless %} + {% endapply %} {% endblock choice_widget_expanded %} {% block form_errors %} {% set errors_attr = errors_attr|default({})|merge({'class': (errors_attr.class|default(''))}) %} - {% spaceless %} + {% apply spaceless %} {% if form.parent %} @@ -52,5 +52,5 @@ {% endif %} - {% endspaceless %} + {% endapply %} {% endblock form_errors %} diff --git a/templates/Front/Form/theme.html.twig b/templates/Front/Form/theme.html.twig index fcd56366c6..3158fa24cf 100644 --- a/templates/Front/Form/theme.html.twig +++ b/templates/Front/Form/theme.html.twig @@ -75,7 +75,7 @@ {%- endblock textarea_row %} {% block form_label %} - {% spaceless %} + {% apply spaceless %} {% if label is not same as(false) %} {% if not compound %} {% set label_attr = label_attr|merge({'for': id}) %} @@ -96,19 +96,19 @@ {% if required %}*{% endif %} {% endif %} - {% endspaceless %} + {% endapply %} {% endblock form_label %} {% block checkbox_label %} - {% spaceless %} + {% apply spaceless %} {% set withoutColon = true %} {{ block('form_label') }} - {% endspaceless %} + {% endapply %} {% endblock checkbox_label %} {% block form_errors %} {% set errors_attr = errors_attr|default({})|merge({'class': (errors_attr.class|default(''))}) %} - {% spaceless %} + {% apply spaceless %} {% if form.parent %} @@ -123,7 +123,7 @@ {% endif %} - {% endspaceless %} + {% endapply %} {% endblock form_errors %} {% block form_widget_simple %} @@ -188,7 +188,7 @@ {% endblock choice_widget_options %} {% block choice_widget_expanded %} - {% spaceless %} + {% apply spaceless %}
    {% for child in form %}
    @@ -201,7 +201,7 @@ {{ empty_message|default('Nothing to choose from.'|trans) }} {% endfor %}
    - {% endspaceless %} + {% endapply %} {% endblock choice_widget_expanded %} {% block widget_attributes -%} @@ -257,14 +257,14 @@ {% endblock honey_pot_row %} {% block date_picker_widget %} - {% spaceless %} + {% apply spaceless %} {% set attr = attr|merge({'class': ((attr.class|default('') ~ ' js-date-picker')|trim)}) %} {{- block('form_widget') -}} - {% endspaceless %} + {% endapply %} {% endblock date_picker_widget %} {% block icon %} - {% spaceless %} + {% apply spaceless %} {% if icon is defined %} {% endif %} - {% endspaceless %} + {% endapply %} {% endblock %} diff --git a/templates/Front/Layout/layout.html.twig b/templates/Front/Layout/layout.html.twig index 3f5d089922..ec1aa21f38 100644 --- a/templates/Front/Layout/layout.html.twig +++ b/templates/Front/Layout/layout.html.twig @@ -2,7 +2,7 @@ {% use 'Front/Layout/header.html.twig' %} {% block html_body %} - {% set adminLoggedAsCustomer = is_granted(constant('Shopsys\\FrameworkBundle\\Model\\Security\\Roles::ROLE_ADMIN_AS_CUSTOMER')) %} + {% set adminLoggedAsCustomer = app.session.has(constant('Shopsys\\FrameworkBundle\\Model\\Security\\LoginAsUserFacade::SESSION_LOGIN_AS')) %} {% if adminLoggedAsCustomer or isMailerSettingUnusual() %}
    {% if adminLoggedAsCustomer %} diff --git a/tests/App/Acceptance/acceptance/_bootstrap.php b/tests/App/Acceptance/acceptance/_bootstrap.php deleted file mode 100644 index c72c43dede..0000000000 --- a/tests/App/Acceptance/acceptance/_bootstrap.php +++ /dev/null @@ -1,5 +0,0 @@ -getEntityManager()->createQueryBuilder() + $qb = $this->em->createQueryBuilder() ->select('o, oi') ->from(Order::class, 'o') ->join(OrderItem::class, 'oi', Join::WITH, 'oi.order = o') @@ -23,14 +23,14 @@ public function testHydrateAllData() $rows = $qb->getQuery()->execute(null, GroupedScalarHydrator::HYDRATION_MODE); $row = $rows[0]; - $this->assertInternalType('array', $row); + $this->assertIsArray($row); $this->assertCount(2, $row); $this->assertArrayHasKey('o', $row); $this->assertArrayHasKey('oi', $row); - $this->assertInternalType('array', $row['o']); - $this->assertInternalType('array', $row['oi']); + $this->assertIsArray($row['o']); + $this->assertIsArray($row['oi']); $this->assertArrayHasKey('id', $row['o']); $this->assertArrayHasKey('id', $row['oi']); diff --git a/tests/App/Functional/Component/Doctrine/SortableNullsWalkerTest.php b/tests/App/Functional/Component/Doctrine/SortableNullsWalkerTest.php index 39299bb615..f8326d77a8 100644 --- a/tests/App/Functional/Component/Doctrine/SortableNullsWalkerTest.php +++ b/tests/App/Functional/Component/Doctrine/SortableNullsWalkerTest.php @@ -7,16 +7,14 @@ use App\Model\Product\Product; use Doctrine\ORM\Query; use Shopsys\FrameworkBundle\Component\Doctrine\SortableNullsWalker; -use Tests\App\Test\FunctionalTestCase; +use Tests\App\Test\TransactionFunctionalTestCase; -class SortableNullsWalkerTest extends FunctionalTestCase +class SortableNullsWalkerTest extends TransactionFunctionalTestCase { public function testWalkOrderByItemAsc() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */ - $queryBuilder = $em->createQueryBuilder(); + $queryBuilder = $this->em->createQueryBuilder(); $queryBuilder ->select('p.id') @@ -31,10 +29,8 @@ public function testWalkOrderByItemAsc() public function testWalkOrderByItemDesc() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */ - $queryBuilder = $em->createQueryBuilder(); + $queryBuilder = $this->em->createQueryBuilder(); $queryBuilder ->select('p.id') @@ -49,10 +45,8 @@ public function testWalkOrderByItemDesc() public function testWalkOrderByItemWithoutOrdering() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */ - $queryBuilder = $em->createQueryBuilder(); + $queryBuilder = $this->em->createQueryBuilder(); $queryBuilder ->select('p.id') diff --git a/tests/App/Functional/Component/Domain/Multidomain/MultidomainEntityDataCreatorTest.php b/tests/App/Functional/Component/Domain/Multidomain/MultidomainEntityDataCreatorTest.php index df39d06a5d..e45883d4b9 100644 --- a/tests/App/Functional/Component/Domain/Multidomain/MultidomainEntityDataCreatorTest.php +++ b/tests/App/Functional/Component/Domain/Multidomain/MultidomainEntityDataCreatorTest.php @@ -13,10 +13,7 @@ class MultidomainEntityDataCreatorTest extends TransactionFunctionalTestCase { public function testCopyAllMultidomainDataForNewDomainCopiesTestRow() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); - - $em->getConnection()->executeQuery(' + $this->em->getConnection()->executeQuery(' CREATE TABLE _test_table ( domain_id int NOT NULL, title text NOT NULL, @@ -24,7 +21,7 @@ public function testCopyAllMultidomainDataForNewDomainCopiesTestRow() ) '); - $em->getConnection()->executeQuery(" + $this->em->getConnection()->executeQuery(" INSERT INTO _test_table (domain_id, title, description) VALUES (1, 'asdf', 'qwer') "); @@ -40,13 +37,13 @@ public function testCopyAllMultidomainDataForNewDomainCopiesTestRow() '_test_table' => ['title'], ]); - $sqlQuoter = new SqlQuoter($em); + $sqlQuoter = new SqlQuoter($this->em); - $multidomainEntityDataCreator = new MultidomainEntityDataCreator($multidomainEntityClassFinderFacadeMock, $em, $sqlQuoter); + $multidomainEntityDataCreator = new MultidomainEntityDataCreator($multidomainEntityClassFinderFacadeMock, $this->em, $sqlQuoter); $multidomainEntityDataCreator->copyAllMultidomainDataForNewDomain(1, 2); - $results = $em->getConnection()->fetchAll(' + $results = $this->em->getConnection()->fetchAll(' SELECT domain_id, title, description FROM _test_table ORDER BY domain_id @@ -70,17 +67,14 @@ public function testCopyAllMultidomainDataForNewDomainCopiesTestRow() public function testCopyAllMultidomainDataForNewDomainWithDomainIdDoesNotThrowDriverException() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); - - $em->getConnection()->executeQuery(' + $this->em->getConnection()->executeQuery(' CREATE TABLE _test_table ( domain_id int NOT NULL, title text NOT NULL ) '); - $em->getConnection()->executeQuery(" + $this->em->getConnection()->executeQuery(" INSERT INTO _test_table (domain_id, title) VALUES (1, 'asdf') "); @@ -96,9 +90,9 @@ public function testCopyAllMultidomainDataForNewDomainWithDomainIdDoesNotThrowDr '_test_table' => ['domain_id', 'title'], ]); - $sqlQuoter = new SqlQuoter($em); + $sqlQuoter = new SqlQuoter($this->em); - $multidomainEntityDataCreator = new MultidomainEntityDataCreator($multidomainEntityClassFinderFacadeMock, $em, $sqlQuoter); + $multidomainEntityDataCreator = new MultidomainEntityDataCreator($multidomainEntityClassFinderFacadeMock, $this->em, $sqlQuoter); try { $multidomainEntityDataCreator->copyAllMultidomainDataForNewDomain(1, 2); diff --git a/tests/App/Functional/Component/FlashMessage/BagTest.php b/tests/App/Functional/Component/FlashMessage/BagTest.php deleted file mode 100644 index 50ab960718..0000000000 --- a/tests/App/Functional/Component/FlashMessage/BagTest.php +++ /dev/null @@ -1,87 +0,0 @@ -getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageFront */ - $flashMessageFront = $this->getContainer()->get('shopsys.shop.component.flash_message.bag.front'); - - $errorMessageAdmin = 'Error message admin'; - $errorMessageFront = 'Error message front'; - $successMessageAdmin = 'Success message admin'; - - $flashMessageAdmin->addError($errorMessageAdmin); - $flashMessageAdmin->addSuccess($successMessageAdmin); - $flashMessageFront->addError($errorMessageFront); - - $this->assertSame([$errorMessageAdmin], $flashMessageAdmin->getErrorMessages()); - $this->assertSame([], $flashMessageAdmin->getInfoMessages()); - $this->assertSame([$successMessageAdmin], $flashMessageAdmin->getSuccessMessages()); - $this->assertSame([$errorMessageFront], $flashMessageFront->getErrorMessages()); - $this->assertSame([], $flashMessageFront->getInfoMessages()); - $this->assertSame([], $flashMessageFront->getSuccessMessages()); - } - - public function testAddArrayOfMessages() - { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageAdmin */ - $flashMessageAdmin = $this->getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); - - $errorMessagesAdmin = ['First error message admin', 'Second error message admin']; - - $flashMessageAdmin->addError($errorMessagesAdmin); - - $this->assertSame($errorMessagesAdmin, $flashMessageAdmin->getErrorMessages()); - } - - public function testGetUniqueMessage() - { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageAdmin */ - $flashMessageAdmin = $this->getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); - - $errorMessageAdmin = 'Error message admin'; - - $flashMessageAdmin->addError($errorMessageAdmin); - $flashMessageAdmin->addError($errorMessageAdmin); - - $this->assertSame([$errorMessageAdmin], $flashMessageAdmin->getErrorMessages()); - } - - public function testGetAndClearBag() - { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageAdmin */ - $flashMessageAdmin = $this->getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); - - $errorMessageAdmin = 'Error message admin'; - - $flashMessageAdmin->addError($errorMessageAdmin); - - $this->assertSame([$errorMessageAdmin], $flashMessageAdmin->getErrorMessages()); - $this->assertSame([], $flashMessageAdmin->getErrorMessages()); - } - - public function testIsEmpty() - { - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageAdmin */ - $flashMessageAdmin = $this->getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); - - // clearing after previous tests - $flashMessageAdmin->getErrorMessages(); - $flashMessageAdmin->getInfoMessages(); - $flashMessageAdmin->getSuccessMessages(); - - $this->assertTrue($flashMessageAdmin->isEmpty()); - $flashMessageAdmin->addInfo('Some message'); - $this->assertFalse($flashMessageAdmin->isEmpty()); - $this->assertFalse($flashMessageAdmin->isEmpty(), 'Flash message cannot modified content after call isEmpty()'); - } -} diff --git a/tests/App/Functional/Component/Grid/Ordering/GridOrderingFacadeTest.php b/tests/App/Functional/Component/Grid/Ordering/GridOrderingFacadeTest.php index 1681ffba6b..615c7856a8 100644 --- a/tests/App/Functional/Component/Grid/Ordering/GridOrderingFacadeTest.php +++ b/tests/App/Functional/Component/Grid/Ordering/GridOrderingFacadeTest.php @@ -12,9 +12,7 @@ class GridOrderingFacadeTest extends TransactionFunctionalTestCase { public function testSetPositionWrongEntity() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - $gridOrderingFacade = new GridOrderingFacade($em); + $gridOrderingFacade = new GridOrderingFacade($this->em); $entity = new stdClass(); $this->expectException(\Shopsys\FrameworkBundle\Component\Grid\Ordering\Exception\EntityIsNotOrderableException::class); $gridOrderingFacade->saveOrdering($entity, []); diff --git a/tests/App/Functional/Component/Grid/QueryBuilderDataSourceTest.php b/tests/App/Functional/Component/Grid/QueryBuilderDataSourceTest.php index 7e3c2b5342..36f85adf3d 100644 --- a/tests/App/Functional/Component/Grid/QueryBuilderDataSourceTest.php +++ b/tests/App/Functional/Component/Grid/QueryBuilderDataSourceTest.php @@ -13,10 +13,7 @@ class QueryBuilderDataSourceTest extends TransactionFunctionalTestCase { public function testGetOneRow() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p'); @@ -24,16 +21,13 @@ public function testGetOneRow() $row = $queryBuilderDataSource->getOneRow($this->getReference(ProductDataFixture::PRODUCT_PREFIX . '1')); - $this->assertInternalType('array', $row); + $this->assertIsArray($row); $this->assertArrayHasKey('p', $row); } public function testGetTotalRowsCount() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->where('p.id >= 1 AND p.id <= 10') @@ -49,10 +43,7 @@ public function testGetTotalRowsCount() public function testGetRows() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->setMaxResults(5); @@ -60,21 +51,18 @@ public function testGetRows() $queryBuilderDataSource = new QueryBuilderDataSource($qb, 'p.id'); $rows = $queryBuilderDataSource->getPaginatedRows()->getResults(); - $this->assertInternalType('array', $rows); + $this->assertIsArray($rows); $this->assertCount(5, $rows); foreach ($rows as $row) { - $this->assertInternalType('array', $row); + $this->assertIsArray($row); $this->assertArrayHasKey('p', $row); } } public function testGetRowsInAscOrder() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->setMaxResults(10); @@ -96,10 +84,7 @@ public function testGetRowsInAscOrder() public function testGetRowsInDescOrder() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->setMaxResults(10); diff --git a/tests/App/Functional/Component/Grid/QueryBuilderWithRowManipulatorDataSourceTest.php b/tests/App/Functional/Component/Grid/QueryBuilderWithRowManipulatorDataSourceTest.php index 0f17ea0413..616be0a62b 100644 --- a/tests/App/Functional/Component/Grid/QueryBuilderWithRowManipulatorDataSourceTest.php +++ b/tests/App/Functional/Component/Grid/QueryBuilderWithRowManipulatorDataSourceTest.php @@ -13,10 +13,7 @@ class QueryBuilderWithRowManipulatorDataSourceTest extends TransactionFunctional { public function testGetOneRow() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p'); @@ -27,17 +24,14 @@ public function testGetOneRow() $row = $dataSource->getOneRow($this->getReference(ProductDataFixture::PRODUCT_PREFIX . '1')); - $this->assertInternalType('array', $row); + $this->assertIsArray($row); $this->assertArrayHasKey('newField', $row); $this->assertSame('newValue', $row['newField']); } public function testGetTotalRowsCount() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->where('p.id >= 1 AND p.id <= 10') @@ -56,10 +50,7 @@ public function testGetTotalRowsCount() public function testGetRows() { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - - $qb = $em->createQueryBuilder(); + $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from(Product::class, 'p') ->setMaxResults(5); @@ -70,11 +61,11 @@ public function testGetRows() }); $rows = $dataSource->getPaginatedRows()->getResults(); - $this->assertInternalType('array', $rows); + $this->assertIsArray($rows); $this->assertCount(5, $rows); foreach ($rows as $row) { - $this->assertInternalType('array', $row); + $this->assertIsArray($row); $this->assertArrayHasKey('newField', $row); $this->assertSame('newValue' . $row['p']['id'], $row['newField']); } diff --git a/tests/App/Functional/Component/HttpFoundation/FragmentHandlerTest.php b/tests/App/Functional/Component/HttpFoundation/FragmentHandlerTest.php index f62cc37648..eb99f860c9 100644 --- a/tests/App/Functional/Component/HttpFoundation/FragmentHandlerTest.php +++ b/tests/App/Functional/Component/HttpFoundation/FragmentHandlerTest.php @@ -8,31 +8,40 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class FragmentHandlerTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + + /** + * @var \Symfony\Bridge\Twig\Extension\HttpKernelRuntime + * @inject + */ + private $httpKernelRuntime; + + /** + * @var \Symfony\Component\HttpFoundation\RequestStack + * @inject + */ + private $requestStack; + public function testRenderingFragmentDoesNotIgnoreException() { - /** @var \Symfony\Bridge\Twig\Extension\HttpKernelRuntime $httpKernelRuntime */ - $httpKernelRuntime = $this->getContainer()->get('twig.runtime.httpkernel'); - // Rendering a fragment can only be done when handling a Request. $this->putFakeRequestToRequestStack(); $this->expectException(\App\Controller\Test\ExpectedTestException::class); /** This should call @see \Shopsys\FrameworkBundle\Component\HttpFoundation\FragmentHandler::render() */ - $httpKernelRuntime->renderFragment('/test/error-handler/exception'); + $this->httpKernelRuntime->renderFragment('/test/error-handler/exception'); } private function putFakeRequestToRequestStack() { - /** @var \Symfony\Component\HttpFoundation\RequestStack $requestStack */ - $requestStack = $this->getContainer()->get('request_stack'); - $request = new Request(); $session = new Session(new MockArraySessionStorage()); $request->setSession($session); - $requestStack->push($request); + $this->requestStack->push($request); } } diff --git a/tests/App/Functional/Controller/HomepageControllerTest.php b/tests/App/Functional/Controller/HomepageControllerTest.php index ece4270452..862dae8b58 100644 --- a/tests/App/Functional/Controller/HomepageControllerTest.php +++ b/tests/App/Functional/Controller/HomepageControllerTest.php @@ -10,7 +10,7 @@ class HomepageControllerTest extends FunctionalTestCase { public function testHomepageHttpStatus200() { - $client = $this->getClient(); + $client = $this->findClient(); $client->request('GET', '/'); $code = $client->getResponse()->getStatusCode(); @@ -20,7 +20,7 @@ public function testHomepageHttpStatus200() public function testHomepageHasBodyEnd() { - $client = $this->getClient(); + $client = $this->findClient(); $client->request('GET', '/'); $content = $client->getResponse()->getContent(); diff --git a/tests/App/Functional/Controller/ProductRenameRedirectPreviousUrlTest.php b/tests/App/Functional/Controller/ProductRenameRedirectPreviousUrlTest.php index ee44b862bf..9f874279ac 100644 --- a/tests/App/Functional/Controller/ProductRenameRedirectPreviousUrlTest.php +++ b/tests/App/Functional/Controller/ProductRenameRedirectPreviousUrlTest.php @@ -5,12 +5,16 @@ namespace Tests\App\Functional\Controller; use App\DataFixtures\Demo\ProductDataFixture; +use Faker\Provider\Text; use Shopsys\FrameworkBundle\Component\Domain\Domain; -use Tests\App\Test\TransactionFunctionalTestCase; +use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; -class ProductRenameRedirectPreviousUrlTest extends TransactionFunctionalTestCase +class ProductRenameRedirectPreviousUrlTest extends FunctionalTestCase { - private const TESTED_PRODUCT_ID = 1; + use SymfonyTestContainer; + + private const TESTED_PRODUCT_ID = 100; /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface @@ -30,19 +34,27 @@ class ProductRenameRedirectPreviousUrlTest extends TransactionFunctionalTestCase */ private $friendlyUrlFacade; + /** + * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator + * @inject + */ + protected $em; + public function testPreviousUrlRedirect(): void { + /** @var \App\Model\Product\Product $product */ $product = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . self::TESTED_PRODUCT_ID); $previousFriendlyUrlSlug = $this->friendlyUrlFacade->findMainFriendlyUrl(Domain::FIRST_DOMAIN_ID, 'front_product_detail', self::TESTED_PRODUCT_ID)->getSlug(); - /** @var \App\Model\Product\Product $product */ $productData = $this->productDataFactory->createFromProduct($product); - $productData->name[$this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()] = 'rename'; + $productData->name[$this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()] = Text::asciify(); $this->productFacade->edit(self::TESTED_PRODUCT_ID, $productData); - $client = $this->getClient(); + $overWriteDomainUrl = preg_replace('#^https?://#', '', $this->getContainer()->getParameter('overwrite_domain_url')); + + $client = $this->findClient(true, null, null, [], ['HTTP_HOST' => $overWriteDomainUrl]); $client->request('GET', '/' . $previousFriendlyUrlSlug); // Should be 301 (moved permanently), because old product urls should be permanently redirected diff --git a/tests/App/Functional/EntityExtension/EntityExtensionTest.php b/tests/App/Functional/EntityExtension/EntityExtensionTest.php index d33dd32140..553ff19ad3 100644 --- a/tests/App/Functional/EntityExtension/EntityExtensionTest.php +++ b/tests/App/Functional/EntityExtension/EntityExtensionTest.php @@ -4,17 +4,17 @@ namespace Tests\App\Functional\EntityExtension; -use App\Model\Category\Category; -use App\Model\Order\Order; use App\Model\Order\Order as ExtendedOrder; use App\Model\Product\Brand\Brand as ExtendedBrand; -use App\Model\Product\Product; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Tools\SchemaTool; +use Shopsys\FrameworkBundle\Model\Category\Category; use Shopsys\FrameworkBundle\Model\Order\Item\OrderItem; +use Shopsys\FrameworkBundle\Model\Order\Order; use Shopsys\FrameworkBundle\Model\Product\Brand\Brand; +use Shopsys\FrameworkBundle\Model\Product\Product; use Shopsys\FrameworkBundle\Model\Product\ProductTranslation; use Tests\App\Functional\EntityExtension\Model\CategoryManyToManyBidirectionalEntity; use Tests\App\Functional\EntityExtension\Model\CategoryOneToManyBidirectionalEntity; @@ -28,9 +28,12 @@ use Tests\App\Functional\EntityExtension\Model\ProductOneToOneBidirectionalEntity; use Tests\App\Functional\EntityExtension\Model\UnidirectionalEntity; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class EntityExtensionTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const MAIN_PRODUCT_ID = 1; protected const ONE_TO_ONE_SELF_REFERENCING_PRODUCT_ID = 2; protected const ONE_TO_MANY_SELF_REFERENCING_PRODUCT_ID = 3; @@ -44,20 +47,20 @@ class EntityExtensionTest extends TransactionFunctionalTestCase protected const ORDER_ITEM_ID = 1; /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator + * @var \Tests\App\Functional\EntityExtension\OverwritableEntityNameResolver + * @inject */ - private $em; + private $entityNameResolver; /** - * @var \Tests\App\Functional\EntityExtension\OverwritableEntityNameResolver + * @var \Tests\App\Functional\EntityExtension\OverwritableLoadORMMetadataSubscriber * @inject */ - private $entityNameResolver; + private $loadORMMetadataSubscriber; - public function setUp() + protected function setUp(): void { parent::setUp(); - $this->em = $this->getEntityManager(); $this->registerTestEntities(); $entityExtensionMap = [ @@ -69,7 +72,7 @@ public function setUp() ProductTranslation::class => ExtendedProductTranslation::class, ]; - $applicationEntityExtensionMap = $this->getContainer()->getParameter('shopsys.entity_extension.map'); + $applicationEntityExtensionMap = static::bootKernel()->getContainer()->getParameter('shopsys.entity_extension.map'); foreach ($applicationEntityExtensionMap as $baseClass => $extendedClass) { if (!array_key_exists($baseClass, $entityExtensionMap)) { @@ -114,10 +117,7 @@ public function registerTestEntities(): void */ public function overwriteEntityExtensionMapInServicesInContainer(array $entityExtensionMap): void { - /** @var \Tests\App\Functional\EntityExtension\OverwritableLoadORMMetadataSubscriber $loadORMMetadataSubscriber */ - $loadORMMetadataSubscriber = $this->getContainer()->get('joschi127_doctrine_entity_override.event_subscriber.load_orm_metadata'); - - $loadORMMetadataSubscriber->overwriteEntityExtensionMap($entityExtensionMap); + $this->loadORMMetadataSubscriber->overwriteEntityExtensionMap($entityExtensionMap); $this->entityNameResolver->overwriteEntityExtensionMap($entityExtensionMap); } diff --git a/tests/App/Functional/EntityExtension/Model/ExtendedCategory.php b/tests/App/Functional/EntityExtension/Model/ExtendedCategory.php index 211b0abff3..0d2e6740b5 100644 --- a/tests/App/Functional/EntityExtension/Model/ExtendedCategory.php +++ b/tests/App/Functional/EntityExtension/Model/ExtendedCategory.php @@ -4,10 +4,10 @@ namespace Tests\App\Functional\EntityExtension\Model; -use App\Model\Category\Category; use App\Model\Category\CategoryData; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Shopsys\FrameworkBundle\Model\Category\Category; /** * @ORM\Entity diff --git a/tests/App/Functional/EntityExtension/Model/ExtendedProduct.php b/tests/App/Functional/EntityExtension/Model/ExtendedProduct.php index d82e619f5f..792019db29 100644 --- a/tests/App/Functional/EntityExtension/Model/ExtendedProduct.php +++ b/tests/App/Functional/EntityExtension/Model/ExtendedProduct.php @@ -4,9 +4,9 @@ namespace Tests\App\Functional\EntityExtension\Model; -use App\Model\Product\Product; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Shopsys\FrameworkBundle\Model\Product\Product; use Shopsys\FrameworkBundle\Model\Product\ProductData; /** diff --git a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOperatorTranslationTest.php b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOperatorTranslationTest.php index c63f21617f..e1a702df03 100644 --- a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOperatorTranslationTest.php +++ b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOperatorTranslationTest.php @@ -6,9 +6,12 @@ use Shopsys\FrameworkBundle\Form\Admin\AdvancedSearch\AdvancedSearchOperatorTranslation; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AdvancedSearchOperatorTranslationTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\AdvancedSearch\ProductAdvancedSearchConfig * @inject diff --git a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOrderFilterTranslationTest.php b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOrderFilterTranslationTest.php index eabbc50a04..3fc2b33ce9 100644 --- a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOrderFilterTranslationTest.php +++ b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchOrderFilterTranslationTest.php @@ -6,9 +6,12 @@ use Shopsys\FrameworkBundle\Form\Admin\AdvancedSearch\AdvancedSearchOrderFilterTranslation; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AdvancedSearchOrderFilterTranslationTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\AdvancedSearch\OrderAdvancedSearchConfig * @inject diff --git a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchProductFilterTranslationTest.php b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchProductFilterTranslationTest.php index 0c76c6c599..16f6bf634e 100644 --- a/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchProductFilterTranslationTest.php +++ b/tests/App/Functional/Form/Admin/AdvancedSearch/AdvancedSearchProductFilterTranslationTest.php @@ -6,9 +6,12 @@ use Shopsys\FrameworkBundle\Form\Admin\AdvancedSearch\AdvancedSearchProductFilterTranslation; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AdvancedSearchProductFilterTranslationTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\AdvancedSearch\ProductAdvancedSearchConfig * @inject diff --git a/tests/App/Functional/Model/Administrator/AdministratorRepositoryTest.php b/tests/App/Functional/Model/Administrator/AdministratorRepositoryTest.php index 32bde31375..9cd973eeaf 100644 --- a/tests/App/Functional/Model/Administrator/AdministratorRepositoryTest.php +++ b/tests/App/Functional/Model/Administrator/AdministratorRepositoryTest.php @@ -7,9 +7,12 @@ use App\DataFixtures\Demo\AdministratorDataFixture; use DateTime; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AdministratorRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Administrator\AdministratorRepository * @inject @@ -25,7 +28,7 @@ public function testGetByValidMultidomainLogin() $administrator = $this->getReference(AdministratorDataFixture::ADMINISTRATOR); $administrator->setMultidomainLoginTokenWithExpiration($validMultidomainLoginToken, $multidomainLoginTokenExpiration); - $this->getEntityManager()->flush($administrator); + $this->em->flush($administrator); $administratorFromDb = $this->administratorRepository->getByValidMultidomainLoginToken($validMultidomainLoginToken); @@ -42,7 +45,7 @@ public function testGetByValidMultidomainLoginTokenInvalidTokenException() $administrator = $this->getReference(AdministratorDataFixture::ADMINISTRATOR); $administrator->setMultidomainLoginTokenWithExpiration($validMultidomainLoginToken, $multidomainLoginTokenExpiration); - $this->getEntityManager()->flush($administrator); + $this->em->flush($administrator); $this->expectException('\Shopsys\FrameworkBundle\Model\Administrator\Security\Exception\InvalidTokenException'); @@ -58,7 +61,7 @@ public function testGetByValidMultidomainLoginTokenExpiredTokenException() $administrator = $this->getReference(AdministratorDataFixture::ADMINISTRATOR); $administrator->setMultidomainLoginTokenWithExpiration($validMultidomainLoginToken, $multidomainLoginTokenExpiration); - $this->getEntityManager()->flush($administrator); + $this->em->flush($administrator); $this->expectException('\Shopsys\FrameworkBundle\Model\Administrator\Security\Exception\InvalidTokenException'); diff --git a/tests/App/Functional/Model/Administrator/Security/AdministratorFrontSecurityFacadeTest.php b/tests/App/Functional/Model/Administrator/Security/AdministratorFrontSecurityFacadeTest.php index dba25f6684..7ed3190a52 100644 --- a/tests/App/Functional/Model/Administrator/Security/AdministratorFrontSecurityFacadeTest.php +++ b/tests/App/Functional/Model/Administrator/Security/AdministratorFrontSecurityFacadeTest.php @@ -8,9 +8,12 @@ use Shopsys\FrameworkBundle\Model\Administrator\Security\AdministratorFrontSecurityFacade; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AdministratorFrontSecurityFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Administrator\Security\AdministratorFrontSecurityFacade * @inject @@ -23,6 +26,12 @@ class AdministratorFrontSecurityFacadeTest extends TransactionFunctionalTestCase */ private $administratorActivityFacade; + /** + * @var \Symfony\Component\HttpFoundation\Session\SessionInterface + * @inject + */ + protected $session; + public function testIsAdministratorLoggedNot() { $this->assertFalse($this->administratorFrontSecurityFacade->isAdministratorLogged()); @@ -30,16 +39,13 @@ public function testIsAdministratorLoggedNot() public function testIsAdministratorLogged() { - /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */ - $session = $this->getContainer()->get('session'); - /** @var \App\Model\Administrator\Administrator $administrator */ $administrator = $this->getReference(AdministratorDataFixture::ADMINISTRATOR); $password = ''; $roles = $administrator->getRoles(); $token = new UsernamePasswordToken($administrator, $password, AdministratorFrontSecurityFacade::ADMINISTRATION_CONTEXT, $roles); - $session->set('_security_' . AdministratorFrontSecurityFacade::ADMINISTRATION_CONTEXT, serialize($token)); + $this->session->set('_security_' . AdministratorFrontSecurityFacade::ADMINISTRATION_CONTEXT, serialize($token)); $this->administratorActivityFacade->create($administrator, '127.0.0.1'); diff --git a/tests/App/Functional/Model/Article/ArticleTest.php b/tests/App/Functional/Model/Article/ArticleTest.php index e227c80c94..16cc89f2c4 100644 --- a/tests/App/Functional/Model/Article/ArticleTest.php +++ b/tests/App/Functional/Model/Article/ArticleTest.php @@ -7,9 +7,12 @@ use App\Model\Article\Article; use DateTime; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ArticleTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Article\ArticleDataFactoryInterface * @inject @@ -22,17 +25,6 @@ class ArticleTest extends TransactionFunctionalTestCase */ private $articleFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - public function testArticleIsCorrectlyRestoredFromDatabase() { /** @var \App\Model\Article\ArticleData $articleData */ diff --git a/tests/App/Functional/Model/Cart/CartFacadeDeleteOldCartsTest.php b/tests/App/Functional/Model/Cart/CartFacadeDeleteOldCartsTest.php index 72709a5289..33157d5de6 100644 --- a/tests/App/Functional/Model/Cart/CartFacadeDeleteOldCartsTest.php +++ b/tests/App/Functional/Model/Cart/CartFacadeDeleteOldCartsTest.php @@ -11,9 +11,12 @@ use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifier; use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifierFactory; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartFacadeDeleteOldCartsTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Cart\CartFactory * @inject @@ -82,8 +85,7 @@ public function testOldUnregisteredCustomerCartGetsDeleted() $cart->setModifiedAt(new DateTime('- 61 days')); - $em = $this->getEntityManager(); - $em->flush($cart); + $this->em->flush($cart); $cartFacade->deleteOldCarts(); @@ -98,8 +100,7 @@ public function testUnregisteredCustomerCartDoesNotGetDeleted() $cart->setModifiedAt(new DateTime('- 59 days')); - $em = $this->getEntityManager(); - $em->flush($cart); + $this->em->flush($cart); $cartFacade->deleteOldCarts(); @@ -114,8 +115,7 @@ public function testOldRegisteredCustomerCartGetsDeleted() $cart->setModifiedAt(new DateTime('- 121 days')); - $em = $this->getEntityManager(); - $em->flush($cart); + $this->em->flush($cart); $cartFacade->deleteOldCarts(); @@ -130,8 +130,7 @@ public function testRegisteredCustomerCartDoesNotGetDeletedIfItContainsRecentlyA $cart->setModifiedAt(new DateTime('- 119 days')); - $em = $this->getEntityManager(); - $em->flush($cart); + $this->em->flush($cart); $cartFacade->deleteOldCarts(); @@ -174,7 +173,7 @@ private function getCartFacadeForUnregisteredCustomer() private function getCartFacadeForCustomerUser(CustomerUserIdentifier $customerUserIdentifier) { return new CartFacade( - $this->getEntityManager(), + $this->em, $this->cartFactory, $this->productRepository, $this->getCustomerUserIdentifierFactoryMock($customerUserIdentifier), @@ -252,15 +251,13 @@ private function getCustomerUserIdentifierForUnregisteredCustomer() */ private function createCartWithProduct(CustomerUserIdentifier $customerUserIdentifier, CartFacade $cartFacade) { - $em = $this->getEntityManager(); - $product = $this->getProductById(1); $cart = $cartFacade->getCartByCustomerUserIdentifierCreateIfNotExists($customerUserIdentifier); $cartItem = new CartItem($cart, $product, 1, Money::zero()); - $em->persist($cartItem); - $em->flush(); + $this->em->persist($cartItem); + $this->em->flush(); $cart->addItem($cartItem); diff --git a/tests/App/Functional/Model/Cart/CartFacadeTest.php b/tests/App/Functional/Model/Cart/CartFacadeTest.php index f2d52c6616..b67daa41e9 100644 --- a/tests/App/Functional/Model/Cart/CartFacadeTest.php +++ b/tests/App/Functional/Model/Cart/CartFacadeTest.php @@ -10,9 +10,12 @@ use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifier; use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifierFactory; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Localization\TranslatableListener * @inject @@ -210,8 +213,8 @@ public function testCartNotExistIfNoListableProductIsInCart(int $productId, bool $cartItem = $this->cartItemFactory->create($cart, $product, 1, Money::create(10)); $cart->addItem($cartItem); - $this->getEntityManager()->persist($cartItem); - $this->getEntityManager()->flush(); + $this->em->persist($cartItem); + $this->em->flush(); $this->assertFalse($cart->isEmpty(), 'Cart should not be empty'); @@ -241,7 +244,7 @@ public function productCartDataProvider() private function createCartFacade(CustomerUserIdentifier $customerUserIdentifier) { return new CartFacade( - $this->getEntityManager(), + $this->em, $this->cartFactory, $this->productRepository, $this->getCustomerUserIdentifierFactoryMock($customerUserIdentifier), diff --git a/tests/App/Functional/Model/Cart/CartItemTest.php b/tests/App/Functional/Model/Cart/CartItemTest.php index 58097e0776..e27d8a5348 100644 --- a/tests/App/Functional/Model/Cart/CartItemTest.php +++ b/tests/App/Functional/Model/Cart/CartItemTest.php @@ -13,9 +13,12 @@ use Shopsys\FrameworkBundle\Model\Product\Availability\Availability; use Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartItemTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface * @inject @@ -30,8 +33,6 @@ class CartItemTest extends TransactionFunctionalTestCase public function testIsSimilarItemAs() { - $em = $this->getEntityManager(); - $customerUserIdentifier = new CustomerUserIdentifier('randomString'); $availabilityData = new AvailabilityData(); @@ -51,10 +52,10 @@ public function testIsSimilarItemAs() $product1 = Product::create($productData); $product2 = Product::create($productData); - $em->persist($availability); - $em->persist($product1); - $em->persist($product2); - $em->flush(); + $this->em->persist($availability); + $this->em->persist($product1); + $this->em->persist($product2); + $this->em->flush(); $cart = new Cart($customerUserIdentifier->getCartIdentifier()); diff --git a/tests/App/Functional/Model/Cart/CartMigrationFacadeTest.php b/tests/App/Functional/Model/Cart/CartMigrationFacadeTest.php index cd840e3c02..c9d766d53c 100644 --- a/tests/App/Functional/Model/Cart/CartMigrationFacadeTest.php +++ b/tests/App/Functional/Model/Cart/CartMigrationFacadeTest.php @@ -16,9 +16,12 @@ use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifier; use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserIdentifierFactory; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartMigrationFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Cart\Item\CartItemFactoryInterface * @inject diff --git a/tests/App/Functional/Model/Cart/CartTest.php b/tests/App/Functional/Model/Cart/CartTest.php index 748ee52b26..0cf416b9a7 100644 --- a/tests/App/Functional/Model/Cart/CartTest.php +++ b/tests/App/Functional/Model/Cart/CartTest.php @@ -14,9 +14,12 @@ use Shopsys\FrameworkBundle\Model\Product\Availability\Availability; use Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface * @inject @@ -31,8 +34,6 @@ class CartTest extends TransactionFunctionalTestCase public function testRemoveItem() { - $em = $this->getEntityManager(); - $customerUserIdentifier = new CustomerUserIdentifier('randomString'); $availabilityData = new AvailabilityData(); @@ -54,17 +55,17 @@ public function testRemoveItem() $cartItem2 = new CartItem($cart, $product2, 3, Money::zero()); $cart->addItem($cartItem2); - $em->persist($cart); - $em->persist($availability); - $em->persist($product1); - $em->persist($product2); - $em->persist($cartItem1); - $em->persist($cartItem2); - $em->flush(); + $this->em->persist($cart); + $this->em->persist($availability); + $this->em->persist($product1); + $this->em->persist($product2); + $this->em->persist($cartItem1); + $this->em->persist($cartItem2); + $this->em->flush(); $cart->removeItemById($cartItem1->getId()); - $em->remove($cartItem1); - $em->flush(); + $this->em->remove($cartItem1); + $this->em->flush(); $this->assertSame(1, $cart->getItemsCount()); } diff --git a/tests/App/Functional/Model/Cart/Watcher/CartWatcherTest.php b/tests/App/Functional/Model/Cart/Watcher/CartWatcherTest.php index aa725202c7..1efab637c3 100644 --- a/tests/App/Functional/Model/Cart/Watcher/CartWatcherTest.php +++ b/tests/App/Functional/Model/Cart/Watcher/CartWatcherTest.php @@ -18,9 +18,12 @@ use Shopsys\FrameworkBundle\Model\Product\ProductVisibility; use Shopsys\FrameworkBundle\Model\Product\ProductVisibilityRepository; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CartWatcherTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Pricing\ProductPriceCalculationForCustomerUser * @inject diff --git a/tests/App/Functional/Model/Category/CategoryDomainTest.php b/tests/App/Functional/Model/Category/CategoryDomainTest.php index ec0c3fe8e3..7d0aeb66fe 100644 --- a/tests/App/Functional/Model/Category/CategoryDomainTest.php +++ b/tests/App/Functional/Model/Category/CategoryDomainTest.php @@ -6,9 +6,12 @@ use App\Model\Category\Category; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CategoryDomainTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; protected const DEMONSTRATIVE_SEO_TITLE = 'Demonstrative seo title'; @@ -27,17 +30,6 @@ class CategoryDomainTest extends TransactionFunctionalTestCase */ private $categoryFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - public function testCreateCategoryEnabledOnDomain() { $categoryData = $this->categoryDataFactory->create(); diff --git a/tests/App/Functional/Model/Category/CategoryRepositoryTest.php b/tests/App/Functional/Model/Category/CategoryRepositoryTest.php index f2db122928..25773d0893 100644 --- a/tests/App/Functional/Model/Category/CategoryRepositoryTest.php +++ b/tests/App/Functional/Model/Category/CategoryRepositoryTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Category; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class CategoryRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; diff --git a/tests/App/Functional/Model/Customer/UserFacadeTest.php b/tests/App/Functional/Model/Customer/UserFacadeTest.php index dfb9bc2d5d..952b4daa1b 100644 --- a/tests/App/Functional/Model/Customer/UserFacadeTest.php +++ b/tests/App/Functional/Model/Customer/UserFacadeTest.php @@ -7,9 +7,12 @@ use App\DataFixtures\Demo\PricingGroupDataFixture; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class UserFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const EXISTING_EMAIL_ON_DOMAIN_1 = 'no-reply.3@shopsys.com'; protected const EXISTING_EMAIL_ON_DOMAIN_2 = 'no-reply.4@shopsys.com'; diff --git a/tests/App/Functional/Model/Newsletter/NewsletterRepository/GetAllEmailsDataIteratorMethodTest.php b/tests/App/Functional/Model/Newsletter/NewsletterRepository/GetAllEmailsDataIteratorMethodTest.php index 8de3eaa608..bc64353296 100644 --- a/tests/App/Functional/Model/Newsletter/NewsletterRepository/GetAllEmailsDataIteratorMethodTest.php +++ b/tests/App/Functional/Model/Newsletter/NewsletterRepository/GetAllEmailsDataIteratorMethodTest.php @@ -8,9 +8,12 @@ use PHPUnit\Framework\Assert; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class GetAllEmailsDataIteratorMethodTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_SUBSCRIBER_EMAIL = 'james.black@no-reply.com'; /** diff --git a/tests/App/Functional/Model/Newsletter/Subscriber/NewsletterSubscriberPersistenceTest.php b/tests/App/Functional/Model/Newsletter/Subscriber/NewsletterSubscriberPersistenceTest.php index 8dc53dc59e..574f940484 100644 --- a/tests/App/Functional/Model/Newsletter/Subscriber/NewsletterSubscriberPersistenceTest.php +++ b/tests/App/Functional/Model/Newsletter/Subscriber/NewsletterSubscriberPersistenceTest.php @@ -20,12 +20,11 @@ public function testPersistence(): void 1 ); - $em = $this->getEntityManager(); - $em->persist($newsletterSubscriber); - $em->flush(); - $em->clear(); + $this->em->persist($newsletterSubscriber); + $this->em->flush(); + $this->em->clear(); - $found = $em->createQueryBuilder() + $found = $this->em->createQueryBuilder() ->select('ns') ->from(NewsletterSubscriber::class, 'ns') ->where('ns.email = :email') diff --git a/tests/App/Functional/Model/Order/Mail/OrderMailTest.php b/tests/App/Functional/Model/Order/Mail/OrderMailTest.php index 8c51bd62da..b5f3f2dc77 100644 --- a/tests/App/Functional/Model/Order/Mail/OrderMailTest.php +++ b/tests/App/Functional/Model/Order/Mail/OrderMailTest.php @@ -19,7 +19,7 @@ use Shopsys\FrameworkBundle\Twig\PriceExtension; use Symfony\Component\Routing\RouterInterface; use Tests\App\Test\FunctionalTestCase; -use Twig_Environment; +use Twig\Environment; class OrderMailTest extends FunctionalTestCase { @@ -41,10 +41,10 @@ public function testGetMailTemplateNameByStatus() $mailTempleteName2 = OrderMail::getMailTemplateNameByStatus($orderStatus2); $this->assertNotEmpty($mailTempleteName1); - $this->assertInternalType('string', $mailTempleteName1); + $this->assertIsString($mailTempleteName1); $this->assertNotEmpty($mailTempleteName2); - $this->assertInternalType('string', $mailTempleteName2); + $this->assertIsString($mailTempleteName2); $this->assertNotSame($mailTempleteName1, $mailTempleteName2); } @@ -60,7 +60,7 @@ public function testGetMessageByOrder() ->getMock(); $domainRouterFactoryMock->expects($this->any())->method('getRouter')->willReturn($routerMock); - $twigMock = $this->getMockBuilder(Twig_Environment::class)->disableOriginalConstructor()->getMock(); + $twigMock = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); $orderItemPriceCalculationMock = $this->getMockBuilder(OrderItemPriceCalculation::class)->disableOriginalConstructor()->getMock(); $settingMock = $this->getMockBuilder(Setting::class)->disableOriginalConstructor()->getMock(); $priceExtensionMock = $this->getMockBuilder(PriceExtension::class)->disableOriginalConstructor()->getMock(); diff --git a/tests/App/Functional/Model/Order/OrderFacadeEditTest.php b/tests/App/Functional/Model/Order/OrderFacadeEditTest.php index b6a89c5344..68888b4b62 100644 --- a/tests/App/Functional/Model/Order/OrderFacadeEditTest.php +++ b/tests/App/Functional/Model/Order/OrderFacadeEditTest.php @@ -11,9 +11,12 @@ use Shopsys\FrameworkBundle\Model\Order\OrderData; use Tests\App\Test\TransactionFunctionalTestCase; use Tests\FrameworkBundle\Test\IsMoneyEqual; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; final class OrderFacadeEditTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + private const ORDER_ID = 10; private const PRODUCT_ITEM_ID = 45; private const PAYMENT_ITEM_ID = 46; diff --git a/tests/App/Functional/Model/Order/OrderFacadeTest.php b/tests/App/Functional/Model/Order/OrderFacadeTest.php index 914b034d71..f146bda172 100644 --- a/tests/App/Functional/Model/Order/OrderFacadeTest.php +++ b/tests/App/Functional/Model/Order/OrderFacadeTest.php @@ -12,9 +12,12 @@ use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Component\Money\Money; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class OrderFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Cart\CartFacade * @inject @@ -57,12 +60,6 @@ class OrderFacadeTest extends TransactionFunctionalTestCase */ private $paymentRepository; - /** - * @var \Shopsys\FrameworkBundle\Component\DataFixture\PersistentReferenceFacade - * @inject - */ - private $persistentReferenceFacade; - /** * @var \Shopsys\FrameworkBundle\Model\Order\OrderDataFactoryInterface * @inject @@ -83,7 +80,7 @@ public function testCreate() $orderData = new OrderData(); $orderData->transport = $transport; $orderData->payment = $payment; - $orderData->status = $this->persistentReferenceFacade->getReference(OrderStatusDataFixture::ORDER_STATUS_NEW); + $orderData->status = $this->getReference(OrderStatusDataFixture::ORDER_STATUS_NEW); $orderData->firstName = 'firstName'; $orderData->lastName = 'lastName'; $orderData->email = 'email'; @@ -94,7 +91,7 @@ public function testCreate() $orderData->street = 'street'; $orderData->city = 'city'; $orderData->postcode = 'postcode'; - $orderData->country = $this->persistentReferenceFacade->getReference(CountryDataFixture::COUNTRY_CZECH_REPUBLIC); + $orderData->country = $this->getReference(CountryDataFixture::COUNTRY_CZECH_REPUBLIC); $orderData->deliveryAddressSameAsBillingAddress = false; $orderData->deliveryFirstName = 'deliveryFirstName'; $orderData->deliveryLastName = 'deliveryLastName'; @@ -103,7 +100,7 @@ public function testCreate() $orderData->deliveryStreet = 'deliveryStreet'; $orderData->deliveryCity = 'deliveryCity'; $orderData->deliveryPostcode = 'deliveryPostcode'; - $orderData->deliveryCountry = $this->persistentReferenceFacade->getReference(CountryDataFixture::COUNTRY_CZECH_REPUBLIC); + $orderData->deliveryCountry = $this->getReference(CountryDataFixture::COUNTRY_CZECH_REPUBLIC); $orderData->note = 'note'; $orderData->domainId = Domain::FIRST_DOMAIN_ID; $orderData->currency = $this->getReference(CurrencyDataFixture::CURRENCY_CZK); diff --git a/tests/App/Functional/Model/Order/OrderNumberSequenceRepositoryTest.php b/tests/App/Functional/Model/Order/OrderNumberSequenceRepositoryTest.php index 7a110038c9..2c1ab2a0ba 100644 --- a/tests/App/Functional/Model/Order/OrderNumberSequenceRepositoryTest.php +++ b/tests/App/Functional/Model/Order/OrderNumberSequenceRepositoryTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Order; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class OrderNumberSequenceRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Order\OrderNumberSequenceRepository * @inject diff --git a/tests/App/Functional/Model/Order/OrderTransportAndPaymentTest.php b/tests/App/Functional/Model/Order/OrderTransportAndPaymentTest.php index 3c6aa28db3..8e2c5722dd 100644 --- a/tests/App/Functional/Model/Order/OrderTransportAndPaymentTest.php +++ b/tests/App/Functional/Model/Order/OrderTransportAndPaymentTest.php @@ -8,9 +8,12 @@ use App\Model\Transport\Transport; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class OrderTransportAndPaymentTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Transport\TransportFacade * @inject @@ -37,8 +40,6 @@ class OrderTransportAndPaymentTest extends TransactionFunctionalTestCase public function testVisibleTransport() { - $em = $this->getEntityManager(); - $enabledForDomains = [ Domain::FIRST_DOMAIN_ID => true, Domain::SECOND_DOMAIN_ID => false, @@ -48,10 +49,10 @@ public function testVisibleTransport() $payment->addTransport($transport); - $em->persist($transport); - $em->flush(); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -61,8 +62,6 @@ public function testVisibleTransport() public function testVisibleTransportHiddenTransport() { - $em = $this->getEntityManager(); - $enabledOnDomains = [ 1 => true, 2 => false, @@ -72,9 +71,9 @@ public function testVisibleTransportHiddenTransport() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -84,8 +83,6 @@ public function testVisibleTransportHiddenTransport() public function testVisibleTransportHiddenPayment() { - $em = $this->getEntityManager(); - $transportEnabledForDomains = [ 1 => true, 2 => false, @@ -100,9 +97,9 @@ public function testVisibleTransportHiddenPayment() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -112,16 +109,14 @@ public function testVisibleTransportHiddenPayment() public function testVisibleTransportNoPayment() { - $em = $this->getEntityManager(); - $enabledForDomains = [ 1 => true, 2 => false, ]; $transport = $this->getDefaultTransport($enabledForDomains, false); - $em->persist($transport); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -131,8 +126,6 @@ public function testVisibleTransportNoPayment() public function testVisibleTransportOnDifferentDomain() { - $em = $this->getEntityManager(); - $paymentEnabledForDomains = [ 1 => true, 2 => false, @@ -147,9 +140,9 @@ public function testVisibleTransportOnDifferentDomain() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -159,8 +152,6 @@ public function testVisibleTransportOnDifferentDomain() public function testVisibleTransportPaymentOnDifferentDomain() { - $em = $this->getEntityManager(); - $paymentEnabledForDomains = [ 1 => false, 2 => true, @@ -173,9 +164,9 @@ public function testVisibleTransportPaymentOnDifferentDomain() $payment = $this->getDefaultPayment($paymentEnabledForDomains, false); $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); $visibleTransports = $this->transportFacade->getVisibleOnCurrentDomain($visiblePayments); @@ -185,8 +176,6 @@ public function testVisibleTransportPaymentOnDifferentDomain() public function testVisiblePayment() { - $em = $this->getEntityManager(); - $enabledForDomains = [ 1 => true, 2 => false, @@ -196,9 +185,9 @@ public function testVisiblePayment() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); @@ -207,8 +196,6 @@ public function testVisiblePayment() public function testVisiblePaymentHiddenTransport() { - $em = $this->getEntityManager(); - $enabledForDomains = [ 1 => true, 2 => false, @@ -218,9 +205,9 @@ public function testVisiblePaymentHiddenTransport() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); @@ -229,8 +216,6 @@ public function testVisiblePaymentHiddenTransport() public function testVisiblePaymentHiddenPayment() { - $em = $this->getEntityManager(); - $enabledForDomains = [ 1 => true, 2 => false, @@ -240,9 +225,9 @@ public function testVisiblePaymentHiddenPayment() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); @@ -251,16 +236,14 @@ public function testVisiblePaymentHiddenPayment() public function testVisiblePaymentNoTransport() { - $em = $this->getEntityManager(); - $enabledForDomains = [ 1 => true, 2 => false, ]; $payment = $this->getDefaultPayment($enabledForDomains, false); - $em->persist($payment); - $em->flush(); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); @@ -269,8 +252,6 @@ public function testVisiblePaymentNoTransport() public function testVisiblePaymentOnDifferentDomain() { - $em = $this->getEntityManager(); - $transportEnabledForDomains = [ 1 => true, 2 => false, @@ -283,9 +264,9 @@ public function testVisiblePaymentOnDifferentDomain() $payment = $this->getDefaultPayment($paymentEnabledForDomains, false); $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); @@ -294,8 +275,6 @@ public function testVisiblePaymentOnDifferentDomain() public function testVisiblePaymentTransportOnDifferentDomain() { - $em = $this->getEntityManager(); - $transportEnabledForDomains = [ 1 => true, 2 => false, @@ -309,9 +288,9 @@ public function testVisiblePaymentTransportOnDifferentDomain() $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $visiblePayments = $this->paymentFacade->getVisibleOnCurrentDomain(); diff --git a/tests/App/Functional/Model/Order/Status/OrderStatusFacadeTest.php b/tests/App/Functional/Model/Order/Status/OrderStatusFacadeTest.php index 2eed1cbef1..e30a3ebee0 100644 --- a/tests/App/Functional/Model/Order/Status/OrderStatusFacadeTest.php +++ b/tests/App/Functional/Model/Order/Status/OrderStatusFacadeTest.php @@ -8,9 +8,12 @@ use App\DataFixtures\Demo\OrderStatusDataFixture; use Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class OrderStatusFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusFacade * @inject @@ -31,8 +34,6 @@ class OrderStatusFacadeTest extends TransactionFunctionalTestCase public function testDeleteByIdAndReplace() { - $em = $this->getEntityManager(); - $orderStatusData = new OrderStatusData(); $orderStatusData->name = ['cs' => 'name']; $orderStatusToDelete = $this->orderStatusFacade->create($orderStatusData); @@ -47,7 +48,7 @@ public function testDeleteByIdAndReplace() $this->orderStatusFacade->deleteById($orderStatusToDelete->getId(), $orderStatusToReplaceWith->getId()); - $em->refresh($order); + $this->em->refresh($order); $this->assertEquals($orderStatusToReplaceWith, $order->getStatus()); } diff --git a/tests/App/Functional/Model/Payment/IndependentPaymentVisibilityCalculationTest.php b/tests/App/Functional/Model/Payment/IndependentPaymentVisibilityCalculationTest.php index a4b306eb62..a96c505dd0 100644 --- a/tests/App/Functional/Model/Payment/IndependentPaymentVisibilityCalculationTest.php +++ b/tests/App/Functional/Model/Payment/IndependentPaymentVisibilityCalculationTest.php @@ -6,9 +6,12 @@ use App\Model\Payment\Payment; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class IndependentPaymentVisibilityCalculationTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; @@ -32,24 +35,20 @@ class IndependentPaymentVisibilityCalculationTest extends TransactionFunctionalT public function testIsIndependentlyVisible() { - $em = $this->getEntityManager(); - $enabledForDomains = [ self::FIRST_DOMAIN_ID => true, self::SECOND_DOMAIN_ID => true, ]; $payment = $this->getDefaultPayment($enabledForDomains, false); - $em->persist($payment); - $em->flush(); + $this->em->persist($payment); + $this->em->flush(); $this->assertTrue($this->independentPaymentVisibilityCalculation->isIndependentlyVisible($payment, self::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleEmptyName() { - $em = $this->getEntityManager(); - $paymentData = $this->paymentDataFactory->create(); $names = []; foreach ($this->localization->getLocalesOfAllDomains() as $locale) { @@ -64,40 +63,36 @@ public function testIsIndependentlyVisibleEmptyName() $payment = new Payment($paymentData); - $em->persist($payment); - $em->flush(); + $this->em->persist($payment); + $this->em->flush(); $this->assertFalse($this->independentPaymentVisibilityCalculation->isIndependentlyVisible($payment, self::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleNotOnDomain() { - $em = $this->getEntityManager(); - $enabledForDomains = [ self::FIRST_DOMAIN_ID => false, self::SECOND_DOMAIN_ID => false, ]; $payment = $this->getDefaultPayment($enabledForDomains, false); - $em->persist($payment); - $em->flush(); + $this->em->persist($payment); + $this->em->flush(); $this->assertFalse($this->independentPaymentVisibilityCalculation->isIndependentlyVisible($payment, self::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleHidden() { - $em = $this->getEntityManager(); - $enabledForDomains = [ self::FIRST_DOMAIN_ID => false, self::SECOND_DOMAIN_ID => false, ]; $payment = $this->getDefaultPayment($enabledForDomains, false); - $em->persist($payment); - $em->flush(); + $this->em->persist($payment); + $this->em->flush(); $this->assertFalse($this->independentPaymentVisibilityCalculation->isIndependentlyVisible($payment, self::FIRST_DOMAIN_ID)); } diff --git a/tests/App/Functional/Model/Payment/PaymentDomainTest.php b/tests/App/Functional/Model/Payment/PaymentDomainTest.php index f351172540..bc911532af 100644 --- a/tests/App/Functional/Model/Payment/PaymentDomainTest.php +++ b/tests/App/Functional/Model/Payment/PaymentDomainTest.php @@ -6,9 +6,12 @@ use App\Model\Payment\Payment; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class PaymentDomainTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; @@ -24,17 +27,6 @@ class PaymentDomainTest extends TransactionFunctionalTestCase */ private $paymentFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - public function testCreatePaymentEnabledOnDomain() { $paymentData = $this->paymentDataFactory->create(); diff --git a/tests/App/Functional/Model/Payment/PaymentTest.php b/tests/App/Functional/Model/Payment/PaymentTest.php index 25cc758aa8..de15cbefb5 100644 --- a/tests/App/Functional/Model/Payment/PaymentTest.php +++ b/tests/App/Functional/Model/Payment/PaymentTest.php @@ -7,9 +7,12 @@ use App\Model\Payment\Payment; use App\Model\Transport\Transport; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class PaymentTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Payment\PaymentDataFactoryInterface * @inject @@ -30,8 +33,6 @@ class PaymentTest extends TransactionFunctionalTestCase public function testRemoveTransportFromPaymentAfterDelete() { - $em = $this->getEntityManager(); - $transportData = $this->transportDataFactory->create(); $transportData->name['cs'] = 'name'; $transport = new Transport($transportData); @@ -42,9 +43,9 @@ public function testRemoveTransportFromPaymentAfterDelete() $payment = new Payment($paymentData); $payment->addTransport($transport); - $em->persist($transport); - $em->persist($payment); - $em->flush(); + $this->em->persist($transport); + $this->em->persist($payment); + $this->em->flush(); $this->transportFacade->deleteById($transport->getId()); diff --git a/tests/App/Functional/Model/Pricing/Group/PricingGroupFacadeTest.php b/tests/App/Functional/Model/Pricing/Group/PricingGroupFacadeTest.php index e109d6dc84..46534c7771 100644 --- a/tests/App/Functional/Model/Pricing/Group/PricingGroupFacadeTest.php +++ b/tests/App/Functional/Model/Pricing/Group/PricingGroupFacadeTest.php @@ -10,9 +10,12 @@ use Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroupData; use Shopsys\FrameworkBundle\Model\Product\Pricing\ProductCalculatedPrice; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class PricingGroupFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroupFacade * @inject @@ -45,7 +48,6 @@ class PricingGroupFacadeTest extends TransactionFunctionalTestCase public function testCreate() { - $em = $this->getEntityManager(); /** @var \App\Model\Product\Product $product */ $product = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '1'); @@ -54,7 +56,7 @@ public function testCreate() $domainId = Domain::FIRST_DOMAIN_ID; $pricingGroup = $this->pricingGroupFacade->create($pricingGroupData, $domainId); $this->productPriceRecalculator->runAllScheduledRecalculations(); - $productCalculatedPrice = $em->getRepository(ProductCalculatedPrice::class)->findOneBy([ + $productCalculatedPrice = $this->em->getRepository(ProductCalculatedPrice::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroup, ]); @@ -64,8 +66,6 @@ public function testCreate() public function testDeleteAndReplace() { - $em = $this->getEntityManager(); - $pricingGroupData = new PricingGroupData(); $pricingGroupData->name = 'name'; $pricingGroupToDelete = $this->pricingGroupFacade->create($pricingGroupData, Domain::FIRST_DOMAIN_ID); @@ -82,7 +82,7 @@ public function testDeleteAndReplace() $this->pricingGroupFacade->delete($pricingGroupToDelete->getId(), $pricingGroupToReplaceWith->getId()); - $em->refresh($customerUser); + $this->em->refresh($customerUser); $this->assertEquals($pricingGroupToReplaceWith, $customerUser->getPricingGroup()); } diff --git a/tests/App/Functional/Model/Pricing/InputPriceRecalculationSchedulerTest.php b/tests/App/Functional/Model/Pricing/InputPriceRecalculationSchedulerTest.php index 401a835547..23ec69cd71 100644 --- a/tests/App/Functional/Model/Pricing/InputPriceRecalculationSchedulerTest.php +++ b/tests/App/Functional/Model/Pricing/InputPriceRecalculationSchedulerTest.php @@ -16,9 +16,12 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Tests\App\Test\TransactionFunctionalTestCase; use Tests\FrameworkBundle\Test\IsMoneyEqual; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class InputPriceRecalculationSchedulerTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + private const METHOD_WITH_VAT = 'scheduleSetInputPricesWithVat'; private const METHOD_WITHOUT_VAT = 'scheduleSetInputPricesWithoutVat'; @@ -135,8 +138,6 @@ public function testOnKernelResponseRecalculateInputPricesWithVat( */ private function doTestOnKernelResponseRecalculateInputPrices(Money $inputPrice, Money $expectedPrice, $vatPercent, string $scheduleSetInputPricesMethod): void { - $em = $this->getEntityManager(); - $paymentData = $this->paymentDataFactory->create(); $transportData = $this->transportDataFactory->create(); @@ -150,8 +151,8 @@ private function doTestOnKernelResponseRecalculateInputPrices(Money $inputPrice, $availabilityData = new AvailabilityData(); $availabilityData->dispatchTime = 0; $availability = new Availability($availabilityData); - $em->persist($vat); - $em->persist($availability); + $this->em->persist($vat); + $this->em->persist($availability); $paymentData->name = ['cs' => 'name']; @@ -163,7 +164,7 @@ private function doTestOnKernelResponseRecalculateInputPrices(Money $inputPrice, /** @var \App\Model\Transport\Transport $transport */ $transport = $this->transportFacade->create($transportData); - $em->flush(); + $this->em->flush(); $filterResponseEventMock = $this->getMockBuilder(FilterResponseEvent::class) ->disableOriginalConstructor() @@ -180,8 +181,8 @@ private function doTestOnKernelResponseRecalculateInputPrices(Money $inputPrice, $this->inputPriceRecalculationScheduler->onKernelResponse($filterResponseEventMock); - $em->refresh($payment); - $em->refresh($transport); + $this->em->refresh($payment); + $this->em->refresh($transport); $this->assertThat($payment->getPrice(Domain::FIRST_DOMAIN_ID)->getPrice(), new IsMoneyEqual($expectedPrice)); $this->assertThat($transport->getPrice(Domain::FIRST_DOMAIN_ID)->getPrice(), new IsMoneyEqual($expectedPrice)); diff --git a/tests/App/Functional/Model/Pricing/ProductInputPriceRecalculatorTest.php b/tests/App/Functional/Model/Pricing/ProductInputPriceRecalculatorTest.php index 5d48bf5333..1e06202d12 100644 --- a/tests/App/Functional/Model/Pricing/ProductInputPriceRecalculatorTest.php +++ b/tests/App/Functional/Model/Pricing/ProductInputPriceRecalculatorTest.php @@ -14,9 +14,12 @@ use Shopsys\FrameworkBundle\Model\Product\Pricing\ProductManualInputPrice; use Tests\App\Test\TransactionFunctionalTestCase; use Tests\FrameworkBundle\Test\IsMoneyEqual; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductInputPriceRecalculatorTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Component\Setting\Setting * @inject diff --git a/tests/App/Functional/Model/Product/Availability/AvailabilityFacadeTest.php b/tests/App/Functional/Model/Product/Availability/AvailabilityFacadeTest.php index b7f7572c3c..ffa4826b4a 100644 --- a/tests/App/Functional/Model/Product/Availability/AvailabilityFacadeTest.php +++ b/tests/App/Functional/Model/Product/Availability/AvailabilityFacadeTest.php @@ -8,13 +8,11 @@ use Shopsys\FrameworkBundle\Model\Product\Availability\Availability; use Shopsys\FrameworkBundle\Model\Product\Product; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; final class AvailabilityFacadeTest extends TransactionFunctionalTestCase { - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; + use SymfonyTestContainer; /** * @var \Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityDataFactoryInterface @@ -40,12 +38,6 @@ final class AvailabilityFacadeTest extends TransactionFunctionalTestCase */ private $productFacade; - protected function setUp(): void - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - public function testDeleteByIdAndReplaceProductAvailability(): void { /** @var \App\Model\Product\Product $product */ diff --git a/tests/App/Functional/Model/Product/Availability/ProductAvailabilityCalculationTest.php b/tests/App/Functional/Model/Product/Availability/ProductAvailabilityCalculationTest.php index fe1a8e0906..0a029104fa 100644 --- a/tests/App/Functional/Model/Product/Availability/ProductAvailabilityCalculationTest.php +++ b/tests/App/Functional/Model/Product/Availability/ProductAvailabilityCalculationTest.php @@ -15,9 +15,12 @@ use Shopsys\FrameworkBundle\Model\Product\ProductSellingDeniedRecalculator; use Shopsys\FrameworkBundle\Model\Product\ProductVisibilityFacade; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductAvailabilityCalculationTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface * @inject @@ -35,36 +38,43 @@ class ProductAvailabilityCalculationTest extends FunctionalTestCase * @param mixed $usingStock * @param mixed $stockQuantity * @param mixed $outOfStockAction - * @param \Shopsys\FrameworkBundle\Model\Product\Availability\Availability|null $availability - * @param \Shopsys\FrameworkBundle\Model\Product\Availability\Availability|null $outOfStockAvailability - * @param \Shopsys\FrameworkBundle\Model\Product\Availability\Availability|null $defaultInStockAvailability - * @param \Shopsys\FrameworkBundle\Model\Product\Availability\Availability|null $expectedCalculatedAvailability + * @param string|null $availability + * @param string|null $outOfStockAvailability + * @param string|null $defaultInStockAvailability + * @param string|null $expectedCalculatedAvailability */ public function testCalculateAvailability( $usingStock, $stockQuantity, $outOfStockAction, - ?Availability $availability = null, - ?Availability $outOfStockAvailability = null, - ?Availability $defaultInStockAvailability = null, - ?Availability $expectedCalculatedAvailability = null + ?string $availability = null, + ?string $outOfStockAvailability = null, + ?string $defaultInStockAvailability = null, + ?string $expectedCalculatedAvailability = null ) { $productData = $this->productDataFactory->create(); $productData->usingStock = $usingStock; $productData->stockQuantity = $stockQuantity; - $productData->availability = $availability; + + if ($availability !== null) { + $productData->availability = $this->getReference($availability); + } + $productData->outOfStockAction = $outOfStockAction; - $productData->outOfStockAvailability = $outOfStockAvailability; + + if ($outOfStockAvailability !== null) { + $productData->outOfStockAvailability = $this->getReference($outOfStockAvailability); + } + $this->setVats($productData); $product = Product::create($productData); $availabilityFacadeMock = $this->getMockBuilder(AvailabilityFacade::class) - ->setMethods(['getDefaultInStockAvailability']) ->disableOriginalConstructor() ->getMock(); $availabilityFacadeMock->expects($this->any())->method('getDefaultInStockAvailability') - ->willReturn($defaultInStockAvailability); + ->willReturn($this->getReference($defaultInStockAvailability)); $productSellingDeniedRecalculatorMock = $this->createMock(ProductSellingDeniedRecalculator::class); $productVisibilityFacadeMock = $this->createMock(ProductVisibilityFacade::class); @@ -81,7 +91,7 @@ public function testCalculateAvailability( $calculatedAvailability = $productAvailabilityCalculation->calculateAvailability($product); - $this->assertSame($expectedCalculatedAvailability, $calculatedAvailability); + $this->assertSame($this->getReference($expectedCalculatedAvailability), $calculatedAvailability); } public function getTestCalculateAvailabilityData() @@ -91,46 +101,46 @@ public function getTestCalculateAvailabilityData() 'usingStock' => false, 'stockQuantity' => null, 'outOfStockAction' => null, - 'availability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), + 'availability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, 'outOfStockAvailability' => null, - 'defaultInStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), - 'calculatedAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), + 'defaultInStockAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, + 'calculatedAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, ], [ 'usingStock' => true, 'stockQuantity' => null, 'outOfStockAction' => Product::OUT_OF_STOCK_ACTION_HIDE, - 'availability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), + 'availability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, 'outOfStockAvailability' => null, - 'defaultInStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), - 'calculatedAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), + 'defaultInStockAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, + 'calculatedAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, ], [ 'usingStock' => true, 'stockQuantity' => 5, 'outOfStockAction' => Product::OUT_OF_STOCK_ACTION_SET_ALTERNATE_AVAILABILITY, 'availability' => null, - 'outOfStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK), - 'defaultInStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), - 'calculatedAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), + 'outOfStockAvailability' => AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK, + 'defaultInStockAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, + 'calculatedAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, ], [ 'usingStock' => true, 'stockQuantity' => 0, 'outOfStockAction' => Product::OUT_OF_STOCK_ACTION_SET_ALTERNATE_AVAILABILITY, 'availability' => null, - 'outOfStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK), - 'defaultInStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), - 'calculatedAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK), + 'outOfStockAvailability' => AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK, + 'defaultInStockAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, + 'calculatedAvailability' => AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK, ], [ 'usingStock' => true, 'stockQuantity' => -1, 'outOfStockAction' => Product::OUT_OF_STOCK_ACTION_SET_ALTERNATE_AVAILABILITY, 'availability' => null, - 'outOfStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK), - 'defaultInStockAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_IN_STOCK), - 'calculatedAvailability' => $this->getReference(AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK), + 'outOfStockAvailability' => AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK, + 'defaultInStockAvailability' => AvailabilityDataFixture::AVAILABILITY_IN_STOCK, + 'calculatedAvailability' => AvailabilityDataFixture::AVAILABILITY_OUT_OF_STOCK, ], ]; } diff --git a/tests/App/Functional/Model/Product/Availability/ProductAvailabilityRecalculatorTest.php b/tests/App/Functional/Model/Product/Availability/ProductAvailabilityRecalculatorTest.php index 143b6d7651..efff3df42b 100644 --- a/tests/App/Functional/Model/Product/Availability/ProductAvailabilityRecalculatorTest.php +++ b/tests/App/Functional/Model/Product/Availability/ProductAvailabilityRecalculatorTest.php @@ -7,9 +7,12 @@ use App\DataFixtures\Demo\AvailabilityDataFixture; use App\Model\Product\Product; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductAvailabilityRecalculatorTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductFacade * @inject @@ -46,8 +49,8 @@ public function testRecalculateOnProductEditNotUsingStock() $this->productFacade->edit($productId, $productData); $this->productAvailabilityRecalculator->runAllScheduledRecalculations(); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); + $this->em->flush(); + $this->em->clear(); $productFromDb = $this->productFacade->getById($productId); @@ -68,8 +71,8 @@ public function testRecalculateOnProductEditUsingStockInStock() $this->productFacade->edit($productId, $productData); $this->productAvailabilityRecalculator->runAllScheduledRecalculations(); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); + $this->em->flush(); + $this->em->clear(); $productFromDb = $this->productFacade->getById($productId); @@ -91,8 +94,8 @@ public function testRecalculateOnProductEditUsingStockOutOfStock() $this->productFacade->edit($productId, $productData); $this->productAvailabilityRecalculator->runAllScheduledRecalculations(); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); + $this->em->flush(); + $this->em->clear(); $productFromDb = $this->productFacade->getById($productId); diff --git a/tests/App/Functional/Model/Product/Brand/BrandDomainTest.php b/tests/App/Functional/Model/Product/Brand/BrandDomainTest.php index a6ea494d5f..c28a8cf05d 100644 --- a/tests/App/Functional/Model/Product/Brand/BrandDomainTest.php +++ b/tests/App/Functional/Model/Product/Brand/BrandDomainTest.php @@ -6,9 +6,12 @@ use App\Model\Product\Brand\Brand; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class BrandDomainTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; protected const DEMONSTRATIVE_SEO_TITLE = 'Demonstrative seo title'; @@ -26,17 +29,6 @@ class BrandDomainTest extends TransactionFunctionalTestCase */ private $brandFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - /** * @group multidomain */ diff --git a/tests/App/Functional/Model/Product/Elasticsearch/ProductExportRepositoryTest.php b/tests/App/Functional/Model/Product/Elasticsearch/ProductExportRepositoryTest.php index 32bb5bcb58..1bf8c51ac4 100644 --- a/tests/App/Functional/Model/Product/Elasticsearch/ProductExportRepositoryTest.php +++ b/tests/App/Functional/Model/Product/Elasticsearch/ProductExportRepositoryTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Product\Elasticsearch; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductExportRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Elasticsearch\ProductExportRepository * @inject diff --git a/tests/App/Functional/Model/Product/Filter/BrandFilterChoiceRepositoryTest.php b/tests/App/Functional/Model/Product/Filter/BrandFilterChoiceRepositoryTest.php index dd13e950da..fca9b82a86 100644 --- a/tests/App/Functional/Model/Product/Filter/BrandFilterChoiceRepositoryTest.php +++ b/tests/App/Functional/Model/Product/Filter/BrandFilterChoiceRepositoryTest.php @@ -9,9 +9,12 @@ use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Product\Brand\Brand; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class BrandFilterChoiceRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Filter\BrandFilterChoiceRepository * @inject diff --git a/tests/App/Functional/Model/Product/Filter/FlagFilterChoiceRepositoryTest.php b/tests/App/Functional/Model/Product/Filter/FlagFilterChoiceRepositoryTest.php index 7ffca9c2a6..fde9d588c1 100644 --- a/tests/App/Functional/Model/Product/Filter/FlagFilterChoiceRepositoryTest.php +++ b/tests/App/Functional/Model/Product/Filter/FlagFilterChoiceRepositoryTest.php @@ -9,9 +9,12 @@ use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Product\Flag\Flag; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class FlagFilterChoiceRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Filter\FlagFilterChoiceRepository * @inject diff --git a/tests/App/Functional/Model/Product/Filter/ParameterFilterChoiceRepositoryTest.php b/tests/App/Functional/Model/Product/Filter/ParameterFilterChoiceRepositoryTest.php index cf7f55eb89..a29ef09dba 100644 --- a/tests/App/Functional/Model/Product/Filter/ParameterFilterChoiceRepositoryTest.php +++ b/tests/App/Functional/Model/Product/Filter/ParameterFilterChoiceRepositoryTest.php @@ -8,9 +8,12 @@ use App\DataFixtures\Demo\PricingGroupDataFixture; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Tests\App\Test\ParameterTransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ParameterFilterChoiceRepositoryTest extends ParameterTransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Filter\ParameterFilterChoiceRepository * @inject diff --git a/tests/App/Functional/Model/Product/ProductDomainTest.php b/tests/App/Functional/Model/Product/ProductDomainTest.php index fd638c7dc1..769d3de5e8 100644 --- a/tests/App/Functional/Model/Product/ProductDomainTest.php +++ b/tests/App/Functional/Model/Product/ProductDomainTest.php @@ -8,9 +8,12 @@ use App\Model\Product\Product; use App\Model\Product\ProductData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductDomainTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; protected const DEMONSTRATIVE_DESCRIPTION = 'Demonstrative description'; @@ -31,23 +34,12 @@ class ProductDomainTest extends TransactionFunctionalTestCase */ private $productFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - /** * @var \Shopsys\FrameworkBundle\Model\Pricing\Vat\VatFacade * @inject */ private $vatFacade; - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - /** * @group multidomain */ diff --git a/tests/App/Functional/Model/Product/ProductFacadeTest.php b/tests/App/Functional/Model/Product/ProductFacadeTest.php index 1331a07b69..f398454136 100644 --- a/tests/App/Functional/Model/Product/ProductFacadeTest.php +++ b/tests/App/Functional/Model/Product/ProductFacadeTest.php @@ -11,9 +11,12 @@ use App\Model\Product\ProductData; use ReflectionClass; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface * @inject @@ -68,7 +71,7 @@ public function testHandleOutOfStockState( $product = $this->productFacade->create($productData); - $this->getEntityManager()->clear(); + $this->em->clear(); $productFromDb = $this->productFacade->getById($product->getId()); diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeCountDataTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeCountDataTest.php index 2f77f4e4aa..755a326398 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeCountDataTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeCountDataTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Product; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductOnCurrentDomainElasticFacadeCountDataTest extends ProductOnCurrentDomainFacadeCountDataTest { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainElasticFacade * @inject diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeTest.php index de431e0b5b..1d9d5bf008 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Product; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductOnCurrentDomainElasticFacadeTest extends ProductOnCurrentDomainFacadeTest { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainElasticFacade * @inject diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php index ed3fa047e0..c0246eb7af 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php @@ -15,9 +15,12 @@ use Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterValue; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; use Tests\App\Test\ParameterTransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; abstract class ProductOnCurrentDomainFacadeCountDataTest extends ParameterTransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfigFactory * @inject @@ -41,7 +44,7 @@ abstract class ProductOnCurrentDomainFacadeCountDataTest extends ParameterTransa */ protected $productOnCurrentDomainFacade; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->productOnCurrentDomainFacade = $this->getProductOnCurrentDomainFacade(); @@ -90,7 +93,7 @@ public function testSearch(): void $this->skipTestIfFirstDomainIsNotInEnglish(); foreach ($this->searchTestCasesProvider() as $dataProvider) { - /** @var string $category */ + /** @var string $searchText */ $searchText = $dataProvider[0]; /** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData $filterData */ $filterData = $dataProvider[1]; @@ -637,14 +640,12 @@ private function createParameterFilterData(array $namesByLocale, array $valuesTe */ private function getParameterValuesByLocalesAndTexts(array $valuesTextsByLocales) { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $parameterValues = []; foreach ($valuesTextsByLocales as $valueTextsByLocales) { foreach ($valueTextsByLocales as $locale => $text) { /** @var \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterValue $parameterValue */ - $parameterValue = $em->getRepository(ParameterValue::class)->findOneBy([ + $parameterValue = $this->em->getRepository(ParameterValue::class)->findOneBy([ 'text' => $text, 'locale' => $locale, ]); diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeTest.php index 131a493b0e..41dfa1b62e 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeTest.php @@ -18,9 +18,12 @@ use Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterValue; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; abstract class ProductOnCurrentDomainFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterRepository * @inject @@ -226,14 +229,12 @@ private function createParameterFilterData(array $namesByLocale, array $valuesTe */ private function getParameterValuesByLocalesAndTexts(array $valuesTextsByLocales) { - /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $parameterValues = []; foreach ($valuesTextsByLocales as $valueTextsByLocales) { foreach ($valueTextsByLocales as $locale => $text) { /** @var \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterValue $parameterValue */ - $parameterValue = $em->getRepository(ParameterValue::class)->findOneBy([ + $parameterValue = $this->em->getRepository(ParameterValue::class)->findOneBy([ 'text' => $text, 'locale' => $locale, ]); diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeCountDataTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeCountDataTest.php index a09bb7b6c6..52362160f3 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeCountDataTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeCountDataTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Product; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductOnCurrentDomainSqlFacadeCountDataTest extends ProductOnCurrentDomainFacadeCountDataTest { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacade * @inject diff --git a/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeTest.php b/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeTest.php index cf3d3392b7..4f4ecb7a78 100644 --- a/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeTest.php +++ b/tests/App/Functional/Model/Product/ProductOnCurrentDomainSqlFacadeTest.php @@ -5,9 +5,12 @@ namespace Tests\App\Functional\Model\Product; use Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacadeInterface; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductOnCurrentDomainSqlFacadeTest extends ProductOnCurrentDomainFacadeTest { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductOnCurrentDomainFacade * @inject diff --git a/tests/App/Functional/Model/Product/ProductRepositoryTest.php b/tests/App/Functional/Model/Product/ProductRepositoryTest.php index 19e0136a13..95cccbd1f1 100644 --- a/tests/App/Functional/Model/Product/ProductRepositoryTest.php +++ b/tests/App/Functional/Model/Product/ProductRepositoryTest.php @@ -13,9 +13,12 @@ use Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData; use Shopsys\FrameworkBundle\Model\Product\Listing\ProductListOrderingConfig; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductRepository * @inject @@ -202,10 +205,13 @@ public function testGetSortedProductsByIds() /** @var \Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroup $pricingGroup */ $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); - /** @var \App\Model\Product\Product $product */ + /** @var \App\Model\Product\Product $product1 */ $product1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . 1); + /** @var \App\Model\Product\Product $product2 */ $product2 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . 2); + /** @var \App\Model\Product\Product $product3 */ $product3 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . 3); + /** @var \App\Model\Product\Product $product4 */ $product4 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . 4); $sortedProducts = [ diff --git a/tests/App/Functional/Model/Product/ProductSellingDeniedRecalculatorTest.php b/tests/App/Functional/Model/Product/ProductSellingDeniedRecalculatorTest.php index b150ca829c..f5afa40f20 100644 --- a/tests/App/Functional/Model/Product/ProductSellingDeniedRecalculatorTest.php +++ b/tests/App/Functional/Model/Product/ProductSellingDeniedRecalculatorTest.php @@ -6,9 +6,12 @@ use App\DataFixtures\Demo\ProductDataFixture; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductSellingDeniedRecalculatorTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductSellingDeniedRecalculator * @inject @@ -29,8 +32,6 @@ class ProductSellingDeniedRecalculatorTest extends TransactionFunctionalTestCase public function testCalculateSellingDeniedForProductSellableVariant() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -46,10 +47,10 @@ public function testCalculateSellingDeniedForProductSellableVariant() $this->productSellingDeniedRecalculator->calculateSellingDeniedForProduct($variant1); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertTrue($variant1->getCalculatedSellingDenied()); $this->assertFalse($variant2->getCalculatedSellingDenied()); @@ -59,8 +60,6 @@ public function testCalculateSellingDeniedForProductSellableVariant() public function testCalculateSellingDeniedForProductNotSellableVariants() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -82,10 +81,10 @@ public function testCalculateSellingDeniedForProductNotSellableVariants() $this->productSellingDeniedRecalculator->calculateSellingDeniedForProduct($mainVariant); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertTrue($variant1->getCalculatedSellingDenied()); $this->assertTrue($variant2->getCalculatedSellingDenied()); @@ -95,8 +94,6 @@ public function testCalculateSellingDeniedForProductNotSellableVariants() public function testCalculateSellingDeniedForProductNotSellableMainVariant() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -112,10 +109,10 @@ public function testCalculateSellingDeniedForProductNotSellableMainVariant() $this->productSellingDeniedRecalculator->calculateSellingDeniedForProduct($mainVariant); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertTrue($variant1->getCalculatedSellingDenied()); $this->assertTrue($variant2->getCalculatedSellingDenied()); diff --git a/tests/App/Functional/Model/Product/ProductVariantCreationTest.php b/tests/App/Functional/Model/Product/ProductVariantCreationTest.php index 71ace0620e..a73041a130 100644 --- a/tests/App/Functional/Model/Product/ProductVariantCreationTest.php +++ b/tests/App/Functional/Model/Product/ProductVariantCreationTest.php @@ -8,9 +8,12 @@ use Shopsys\FrameworkBundle\Model\Product\Product; use Shopsys\FrameworkBundle\Model\Product\ProductData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; final class ProductVariantCreationTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductFacade * @inject diff --git a/tests/App/Functional/Model/Product/ProductVisibilityRepositoryTest.php b/tests/App/Functional/Model/Product/ProductVisibilityRepositoryTest.php index 8f28211a40..205823461b 100644 --- a/tests/App/Functional/Model/Product/ProductVisibilityRepositoryTest.php +++ b/tests/App/Functional/Model/Product/ProductVisibilityRepositoryTest.php @@ -18,9 +18,12 @@ use Shopsys\FrameworkBundle\Model\Product\ProductData; use Shopsys\FrameworkBundle\Model\Product\ProductVisibility; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ProductVisibilityRepositoryTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\ProductDataFactoryInterface * @inject @@ -87,14 +90,12 @@ private function getDefaultProductData() private function setVatsForAllDomains(ProductData $productData): void { $productVats = []; - $em = $this->getEntityManager(); - foreach ($this->domain->getAllIds() as $domainId) { $vatData = new VatData(); $vatData->name = 'vat'; $vatData->percent = '21'; $vat = new Vat($vatData, $domainId); - $em->persist($vat); + $this->em->persist($vat); $productVats[$domainId] = $vat; } @@ -119,27 +120,25 @@ private function setPriceForAllDomains(ProductData $productData, ?Money $price) public function testIsVisibleOnAnyDomainWhenHidden() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $productData->hidden = true; $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->flush(); + $this->em->flush(); $id = $product->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $productAgain */ - $productAgain = $em->getRepository(Product::class)->find($id); + $productAgain = $this->em->getRepository(Product::class)->find($id); /** @var \Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroup $pricingGroup */ $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility1 */ - $productVisibility1 = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility1 = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $productAgain, 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -151,26 +150,24 @@ public function testIsVisibleOnAnyDomainWhenHidden() public function testIsVisibleOnAnyDomainWhenNotHidden() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->flush(); + $this->em->flush(); $id = $product->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $productAgain */ - $productAgain = $em->getRepository(Product::class)->find($id); + $productAgain = $this->em->getRepository(Product::class)->find($id); /** @var \Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroup $pricingGroup */ $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility1 */ - $productVisibility1 = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility1 = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $productAgain->getId(), 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -182,8 +179,6 @@ public function testIsVisibleOnAnyDomainWhenNotHidden() public function testIsVisibleOnAnyDomainWhenSellingInFuture() { - $em = $this->getEntityManager(); - $sellingFrom = new DateTime('now'); $sellingFrom->modify('+1 day'); @@ -192,22 +187,20 @@ public function testIsVisibleOnAnyDomainWhenSellingInFuture() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->flush(); + $this->em->flush(); $id = $product->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $productAgain */ - $productAgain = $em->getRepository(Product::class)->find($id); + $productAgain = $this->em->getRepository(Product::class)->find($id); $this->assertFalse($productAgain->isVisible()); } public function testIsVisibleOnAnyDomainWhenSellingInPast() { - $em = $this->getEntityManager(); - $sellingTo = new DateTime('now'); $sellingTo->modify('-1 day'); @@ -216,22 +209,20 @@ public function testIsVisibleOnAnyDomainWhenSellingInPast() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->flush(); + $this->em->flush(); $id = $product->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $productAgain */ - $productAgain = $em->getRepository(Product::class)->find($id); + $productAgain = $this->em->getRepository(Product::class)->find($id); $this->assertFalse($productAgain->isVisible()); } public function testIsVisibleOnAnyDomainWhenSellingNow() { - $em = $this->getEntityManager(); - $sellingFrom = new DateTime('now'); $sellingFrom->modify('-1 day'); $sellingTo = new DateTime('now'); @@ -243,22 +234,20 @@ public function testIsVisibleOnAnyDomainWhenSellingNow() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->flush(); + $this->em->flush(); $id = $product->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $productAgain */ - $productAgain = $em->getRepository(Product::class)->find($id); + $productAgain = $this->em->getRepository(Product::class)->find($id); $this->assertTrue($productAgain->isVisible()); } public function testIsNotVisibleWhenZeroOrNullPrice() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $this->setPriceForAllDomains($productData, Money::zero()); $product1 = $this->productFacade->create($productData); @@ -269,14 +258,14 @@ public function testIsNotVisibleWhenZeroOrNullPrice() $product1Id = $product1->getId(); $product2Id = $product2->getId(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \App\Model\Product\Product $product1Again */ - $product1Again = $em->getRepository(Product::class)->find($product1Id); + $product1Again = $this->em->getRepository(Product::class)->find($product1Id); /** @var \App\Model\Product\Product $product2Again */ - $product2Again = $em->getRepository(Product::class)->find($product2Id); + $product2Again = $this->em->getRepository(Product::class)->find($product2Id); $this->assertFalse($product1Again->isVisible()); $this->assertFalse($product2Again->isVisible()); @@ -284,13 +273,11 @@ public function testIsNotVisibleWhenZeroOrNullPrice() public function testIsVisibleWithFilledName() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); @@ -298,7 +285,7 @@ public function testIsVisibleWithFilledName() $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility */ - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -309,14 +296,12 @@ public function testIsVisibleWithFilledName() public function testIsNotVisibleWithEmptyName() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $productData->name = ['cs' => null, 'en' => null]; $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); @@ -324,7 +309,7 @@ public function testIsNotVisibleWithEmptyName() $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility */ - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -335,8 +320,6 @@ public function testIsNotVisibleWithEmptyName() public function testIsVisibleInVisibileCategory() { - $em = $this->getEntityManager(); - /** @var \App\Model\Category\Category $category */ $category = $this->getReference(CategoryDataFixture::CATEGORY_TOYS); @@ -345,7 +328,7 @@ public function testIsVisibleInVisibileCategory() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); @@ -353,7 +336,7 @@ public function testIsVisibleInVisibileCategory() $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility */ - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -364,21 +347,19 @@ public function testIsVisibleInVisibileCategory() public function testIsNotVisibleInHiddenCategory() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $productData->categoriesByDomainId = []; $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroup $pricingGroup */ $pricingGroup = $this->getReferenceForDomain(PricingGroupDataFixture::PRICING_GROUP_ORDINARY, Domain::FIRST_DOMAIN_ID); - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroup->getId(), 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -389,8 +370,6 @@ public function testIsNotVisibleInHiddenCategory() public function testIsNotVisibleWhenZeroManualPrice() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $this->setPriceForAllDomains($productData, Money::create(10)); @@ -403,12 +382,12 @@ public function testIsNotVisibleWhenZeroManualPrice() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility */ - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroupWithZeroPriceId, 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -419,8 +398,6 @@ public function testIsNotVisibleWhenZeroManualPrice() public function testIsNotVisibleWhenNullManualPrice() { - $em = $this->getEntityManager(); - $productData = $this->getDefaultProductData(); $allPricingGroups = $this->pricingGroupFacade->getAll(); @@ -436,12 +413,12 @@ public function testIsNotVisibleWhenNullManualPrice() $product = $this->productFacade->create($productData); $this->productPriceRecalculator->runImmediateRecalculations(); - $em->clear(); + $this->em->clear(); $this->productVisibilityRepository->refreshProductsVisibility(); /** @var \Shopsys\FrameworkBundle\Model\Product\ProductVisibility $productVisibility */ - $productVisibility = $em->getRepository(ProductVisibility::class)->findOneBy([ + $productVisibility = $this->em->getRepository(ProductVisibility::class)->findOneBy([ 'product' => $product, 'pricingGroup' => $pricingGroupWithNullPriceId, 'domainId' => Domain::FIRST_DOMAIN_ID, @@ -452,8 +429,6 @@ public function testIsNotVisibleWhenNullManualPrice() public function testRefreshProductsVisibilityVisibleVariants() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -469,10 +444,10 @@ public function testRefreshProductsVisibilityVisibleVariants() $this->productVisibilityRepository->refreshProductsVisibility(true); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertFalse($variant1->isVisible()); $this->assertTrue($variant2->isVisible()); @@ -482,8 +457,6 @@ public function testRefreshProductsVisibilityVisibleVariants() public function testRefreshProductsVisibilityNotVisibleVariants() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -507,10 +480,10 @@ public function testRefreshProductsVisibilityNotVisibleVariants() $this->productVisibilityRepository->refreshProductsVisibility(true); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertFalse($variant1->isVisible()); $this->assertFalse($variant2->isVisible()); @@ -520,8 +493,6 @@ public function testRefreshProductsVisibilityNotVisibleVariants() public function testRefreshProductsVisibilityNotVisibleMainVariant() { - $em = $this->getEntityManager(); - /** @var \App\Model\Product\Product $variant1 */ $variant1 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '53'); /** @var \App\Model\Product\Product $variant2 */ @@ -537,10 +508,10 @@ public function testRefreshProductsVisibilityNotVisibleMainVariant() $this->productVisibilityRepository->refreshProductsVisibility(true); - $em->refresh($variant1); - $em->refresh($variant2); - $em->refresh($variant3); - $em->refresh($mainVariant); + $this->em->refresh($variant1); + $this->em->refresh($variant2); + $this->em->refresh($variant3); + $this->em->refresh($mainVariant); $this->assertFalse($variant1->isVisible()); $this->assertFalse($variant2->isVisible()); diff --git a/tests/App/Functional/Model/Product/Search/FilterQueryTest.php b/tests/App/Functional/Model/Product/Search/FilterQueryTest.php index 13d4912f42..2c2c9d8df9 100644 --- a/tests/App/Functional/Model/Product/Search/FilterQueryTest.php +++ b/tests/App/Functional/Model/Product/Search/FilterQueryTest.php @@ -11,9 +11,12 @@ use Shopsys\FrameworkBundle\Model\Product\Listing\ProductListOrderingConfig; use Shopsys\FrameworkBundle\Model\Product\Search\FilterQuery; use Tests\App\Test\ParameterTransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class FilterQueryTest extends ParameterTransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Elasticsearch\Client * @inject diff --git a/tests/App/Functional/Model/Security/AuthenticatorTest.php b/tests/App/Functional/Model/Security/AuthenticatorTest.php index 4b0f6c860c..3e3b174e6d 100644 --- a/tests/App/Functional/Model/Security/AuthenticatorTest.php +++ b/tests/App/Functional/Model/Security/AuthenticatorTest.php @@ -8,9 +8,12 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class AuthenticatorTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Security\Authenticator * @inject diff --git a/tests/App/Functional/Model/Transport/IndependentTransportVisibilityCalculationTest.php b/tests/App/Functional/Model/Transport/IndependentTransportVisibilityCalculationTest.php index de2197cca0..7cea8b33fd 100644 --- a/tests/App/Functional/Model/Transport/IndependentTransportVisibilityCalculationTest.php +++ b/tests/App/Functional/Model/Transport/IndependentTransportVisibilityCalculationTest.php @@ -7,9 +7,12 @@ use App\Model\Transport\Transport; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class IndependentTransportVisibilityCalculationTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Localization\Localization * @inject @@ -30,8 +33,6 @@ class IndependentTransportVisibilityCalculationTest extends TransactionFunctiona public function testIsIndependentlyVisible() { - $em = $this->getEntityManager(); - $enabledOnDomains = [ Domain::FIRST_DOMAIN_ID => true, Domain::SECOND_DOMAIN_ID => false, @@ -39,16 +40,14 @@ public function testIsIndependentlyVisible() $transport = $this->getDefaultTransport($enabledOnDomains, false); - $em->persist($transport); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); $this->assertTrue($this->independentTransportVisibilityCalculation->isIndependentlyVisible($transport, Domain::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleEmptyName() { - $em = $this->getEntityManager(); - $transportData = $this->transportDataFactory->create(); $names = []; foreach ($this->localization->getLocalesOfAllDomains() as $locale) { @@ -63,16 +62,14 @@ public function testIsIndependentlyVisibleEmptyName() $transport = new Transport($transportData); - $em->persist($transport); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); $this->assertFalse($this->independentTransportVisibilityCalculation->isIndependentlyVisible($transport, Domain::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleNotOnDomain() { - $em = $this->getEntityManager(); - $enabledOnDomains = [ Domain::FIRST_DOMAIN_ID => false, Domain::SECOND_DOMAIN_ID => false, @@ -80,16 +77,14 @@ public function testIsIndependentlyVisibleNotOnDomain() $transport = $this->getDefaultTransport($enabledOnDomains, false); - $em->persist($transport); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); $this->assertFalse($this->independentTransportVisibilityCalculation->isIndependentlyVisible($transport, Domain::FIRST_DOMAIN_ID)); } public function testIsIndependentlyVisibleHidden() { - $em = $this->getEntityManager(); - $enabledOnDomains = [ Domain::FIRST_DOMAIN_ID => true, Domain::SECOND_DOMAIN_ID => false, @@ -97,8 +92,8 @@ public function testIsIndependentlyVisibleHidden() $transport = $this->getDefaultTransport($enabledOnDomains, true); - $em->persist($transport); - $em->flush(); + $this->em->persist($transport); + $this->em->flush(); $this->assertFalse($this->independentTransportVisibilityCalculation->isIndependentlyVisible($transport, Domain::FIRST_DOMAIN_ID)); } diff --git a/tests/App/Functional/Model/Transport/TransportDomainTest.php b/tests/App/Functional/Model/Transport/TransportDomainTest.php index 1efb88fba5..16c38af99f 100644 --- a/tests/App/Functional/Model/Transport/TransportDomainTest.php +++ b/tests/App/Functional/Model/Transport/TransportDomainTest.php @@ -6,9 +6,12 @@ use App\Model\Transport\Transport; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class TransportDomainTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + protected const FIRST_DOMAIN_ID = 1; protected const SECOND_DOMAIN_ID = 2; @@ -24,17 +27,6 @@ class TransportDomainTest extends TransactionFunctionalTestCase */ private $transportFactory; - /** - * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator - */ - private $em; - - public function setUp() - { - parent::setUp(); - $this->em = $this->getEntityManager(); - } - public function testCreateTransportEnabledOnDomain() { $transportData = $this->transportDataFactory->create(); diff --git a/tests/App/Functional/Model/Unit/UnitFacadeTest.php b/tests/App/Functional/Model/Unit/UnitFacadeTest.php index 98ac0908a3..dc7b2de484 100644 --- a/tests/App/Functional/Model/Unit/UnitFacadeTest.php +++ b/tests/App/Functional/Model/Unit/UnitFacadeTest.php @@ -8,9 +8,12 @@ use App\DataFixtures\Demo\UnitDataFixture; use Shopsys\FrameworkBundle\Model\Product\Unit\UnitData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class UnitFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Product\Unit\UnitFacade * @inject @@ -31,8 +34,6 @@ class UnitFacadeTest extends TransactionFunctionalTestCase public function testDeleteByIdAndReplace() { - $em = $this->getEntityManager(); - $unitData = new UnitData(); $unitData->name = ['cs' => 'name']; $unitToDelete = $this->unitFacade->create($unitData); @@ -47,7 +48,7 @@ public function testDeleteByIdAndReplace() $this->unitFacade->deleteById($unitToDelete->getId(), $unitToReplaceWith->getId()); - $em->refresh($product); + $this->em->refresh($product); $this->assertEquals($unitToReplaceWith, $product->getUnit()); } diff --git a/tests/App/Functional/Model/Vat/VatFacadeTest.php b/tests/App/Functional/Model/Vat/VatFacadeTest.php index 68b81029b1..376fbbe6dc 100644 --- a/tests/App/Functional/Model/Vat/VatFacadeTest.php +++ b/tests/App/Functional/Model/Vat/VatFacadeTest.php @@ -10,9 +10,12 @@ use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Pricing\Vat\VatData; use Tests\App\Test\TransactionFunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class VatFacadeTest extends TransactionFunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Model\Pricing\Vat\VatFacade * @inject @@ -45,8 +48,6 @@ class VatFacadeTest extends TransactionFunctionalTestCase public function testDeleteByIdAndReplaceForFirstDomain() { - $em = $this->getEntityManager(); - $vatData = new VatData(); $vatData->name = 'name'; $vatData->percent = '10'; @@ -71,8 +72,8 @@ public function testDeleteByIdAndReplaceForFirstDomain() $this->vatFacade->deleteById($vatToDelete, $vatToReplaceWith); - $em->refresh($transport->getTransportDomain(Domain::FIRST_DOMAIN_ID)); - $em->refresh($payment->getPaymentDomain(Domain::FIRST_DOMAIN_ID)); + $this->em->refresh($transport->getTransportDomain(Domain::FIRST_DOMAIN_ID)); + $this->em->refresh($payment->getPaymentDomain(Domain::FIRST_DOMAIN_ID)); $this->assertEquals($vatToReplaceWith, $payment->getPaymentDomain(Domain::FIRST_DOMAIN_ID)->getVat()); $this->assertEquals($vatToReplaceWith, $transport->getTransportDomain(Domain::FIRST_DOMAIN_ID)->getVat()); diff --git a/tests/App/Functional/Twig/ImageExtensionTest.php b/tests/App/Functional/Twig/ImageExtensionTest.php index 3c9e21dd2e..228bb86fe3 100644 --- a/tests/App/Functional/Twig/ImageExtensionTest.php +++ b/tests/App/Functional/Twig/ImageExtensionTest.php @@ -9,9 +9,12 @@ use Shopsys\FrameworkBundle\Component\Image\ImageFacade; use Shopsys\FrameworkBundle\Twig\ImageExtension; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ImageExtensionTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\FrameworkBundle\Component\Image\ImageLocator * @inject @@ -20,7 +23,7 @@ class ImageExtensionTest extends FunctionalTestCase public function testGetImageHtmlWithAdditional(): void { - $templating = $this->getContainer()->get('templating'); + $templating = $this->getContainer()->get('twig'); $imageFacade = $this->createMock(ImageFacade::class); diff --git a/tests/App/Functional/Twig/NumberFormatterExtensionTest.php b/tests/App/Functional/Twig/NumberFormatterExtensionTest.php index f57db44ac6..51fde2793a 100644 --- a/tests/App/Functional/Twig/NumberFormatterExtensionTest.php +++ b/tests/App/Functional/Twig/NumberFormatterExtensionTest.php @@ -4,19 +4,17 @@ namespace Tests\App\Functional\Twig; +use CommerceGuys\Intl\NumberFormat\NumberFormatRepository; use Shopsys\FrameworkBundle\Model\Localization\Localization; use Shopsys\FrameworkBundle\Twig\NumberFormatterExtension; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class NumberFormatterExtensionTest extends FunctionalTestCase { - protected const NBSP = "\xc2\xa0"; + use SymfonyTestContainer; - /** - * @var \CommerceGuys\Intl\NumberFormat\NumberFormatRepository - * @inject - */ - private $numberFormatRepository; + protected const NBSP = "\xc2\xa0"; /** * @var \Shopsys\FrameworkBundle\Model\Administration\AdministrationFacade @@ -60,7 +58,7 @@ public function testFormatNumber($input, $locale, $result) $localizationMock->expects($this->any())->method('getLocale') ->willReturn($locale); - $numberFormatterExtension = new NumberFormatterExtension($localizationMock, $this->numberFormatRepository, $this->administrationFacade); + $numberFormatterExtension = new NumberFormatterExtension($localizationMock, new NumberFormatRepository(), $this->administrationFacade); $this->assertSame($result, $numberFormatterExtension->formatNumber($input, $locale)); } diff --git a/tests/App/Functional/Twig/PriceExtensionTest.php b/tests/App/Functional/Twig/PriceExtensionTest.php index 40c289f072..d760418ccb 100644 --- a/tests/App/Functional/Twig/PriceExtensionTest.php +++ b/tests/App/Functional/Twig/PriceExtensionTest.php @@ -4,20 +4,22 @@ namespace Tests\App\Functional\Twig; +use CommerceGuys\Intl\NumberFormat\NumberFormatRepository; use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Component\Money\Money; use Shopsys\FrameworkBundle\Component\Setting\Setting; use Shopsys\FrameworkBundle\Model\Localization\Localization; use Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency; -use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyDataFactoryInterface; use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade; -use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFactoryInterface; use Shopsys\FrameworkBundle\Twig\PriceExtension; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class PriceExtensionTest extends FunctionalTestCase { + use SymfonyTestContainer; + protected const NBSP = "\xc2\xa0"; /** @@ -27,18 +29,24 @@ class PriceExtensionTest extends FunctionalTestCase private $intlCurrencyRepository; /** - * @var \CommerceGuys\Intl\NumberFormat\NumberFormatRepository + * @var \Shopsys\FrameworkBundle\Component\CurrencyFormatter\CurrencyFormatterFactory * @inject */ - private $numberFormatRepository; + private $currencyFormatterFactory; /** - * @var \Shopsys\FrameworkBundle\Component\CurrencyFormatter\CurrencyFormatterFactory + * @var \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFactoryInterface * @inject */ - private $currencyFormatterFactory; + private $currencyFactory; - protected function setUp() + /** + * @var \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyDataFactoryInterface + * @inject + */ + private $currencyDataFactory; + + protected function setUp(): void { $domainConfig1 = new DomainConfig(Domain::FIRST_DOMAIN_ID, 'http://example.com', 'example', 'en'); $domainConfig2 = new DomainConfig(Domain::SECOND_DOMAIN_ID, 'http://example.com', 'example', 'cs'); @@ -116,27 +124,22 @@ public function testPriceFilter($input, $domainId, $result) */ private function getPriceExtensionWithMockedConfiguration(): PriceExtension { - /** @var \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFactoryInterface $currencyFactory */ - $currencyFactory = $this->getContainer()->get(CurrencyFactoryInterface::class); - /** @var \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyDataFactoryInterface $currencyFactory */ - $currencyDataFactory = $this->getContainer()->get(CurrencyDataFactoryInterface::class); - - $domain1DefaultCurrencyData = $currencyDataFactory->create(); + $domain1DefaultCurrencyData = $this->currencyDataFactory->create(); $domain1DefaultCurrencyData->name = 'Czech crown'; $domain1DefaultCurrencyData->code = Currency::CODE_CZK; - $domain1DefaultCurrencyData->exchangeRate = 1; + $domain1DefaultCurrencyData->exchangeRate = '1'; $domain1DefaultCurrencyData->minFractionDigits = 2; $domain1DefaultCurrencyData->roundingType = Currency::ROUNDING_TYPE_INTEGER; - $domain2DefaultCurrencyData = $currencyDataFactory->create(); + $domain2DefaultCurrencyData = $this->currencyDataFactory->create(); $domain2DefaultCurrencyData->name = 'Euro'; $domain2DefaultCurrencyData->code = Currency::CODE_EUR; - $domain2DefaultCurrencyData->exchangeRate = 25; + $domain2DefaultCurrencyData->exchangeRate = '25'; $domain1DefaultCurrencyData->minFractionDigits = 2; $domain1DefaultCurrencyData->roundingType = Currency::ROUNDING_TYPE_INTEGER; - $domain1DefaultCurrency = $currencyFactory->create($domain1DefaultCurrencyData); - $domain2DefaultCurrency = $currencyFactory->create($domain2DefaultCurrencyData); + $domain1DefaultCurrency = $this->currencyFactory->create($domain1DefaultCurrencyData); + $domain2DefaultCurrency = $this->currencyFactory->create($domain2DefaultCurrencyData); /** @var \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade|\PHPUnit\Framework\MockObject\MockObject $currencyFacadeMock */ $currencyFacadeMock = $this->getMockBuilder(CurrencyFacade::class) @@ -158,7 +161,7 @@ private function getPriceExtensionWithMockedConfiguration(): PriceExtension $currencyFacadeMock, $this->domain, $localization, - $this->numberFormatRepository, + new NumberFormatRepository(), $this->intlCurrencyRepository, $this->currencyFormatterFactory ); diff --git a/tests/App/Functional/Twig/TwigEnvironmentTest.php b/tests/App/Functional/Twig/TwigEnvironmentTest.php index 14d51670c0..84cf5a99f0 100644 --- a/tests/App/Functional/Twig/TwigEnvironmentTest.php +++ b/tests/App/Functional/Twig/TwigEnvironmentTest.php @@ -17,7 +17,7 @@ public function testGetFilterMethodIsCallableOnTwigEnvironment() { $twigEnvironment = $this->getContainer()->get('twig'); if (!is_callable([$twigEnvironment, 'getFilter'])) { - $this->fail('Method "getFilter" is not callable on Twig_Environment class'); + $this->fail('Method "getFilter" is not callable on Twig\Environment class'); } } } diff --git a/tests/App/Performance/Feed/AllFeedsTest.php b/tests/App/Performance/Feed/AllFeedsTest.php index 93de53db70..b5cccdbe3d 100644 --- a/tests/App/Performance/Feed/AllFeedsTest.php +++ b/tests/App/Performance/Feed/AllFeedsTest.php @@ -36,7 +36,7 @@ class AllFeedsTest extends KernelTestCase */ private $minDuration; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -45,7 +45,7 @@ protected function setUp() 'debug' => EnvironmentType::isDebug(EnvironmentType::TEST), ]); - $container = self::$kernel->getContainer(); + $container = static::bootKernel()->getContainer(); $container->get(Domain::class) ->switchDomainById(Domain::FIRST_DOMAIN_ID); @@ -89,7 +89,7 @@ public function testAllFeedsGeneration() $this->exportJmeterCsvReport( $performanceTestSamples, - self::$kernel->getContainer()->getParameter('shopsys.root_dir') . '/build/stats/performance-tests-feeds.csv' + static::bootKernel()->getContainer()->getParameter('shopsys.root_dir') . '/build/stats/performance-tests-feeds.csv' ); $this->assertSamplesAreSuccessful($performanceTestSamples); @@ -115,9 +115,9 @@ private function doTestFeedGeneration(FeedInfoInterface $feedInfo, DomainConfig public function getAllFeedGenerationData() { /** @var \Shopsys\FrameworkBundle\Model\Feed\FeedRegistry $feedRegistry */ - $feedRegistry = self::$kernel->getContainer()->get(FeedRegistry::class); + $feedRegistry = static::bootKernel()->getContainer()->get(FeedRegistry::class); /** @var \Shopsys\FrameworkBundle\Component\Domain\Domain $domain */ - $domain = self::$kernel->getContainer()->get(Domain::class); + $domain = static::bootKernel()->getContainer()->get(Domain::class); $dailyFeedGenerationData = $this->getFeedGenerationData( $feedRegistry->getFeeds('daily'), $domain->getAll(), @@ -184,7 +184,7 @@ private function generateFeed(FeedInfoInterface $feed, DomainConfig $domainConfi $this->setUp(); /** @var \Symfony\Component\Routing\RouterInterface $router */ - $router = self::$kernel->getContainer()->get('router'); + $router = static::bootKernel()->getContainer()->get('router'); $uri = $router->generate( self::ROUTE_NAME_GENERATE_FEED, @@ -198,7 +198,7 @@ private function generateFeed(FeedInfoInterface $feed, DomainConfig $domainConfi $auth->authenticateRequest($request); /** @var \Doctrine\ORM\EntityManager $entityManager */ - $entityManager = self::$kernel->getContainer()->get('doctrine.orm.entity_manager'); + $entityManager = static::bootKernel()->getContainer()->get('doctrine.orm.entity_manager'); $startTime = microtime(true); $entityManager->beginTransaction(); diff --git a/tests/App/Performance/Page/AllPagesTest.php b/tests/App/Performance/Page/AllPagesTest.php index b89fa3afdd..67a32a869d 100644 --- a/tests/App/Performance/Page/AllPagesTest.php +++ b/tests/App/Performance/Page/AllPagesTest.php @@ -24,7 +24,7 @@ class AllPagesTest extends KernelTestCase { protected const PASSES = 5; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -226,7 +226,6 @@ private function doAssert( case PerformanceTestSampleQualifier::STATUS_CRITICAL: default: $this->fail('Values are above critical threshold'); - return; } } diff --git a/tests/App/Smoke/AllFeedsTest.php b/tests/App/Smoke/AllFeedsTest.php index c6df4a0882..86ffe7d131 100644 --- a/tests/App/Smoke/AllFeedsTest.php +++ b/tests/App/Smoke/AllFeedsTest.php @@ -4,9 +4,7 @@ namespace Tests\App\Smoke; -use League\Flysystem\FilesystemInterface; use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; -use Shopsys\FrameworkBundle\Model\Feed\FeedFacade; use Shopsys\FrameworkBundle\Model\Feed\FeedInfoInterface; use Tests\App\Test\FunctionalTestCase; @@ -14,20 +12,16 @@ class AllFeedsTest extends FunctionalTestCase { /** * @var \Shopsys\FrameworkBundle\Model\Feed\FeedFacade + * @inject */ private $feedFacade; /** * @var \League\Flysystem\FilesystemInterface + * @inject */ private $filesystem; - protected function setUp() - { - $this->feedFacade = $this->getContainer()->get(FeedFacade::class); - $this->filesystem = $this->getContainer()->get(FilesystemInterface::class); - } - /** * @return array */ diff --git a/tests/App/Smoke/Http/HttpSmokeTest.php b/tests/App/Smoke/Http/HttpSmokeTest.php index f0696c6186..7f7c9e2bcc 100644 --- a/tests/App/Smoke/Http/HttpSmokeTest.php +++ b/tests/App/Smoke/Http/HttpSmokeTest.php @@ -11,7 +11,7 @@ class HttpSmokeTest extends HttpSmokeTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/App/Smoke/NewProductTest.php b/tests/App/Smoke/NewProductTest.php index a3f49e2257..37b6178528 100644 --- a/tests/App/Smoke/NewProductTest.php +++ b/tests/App/Smoke/NewProductTest.php @@ -7,6 +7,7 @@ use App\DataFixtures\Demo\AvailabilityDataFixture; use App\DataFixtures\Demo\UnitDataFixture; use App\DataFixtures\Demo\VatDataFixture; +use Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessage; use Shopsys\FrameworkBundle\Form\Admin\Product\ProductFormType; use Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroupFacade; use Symfony\Component\DomCrawler\Form; @@ -31,13 +32,13 @@ public function testCreateOrEditProduct($relativeUrl) 'HTTP_HOST' => sprintf('%s:%d', parse_url($domainUrl, PHP_URL_HOST), parse_url($domainUrl, PHP_URL_PORT)), ]; - $client1 = $this->getClient(false, 'admin', 'admin123'); + $client1 = $this->findClient(false, 'admin', 'admin123'); $crawler = $client1->request('GET', $relativeUrl, [], [], $server); $form = $crawler->filter('form[name=product_form]')->form(); $this->fillForm($form); - $client2 = $this->getClient(true, 'admin', 'admin123'); + $client2 = $this->findClient(true, 'admin', 'admin123'); /** @var \Doctrine\ORM\EntityManager $em2 */ $em2 = $client2->getContainer()->get('doctrine.orm.entity_manager'); @@ -52,12 +53,12 @@ public function testCreateOrEditProduct($relativeUrl) $em2->rollback(); - /** @var \Shopsys\FrameworkBundle\Component\FlashMessage\Bag $flashMessageBag */ - $flashMessageBag = $client2->getContainer()->get('shopsys.shop.component.flash_message.bag.admin'); + /** @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $flashBag */ + $flashBag = $client2->getContainer()->get('session')->getFlashBag(); $this->assertSame(302, $client2->getResponse()->getStatusCode()); - $this->assertNotEmpty($flashMessageBag->getSuccessMessages()); - $this->assertEmpty($flashMessageBag->getErrorMessages()); + $this->assertNotEmpty($flashBag->get(FlashMessage::KEY_SUCCESS)); + $this->assertEmpty($flashBag->get(FlashMessage::KEY_ERROR)); } /** @@ -125,7 +126,9 @@ private function fillVats(Form $form) 'product_form[pricesGroup][productCalculatedPricesGroup][vatsIndexedByDomainId][%s]', $domainId ); - $form[$inputName] = $vat->getId(); + $form->setValues([ + $inputName => $vat->getId(), + ]); } } } diff --git a/tests/App/Test/Codeception/AcceptanceTester.php b/tests/App/Test/Codeception/AcceptanceTester.php index b7fc62ed53..52331c1e56 100644 --- a/tests/App/Test/Codeception/AcceptanceTester.php +++ b/tests/App/Test/Codeception/AcceptanceTester.php @@ -50,4 +50,8 @@ public function waitForAjax($timeout = self::DEFAULT_AJAX_TIMEOUT_SEC) { $this->waitForJS('return $.active == 0;', $timeout); } + + public function pauseExecution() + { + } } diff --git a/tests/App/Test/Codeception/Helper/LocalizationHelper.php b/tests/App/Test/Codeception/Helper/LocalizationHelper.php index 6077ba99de..d57172259b 100644 --- a/tests/App/Test/Codeception/Helper/LocalizationHelper.php +++ b/tests/App/Test/Codeception/Helper/LocalizationHelper.php @@ -60,7 +60,7 @@ public function _before(TestInterface $test): void * @param string $domain * @param array $parameters */ - public function seeTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []): void + public function seeTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []) { $translatedMessage = t($id, $parameters, $domain, $this->getFrontendLocale()); $this->webDriver->see(strip_tags($translatedMessage)); @@ -71,7 +71,7 @@ public function seeTranslationFrontend(string $id, string $domain = 'messages', * @param string $domain * @param array $parameters */ - public function dontSeeTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []): void + public function dontSeeTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []) { $translatedMessage = t($id, $parameters, $domain, $this->getFrontendLocale()); $this->webDriver->dontSee(strip_tags($translatedMessage)); @@ -82,7 +82,7 @@ public function dontSeeTranslationFrontend(string $id, string $domain = 'message * @param string $domain * @param array $parameters */ - public function seeTranslationAdmin(string $id, string $domain = 'messages', array $parameters = []): void + public function seeTranslationAdmin(string $id, string $domain = 'messages', array $parameters = []) { $translatedMessage = t($id, $parameters, $domain, $this->getAdminLocale()); $this->webDriver->see(strip_tags($translatedMessage)); @@ -94,7 +94,7 @@ public function seeTranslationAdmin(string $id, string $domain = 'messages', arr * @param string $domain * @param array $parameters */ - public function seeTranslationAdminInCss(string $id, string $css, string $domain = 'messages', array $parameters = []): void + public function seeTranslationAdminInCss(string $id, string $css, string $domain = 'messages', array $parameters = []) { $translatedMessage = t($id, $parameters, $domain, $this->getAdminLocale()); $this->webDriver->seeInCss(strip_tags($translatedMessage), $css); @@ -106,7 +106,7 @@ public function seeTranslationAdminInCss(string $id, string $css, string $domain * @param array $parameters * @param \Facebook\WebDriver\WebDriverBy|\Facebook\WebDriver\WebDriverElement|null $contextSelector */ - public function clickByTranslationAdmin(string $id, string $domain = 'messages', array $parameters = [], $contextSelector = null): void + public function clickByTranslationAdmin(string $id, string $domain = 'messages', array $parameters = [], $contextSelector = null) { $translatedMessage = t($id, $parameters, $domain, $this->getAdminLocale()); $this->webDriver->clickByText(strip_tags($translatedMessage), $contextSelector); @@ -118,7 +118,7 @@ public function clickByTranslationAdmin(string $id, string $domain = 'messages', * @param array $parameters * @param \Facebook\WebDriver\WebDriverBy|\Facebook\WebDriver\WebDriverElement|null $contextSelector */ - public function clickByTranslationFrontend(string $id, string $domain = 'messages', array $parameters = [], $contextSelector = null): void + public function clickByTranslationFrontend(string $id, string $domain = 'messages', array $parameters = [], $contextSelector = null) { $translatedMessage = t($id, $parameters, $domain, $this->getFrontendLocale()); $this->webDriver->clickByText(strip_tags($translatedMessage), $contextSelector); @@ -129,7 +129,7 @@ public function clickByTranslationFrontend(string $id, string $domain = 'message * @param string $domain * @param array $parameters */ - public function checkOptionByLabelTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []): void + public function checkOptionByLabelTranslationFrontend(string $id, string $domain = 'messages', array $parameters = []) { $translatedMessage = t($id, $parameters, $domain, $this->getFrontendLocale()); $this->webDriver->checkOptionByLabel($translatedMessage); diff --git a/tests/App/Test/Codeception/Module/StrictWebDriver.php b/tests/App/Test/Codeception/Module/StrictWebDriver.php index a0e9f1f2e2..f0f36b0354 100644 --- a/tests/App/Test/Codeception/Module/StrictWebDriver.php +++ b/tests/App/Test/Codeception/Module/StrictWebDriver.php @@ -130,7 +130,7 @@ public function clickByCss($css) */ public function clickByElement(WebDriverElement $element) { - $element->click(); + return $element->click(); } /** diff --git a/tests/App/Test/Codeception/_bootstrap.php b/tests/App/Test/Codeception/_bootstrap.php deleted file mode 100644 index 88e6674a1f..0000000000 --- a/tests/App/Test/Codeception/_bootstrap.php +++ /dev/null @@ -1,5 +0,0 @@ -domain->switchDomainById(Domain::FIRST_DOMAIN_ID); } - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->setUpDomain(); - - $this->domainRouterFactory = $this->getContainer()->get(DomainRouterFactory::class); - $this->priceConverter = $this->getContainer()->get(PriceConverter::class); } /** @@ -57,13 +57,15 @@ protected function setUp() * @param string $username * @param string $password * @param array $kernelOptions + * @param array $clientOptions * @return \Symfony\Bundle\FrameworkBundle\Client */ - protected function getClient( + protected function findClient( $createNew = false, $username = null, $password = null, - $kernelOptions = [] + $kernelOptions = [], + $clientOptions = [] ) { $defaultKernelOptions = [ 'environment' => EnvironmentType::TEST, @@ -73,10 +75,10 @@ protected function getClient( $kernelOptions = array_replace($defaultKernelOptions, $kernelOptions); if ($createNew) { - $this->client = $this->createClient($kernelOptions); + $this->client = $this->createClient($kernelOptions, $clientOptions); $this->setUpDomain(); } elseif (!isset($this->client)) { - $this->client = $this->createClient($kernelOptions); + $this->client = $this->createClient($kernelOptions, $clientOptions); } if ($username !== null) { @@ -94,7 +96,7 @@ protected function getClient( */ protected function getContainer() { - return $this->getClient()->getContainer(); + return $this->findClient()->getContainer(); } /** @@ -103,11 +105,7 @@ protected function getContainer() */ protected function getReference($referenceName) { - /** @var \Shopsys\FrameworkBundle\Component\DataFixture\PersistentReferenceFacade $persistentReferenceFacade */ - $persistentReferenceFacade = $this->getContainer() - ->get(PersistentReferenceFacade::class); - - return $persistentReferenceFacade->getReference($referenceName); + return $this->persistentReferenceFacade->getReference($referenceName); } /** @@ -125,11 +123,7 @@ public function createContainer(): ContainerInterface */ protected function getReferenceForDomain(string $referenceName, int $domainId) { - /** @var \Shopsys\FrameworkBundle\Component\DataFixture\PersistentReferenceFacade $persistentReferenceFacade */ - $persistentReferenceFacade = $this->getContainer() - ->get(PersistentReferenceFacade::class); - - return $persistentReferenceFacade->getReferenceForDomain($referenceName, $domainId); + return $this->persistentReferenceFacade->getReferenceForDomain($referenceName, $domainId); } protected function skipTestIfFirstDomainIsNotInEnglish() @@ -155,7 +149,8 @@ protected function getFirstDomainLocale(): string */ protected function getLocalizedPathOnFirstDomainByRouteName(string $routeName, array $parameters = []): string { - $router = $this->domainRouterFactory->getRouter(Domain::FIRST_DOMAIN_ID); + $domainRouterFactory = $this->getContainer()->get(DomainRouterFactory::class); + $router = $domainRouterFactory->getRouter(Domain::FIRST_DOMAIN_ID); return $router->generate($routeName, $parameters, UrlGeneratorInterface::ABSOLUTE_URL); } diff --git a/tests/App/Test/TransactionFunctionalTestCase.php b/tests/App/Test/TransactionFunctionalTestCase.php index 95123f327e..2e493d18de 100644 --- a/tests/App/Test/TransactionFunctionalTestCase.php +++ b/tests/App/Test/TransactionFunctionalTestCase.php @@ -4,26 +4,29 @@ namespace Tests\App\Test; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; + abstract class TransactionFunctionalTestCase extends FunctionalTestCase { + use SymfonyTestContainer; + /** - * @return \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator + * @var \Shopsys\FrameworkBundle\Component\EntityExtension\EntityManagerDecorator + * @inject */ - protected function getEntityManager() - { - return $this->getContainer()->get('doctrine.orm.entity_manager'); - } + protected $em; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->getEntityManager()->beginTransaction(); + $this->em->beginTransaction(); + $this->em->getConnection()->setAutoCommit(false); } - protected function tearDown() + protected function tearDown(): void { - $this->getEntityManager()->rollback(); + $this->em->rollback(); parent::tearDown(); } diff --git a/tests/App/Unit/Form/Front/Order/PersonalInfoFormTypeTest.php b/tests/App/Unit/Form/Front/Order/PersonalInfoFormTypeTest.php index 36e9913c1c..69a5983b47 100644 --- a/tests/App/Unit/Form/Front/Order/PersonalInfoFormTypeTest.php +++ b/tests/App/Unit/Form/Front/Order/PersonalInfoFormTypeTest.php @@ -111,7 +111,7 @@ protected function getExtensions(): array ]; } - protected function setUp() + protected function setUp(): void { $countryMock = $this->createMock(Country::class); $countryMock->method('getId')->willReturn(1); diff --git a/tests/FrontendApiBundle/Test/GraphQlTestCase.php b/tests/FrontendApiBundle/Test/GraphQlTestCase.php index 7cee96fb40..cf3fbb1f9b 100644 --- a/tests/FrontendApiBundle/Test/GraphQlTestCase.php +++ b/tests/FrontendApiBundle/Test/GraphQlTestCase.php @@ -23,7 +23,7 @@ abstract class GraphQlTestCase extends FunctionalTestCase protected function setUp(): void { - $this->client = $this->getClient(true); + $this->client = $this->findClient(true); if (!$this->enabledOnCurrentDomainChecker->isEnabledOnCurrentDomain()) { $this->markTestSkipped('Frontend API disabled on domain'); @@ -72,9 +72,9 @@ protected function getResponseContentForQuery(string $query, array $variables = /** * @param string $query * @param array $variables - * @return \Symfony\Component\HttpFoundation\Response|null + * @return \Symfony\Component\HttpFoundation\Response */ - private function getResponseForQuery(string $query, array $variables): ?Response + private function getResponseForQuery(string $query, array $variables): Response { $path = $this->getLocalizedPathOnFirstDomainByRouteName('overblog_graphql_endpoint'); diff --git a/tests/ReadModelBundle/Functional/Product/Listed/ListedProductViewFacadeTest.php b/tests/ReadModelBundle/Functional/Product/Listed/ListedProductViewFacadeTest.php index d175ab7935..ce9f26e76f 100644 --- a/tests/ReadModelBundle/Functional/Product/Listed/ListedProductViewFacadeTest.php +++ b/tests/ReadModelBundle/Functional/Product/Listed/ListedProductViewFacadeTest.php @@ -8,9 +8,12 @@ use Shopsys\FrameworkBundle\Model\Product\Listing\ProductListOrderingConfig; use Shopsys\ReadModelBundle\Product\Listed\ListedProductView; use Tests\App\Test\FunctionalTestCase; +use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyTestContainer; class ListedProductViewFacadeTest extends FunctionalTestCase { + use SymfonyTestContainer; + /** * @var \Shopsys\ReadModelBundle\Product\Listed\ListedProductViewFacadeInterface * @inject diff --git a/tests/ReadModelBundle/Functional/Twig/ImageExtensionTest.php b/tests/ReadModelBundle/Functional/Twig/ImageExtensionTest.php index ac2510c0e3..409c128aa2 100644 --- a/tests/ReadModelBundle/Functional/Twig/ImageExtensionTest.php +++ b/tests/ReadModelBundle/Functional/Twig/ImageExtensionTest.php @@ -139,7 +139,7 @@ private function createImageExtension( ?ImageFacade $imageFacade = null, bool $enableLazyLoad = false ): ImageExtension { - $templating = $this->getContainer()->get('templating'); + $templating = $this->getContainer()->get('twig'); $imageFacade = $imageFacade ?: $this->imageFacade; return new ImageExtension($frontDesignImageUrlPrefix, $this->domain, $this->imageLocator, $imageFacade, $templating, $enableLazyLoad); diff --git a/yaml-standards.yaml b/yaml-standards.yaml new file mode 100644 index 0000000000..1e3a6ac7f1 --- /dev/null +++ b/yaml-standards.yaml @@ -0,0 +1,11 @@ +- pathsToCheck: + - . + excludedPaths: + - ./vendor + - ./node_modules + - ./config/domains_urls.yml + - ./config/oauth2/parameters_oauth.yml.dist + checkers: + - pathToChecker: YamlStandards\Model\YamlIndent\YamlIndentChecker + parameters: + { indents: 4, indentsCommentsWithoutParent: default }