Skip to main content

DDEV & Sylius Test Application

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

In May, Sylius released their new Test Application project, which defines a shared testing environment designed to simplify plugin development and testing.

Since we are big DDEV fans, I wanted to see if it is possible to combine DDEV and the Test Application setup to make plugin development even simpler.

First, I installed the Test Application plugin matching the Sylius version that our plugin, following the official docs:

composer require --dev sylius/test-application:^2.1.0@alpha

Create the tests/TestApplication/config directory:

mkdir -p tests/TestApplication/config

Add an .env file in the tests/TestApplication/config directory:

DATABASE_URL="mysql://db:db@db:3306/db?sslmode=disable&charset=utf8mb4&serverVersion=10.11.0-mariadb"
CONFIGS_TO_IMPORT="@BitExpertSyliusForceCustomerLoginPlugin/Resources/config/config.yml"
ROUTES_TO_IMPORT="@BitExpertSyliusForceCustomerLoginPlugin/Resources/config/test_app_routing.yml"
BUNDLES_TO_ENABLE="BitExpert\SyliusForceCustomerLoginPlugin\BitExpertSyliusForceCustomerLoginPlugin"

Once the Test Application was ready, it was time to configure DDEV for the project by running the following command:

ddev config --project-type=symfony

By default, DDEV points the webroot to the public directory, which we don't have since we are developing a Sylius plugin. Let's change the docroot to the public directory in the Test Application:

ddev config --docroot vendor/sylius/test-application/public

To start the DDEV instance and to set up Sylius, you can run the following commands:

# Start DDEV and let it build all containers
ddev start
# Install all Composer Dependencies
ddev composer install
# Run default Sylius migrations
ddev console doctrine:migration:migrate -n
# Run the migrations for the Force Login module
ddev console doctrine:migration:diff --namespace=App\\Migrations
ddev console doctrine:migration:migrate -n
# Install default fixtures
ddev console sylius:fixtures:load -n
# Build and install frontend dependencies
ddev yarn install
ddev yarn run build:prod
ddev console assets:install

Once all commands have been completed, run ddev launch to open your default browser to access your test setup.

Bonus point:

To make it easy for your dev team, add the commands above in a bash script bootstrap and store the script in .ddev/commands/host. Once done, you can execute ddev bootstrap and all the commands in the bash script are executed for you automatically.