Migrating from tests/Application to Test Application
The traditional approach in Sylius plugins involved bundling a full Symfony application under tests/Application to facilitate testing. With the introduction of the official Sylius Test Application, this practice is now deprecated.
Here’s how to migrate to the new, cleaner setup:
1. Require the Sylius Test Application
⚠️ Warning: The sylius/test-application package is still in an experimental stage. If you're using it with an alpha or beta release (e.g. 2.0.0-ALPHA.1), you might need to adjust your minimum-stability and prefer-stable settings in composer.json:
composer require sylius/test-application:~2.0.0 --dev
Environment Configuration
Create tests/TestApplication/.env
with required variables:
DATABASE_URL=mysql://[email protected]/test_application_%kernel.environment%
CONFIGS_TO_IMPORT="@YourPlugin/tests/TestApplication/config/config.yaml"
ROUTES_TO_IMPORT="@YourPlugin/config/routes.yaml"
TEST_APP_BUNDLES_PATH="tests/TestApplication/config/bundles.php"
# Alternatively:
BUNDLES_TO_ENABLE="Your\\Bundle\\Namespace;"
Register Bundles
If needed, create tests/TestApplication/config/bundles.php
:
<?php
return [
Some\Dependency\Bundle::class => ['all' => true],
Your\Bundle\Namespace::class => ['all' => true],
];
Plugin Configuration
Place any plugin-specific configuration in tests/TestApplication/config/
, such as:
imports:
- { resource: "@YourPlugin/config/config.yaml" }
- { resource: "services_test.php" }
twig:
paths:
'%kernel.project_dir%/../../../tests/TestApplication/templates': ~
parameters:
your_plugin_param: '%kernel.project_dir%/../../../config/plugin_param/'
⚠️ Warning: Make sure the directory you reference above actually exists.
Example tests/TestApplication/config/services_test.php
for test-only service loading:
return function (ContainerConfigurator $container) {
$env = $_ENV['APP_ENV'] ?? 'dev';
if (str_starts_with($env, 'test')) {
$container->import('../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml');
$container->import('@YourPlugin/tests/Behat/Resources/services.xml');
}
};
JavaScript Assets
Add minimal YourPlugin/assets/shop/controllers.json
and YourPlugin/assets/admin/controllers.json
:
{
"controllers": [],
"entrypoints": []
}
Add extra JS dependencies in tests/TestApplication/package.json
:
{
"dependencies": {
"trix": "^2.0.0",
"swiper": "^11.2.6"
}
}
They will be merged into the main test application when running yarn install.
Entity Extensions
If your plugin provides completely custom entities, they should already be loaded through your plugin's own configuration and don't require additional setup here.
However, if you are overriding existing entities from Sylius or its dependencies—for instance, to add traits or modify relationships—you should place the extended entity classes in tests/TestApplication/src/Entity
and register them with Doctrine manually. This configuration can be placed directly in tests/TestApplication/config/config.yaml
or extracted into a dedicated tests/TestApplication/config/doctrine.yaml
file and imported from .env
:
doctrine:
orm:
entity_managers:
default:
mappings:
TestApplication:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/../../../tests/TestApplication/src/Entity'
prefix: Tests\Your\Plugin\TestApplication
Update
composer.json
:
"autoload-dev": {
"psr-4": {
"Tests\\Your\\Plugin\\TestApplication\\": "tests/TestApplication/src/"
}
}
Then run
composer dump-autoload
Ignore Local Overrides
Add to .gitignore
:
/tests/TestApplication/.env.local
/tests/TestApplication/.env.*.local
Last updated
Was this helpful?