Skip to content

Sylius/TestApplication

Repository files navigation

Sylius Logo.

TestApplication

Developer tool that provides a ready-to-use Sylius-based application for testing and running Sylius plugins.

⚠️ While TestApplication is still evolving, it is already being used internally and in official plugins. We encourage you to adopt it in your plugins, provide feedback, and contribute to improve the developer experience for the entire Sylius ecosystem.

Purpose

Previously, each plugin had to maintain its own copy of a test application, leading to duplicated configuration, maintenance overhead, and version incompatibilities.

This package solves that problem by:

  • Extracting a reusable, standalone test application
  • Providing an official, centrally maintained solution by the Sylius team
  • Simplifying the setup and execution of tests within plugins
  • Creating versioned variants aligned with specific Sylius versions (e.g. 1.14, 2.0, etc.)

Installation and configuration in a Plugin

  1. Require the TestApplication as a development dependency:

    composer require sylius/test-application:2.0.x-dev --dev
  2. Set environment variables in tests/TestApplication/.env:

    DATABASE_URL=mysql://[email protected]/test_application_%kernel.environment%
    CONFIGS_TO_IMPORT="@AcmePlugin/tests/TestApplication/config/config.yaml"
    ROUTES_TO_IMPORT="@AcmePlugin/config/routes.yaml"
    TEST_APP_BUNDLES_PATH="tests/TestApplication/config/bundles.php"
    # Optional: fall back to a semicolon-separated list of bundles
    BUNDLES_TO_ENABLE="Acme\Plugin\AcmePlugin"

    💡 The values provided above are examples and should be adjusted for your plugin.

  3. Optionally, return conditionally enabled bundles from tests/TestApplication/bundles.php:

    <?php
    
    return [
        Acme\\Plugin\\AcmePlugin::class => ['all' => true],
    ];
  4. If needed, place plugin-specific configuration files in the tests/TestApplication/config directory (e.g. services.yaml, routes.yaml) and load them by env variables.

  5. If your plugin requires additional JavaScript dependencies, add them to tests/TestApplication/package.json:

    {
        "dependencies": {
            "trix": "^2.0.0"
        }
    }

    This file will be merged with the main TestApplication package.json.

  6. If your plugin requires entity extensions, add them in tests/TestApplication/src/Entity and ensure:

    • Doctrine mappings are configured:

      doctrine:
          orm:
              entity_managers:
                  default:
                      mappings:
                          TestApplication:
                              is_bundle: false
                              type: attribute
                              dir: '%kernel.project_dir%/../../../tests/TestApplication/src/Entity'
                              prefix: Tests\Acme\Plugin\TestApplication
      
    • The namespace is registered properly in the autoloader, in composer.json file

      {
          "autoload-dev": {
              "psr-4": {
                  "Tests\\Acme\\Plugin\\TestApplication\\": "tests/TestApplication/src/"
              }
          }
      }
      
  7. Build the TestApplication in a Plugin:

    vendor/bin/console doctrine:database:create
    vendor/bin/console doctrine:migration:migrate -n
    vendor/bin/console sylius:fixtures:load -n
    
    (cd vendor/sylius/test-application && yarn install)
    (cd vendor/sylius/test-application && yarn build)
    vendor/bin/console assets:install
  8. Run your server locally:

    symfony serve --dir=vendor/sylius/test-application/public

Example usage

See an example implementation in the pull request to Sylius/CmsPlugin.

Community

For online communication, we invite you to chat with us & other users on Sylius Slack.

License

This package is completely free and released under the MIT License.

About

Version-agnostic Sylius environment for app testing

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •