|
| 1 | +<p align="center"> |
| 2 | + <a href="https://sylius.com" target="_blank"> |
| 3 | + <picture> |
| 4 | + <source media="(prefers-color-scheme: dark)" srcset="https://media.sylius.com/sylius-logo-800-dark.png"> |
| 5 | + <source media="(prefers-color-scheme: light)" srcset="https://media.sylius.com/sylius-logo-800.png"> |
| 6 | + <img alt="Sylius Logo." src="https://media.sylius.com/sylius-logo-800.png"> |
| 7 | + </picture> |
| 8 | + </a> |
| 9 | +</p> |
| 10 | + |
| 11 | +TestApplication |
| 12 | +=============== |
| 13 | + |
| 14 | +Developer tool that provides a ready-to-use Sylius-based application for testing and running Sylius plugins. |
| 15 | + |
| 16 | +> ⚠️ While TestApplication is still evolving, it is already being used internally and in official plugins. |
| 17 | + We encourage you to adopt it in your plugins, provide feedback, and contribute to improve the developer experience |
| 18 | + for the entire Sylius ecosystem. |
| 19 | + |
| 20 | +## Purpose |
| 21 | + |
| 22 | +Previously, each plugin had to maintain its own copy of a test application, leading to duplicated configuration, |
| 23 | +maintenance overhead, and version incompatibilities. |
| 24 | + |
| 25 | +This package solves that problem by: |
| 26 | + |
| 27 | +- Extracting a reusable, standalone test application |
| 28 | +- Providing an official, centrally maintained solution by the Sylius team |
| 29 | +- Simplifying the setup and execution of tests within plugins |
| 30 | +- Creating versioned variants aligned with specific Sylius versions (e.g. `1.14`, `2.0`, etc.) |
| 31 | + |
| 32 | +## Installation and configuration in a Plugin |
| 33 | + |
| 34 | +1. Require the TestApplication as a development dependency: |
| 35 | + |
| 36 | + ```bash |
| 37 | + composer require sylius/test-application:2.0.x-dev --dev |
| 38 | + ``` |
| 39 | + |
| 40 | +1. Set environment variables in `tests/TestApplication/.env`: |
| 41 | + |
| 42 | + ```dotenv |
| 43 | + DATABASE_URL=mysql://root@127.0.0.1/test_application_%kernel.environment% |
| 44 | + BUNDLES_TO_ENABLE="Acme\Plugin\AcmePlugin" |
| 45 | + CONFIGS_TO_IMPORT="@AcmePlugin/tests/TestApplication/config/config.yaml" |
| 46 | + ROUTES_TO_IMPORT="@AcmePlugin/config/routes.yaml" |
| 47 | + ``` |
| 48 | + |
| 49 | + > 💡 The values provided above are examples and should be adjusted for your plugin. |
| 50 | + |
| 51 | + |
| 52 | +1. If needed, place plugin-specific configuration files in the `tests/TestApplication/config` directory |
| 53 | + (e.g. `services.yaml`, `routes.yaml`) and load them by env variables. |
| 54 | + |
| 55 | +1. If your plugin requires additional JavaScript dependencies, add them to `tests/TestApplication/package.json`: |
| 56 | + |
| 57 | + ```json |
| 58 | + { |
| 59 | + "dependencies": { |
| 60 | + "trix": "^2.0.0" |
| 61 | + } |
| 62 | + } |
| 63 | + ``` |
| 64 | + |
| 65 | + This file will be merged with the main TestApplication `package.json`. |
| 66 | + |
| 67 | +1. If your plugin requires entity extensions, add them in `tests/TestApplication/src/Entity` and ensure: |
| 68 | + |
| 69 | + - Doctrine mappings are configured: |
| 70 | + |
| 71 | + ``` |
| 72 | + doctrine: |
| 73 | + orm: |
| 74 | + entity_managers: |
| 75 | + default: |
| 76 | + mappings: |
| 77 | + TestApplication: |
| 78 | + is_bundle: false |
| 79 | + type: attribute |
| 80 | + dir: '%kernel.project_dir%/../../../tests/TestApplication/src/Entity' |
| 81 | + prefix: Tests\Acme\Plugin\TestApplication |
| 82 | + ``` |
| 83 | + |
| 84 | + - The namespace is registered properly in the autoloader, in `composer.json` file |
| 85 | + |
| 86 | + ```json |
| 87 | + { |
| 88 | + "autoload-dev": { |
| 89 | + "psr-4": { |
| 90 | + "Tests\\Acme\\Plugin\\TestApplication\\": "tests/TestApplication/src/" |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +
|
| 95 | +1. Build the TestApplication in a Plugin: |
| 96 | +
|
| 97 | + ```bash |
| 98 | + vendor/bin/console doctrine:database:create |
| 99 | + vendor/bin/console doctrine:migration:migrate -n |
| 100 | + vendor/bin/console sylius:fixtures:load -n |
| 101 | + |
| 102 | + (cd vendor/sylius/test-application && yarn install) |
| 103 | + (cd vendor/sylius/test-application && yarn build) |
| 104 | + vendor/bin/console assets:install |
| 105 | + ``` |
| 106 | + |
| 107 | +1. Run your server locally: |
| 108 | + |
| 109 | + ```bash |
| 110 | + symfony serve --dir=vendor/sylius/test-application/public |
| 111 | + ``` |
| 112 | + |
| 113 | +## Example usage |
| 114 | + |
| 115 | +See an example implementation in [the pull request](https://github.com/Sylius/CmsPlugin/pull/53) to Sylius/CmsPlugin. |
| 116 | + |
| 117 | +## Community |
| 118 | + |
| 119 | +For online communication, we invite you to chat with us & other users on [Sylius Slack](https://sylius-devs.slack.com/). |
| 120 | + |
| 121 | +## License |
| 122 | + |
| 123 | +This package is completely free and released under the MIT License. |
0 commit comments