Skip to content

Commit 4922437

Browse files
authored
[UPMERGE] 2.0 -> 2.1 (#31)
This PR has been generated automatically. For more details see [upmerge_pr.yaml](/Sylius/TestApplication/blob/2.0/.github/workflows/upmerge_pr.yaml). **Remember!** The upmerge should always be merged with using `Merge pull request` button. In case of conflicts, please resolve them manually with usign the following commands: ``` git fetch upstream gh pr checkout <this-pr-number> git merge upstream/2.1 -m "Resolve conflicts between 2.0 and 2.1" ``` If you use other name for the upstream remote, please replace `upstream` with the name of your remote pointing to the `Sylius/TestApplication` repository. Once the conflicts are resolved, please run `git merge --continue` and push the changes to this PR.
2 parents 0064d19 + d7675aa commit 4922437

File tree

8 files changed

+55
-118
lines changed

8 files changed

+55
-118
lines changed

README.md

Lines changed: 9 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@
88
</a>
99
</p>
1010

11-
TestApplication
12-
===============
11+
Test Application
12+
================
1313

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-
## Documentation
21-
22-
For more information about the **Test Application**, please refer to the [Sylius documentation](https://docs.sylius.com/sylius-plugins/plugins-development-guide/testapplication).
14+
The Test Application is a shared testing environment designed to simplify Sylius plugin development. Instead of setting up
15+
a full application in every plugin, you now use a common, pre-configured application maintained by the Sylius team.
2316

2417
## Purpose
2518

26-
Previously, each plugin had to maintain its own copy of a test application, leading to duplicated configuration,
19+
Previously, each plugin had to maintain its own copy of a test application, leading to duplicated configuration,
2720
maintenance overhead, and version incompatibilities.
2821

2922
This package solves that problem by:
@@ -33,104 +26,14 @@ This package solves that problem by:
3326
- Simplifying the setup and execution of tests within plugins
3427
- Creating versioned variants aligned with specific Sylius versions (e.g. `1.14`, `2.0`, etc.)
3528

36-
## Installation and configuration in a Plugin
37-
38-
1. Require the TestApplication as a development dependency:
39-
40-
```bash
41-
composer require sylius/test-application:2.0.x-dev --dev
42-
```
43-
44-
1. Set environment variables in `tests/TestApplication/.env`:
45-
46-
```dotenv
47-
DATABASE_URL=mysql://root@127.0.0.1/test_application_%kernel.environment%
48-
49-
SYLIUS_TEST_APP_CONFIGS_TO_IMPORT="@AcmePlugin/tests/TestApplication/config/config.yaml"
50-
SYLIUS_TEST_APP_ROUTES_TO_IMPORT="@AcmePlugin/config/routes.yaml"
51-
SYLIUS_TEST_APP_BUNDLES_PATH="tests/TestApplication/config/bundles.php"
52-
# Optionally, replace the default bundles entirely
53-
SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH="tests/TestApplication/config/bundles.php"
54-
# Optionally, use a semicolon-separated list to add needed bundles
55-
SYLIUS_TEST_APP_BUNDLES_TO_ENABLE="Acme\Plugin\AcmePlugin"
56-
```
57-
58-
> 💡 The values provided above are examples and should be adjusted for your plugin.
59-
60-
1. Optionally, return conditionally enabled bundles from `tests/TestApplication/bundles.php`:
61-
62-
```php
63-
<?php
64-
65-
return [
66-
Acme\\Plugin\\AcmePlugin::class => ['all' => true],
67-
];
68-
```
69-
70-
1. If needed, place plugin-specific configuration files in the `tests/TestApplication/config` directory
71-
(e.g. `services.yaml`, `routes.yaml`) and load them by env variables.
72-
73-
1. If your plugin requires additional JavaScript dependencies, add them to `tests/TestApplication/package.json`:
74-
75-
```json
76-
{
77-
"dependencies": {
78-
"trix": "^2.0.0"
79-
}
80-
}
81-
```
82-
83-
This file will be merged with the main TestApplication `package.json`.
84-
85-
1. If your plugin requires entity extensions, add them in `tests/TestApplication/src/Entity` and ensure:
86-
87-
- Doctrine mappings are configured:
88-
89-
```
90-
doctrine:
91-
orm:
92-
entity_managers:
93-
default:
94-
mappings:
95-
TestApplication:
96-
is_bundle: false
97-
type: attribute
98-
dir: '%kernel.project_dir%/../../../tests/TestApplication/src/Entity'
99-
prefix: Tests\Acme\Plugin\TestApplication
100-
```
101-
102-
- The namespace is registered properly in the autoloader, in `composer.json` file
103-
104-
```json
105-
{
106-
"autoload-dev": {
107-
"psr-4": {
108-
"Tests\\Acme\\Plugin\\TestApplication\\": "tests/TestApplication/src/"
109-
}
110-
}
111-
}
112-
113-
1. Build the TestApplication in a Plugin:
114-
115-
```bash
116-
vendor/bin/console doctrine:database:create
117-
vendor/bin/console doctrine:migration:migrate -n
118-
vendor/bin/console sylius:fixtures:load -n
119-
120-
(cd vendor/sylius/test-application && yarn install)
121-
(cd vendor/sylius/test-application && yarn build)
122-
vendor/bin/console assets:install
123-
```
124-
125-
1. Run your server locally:
29+
## Documentation
12630

127-
```bash
128-
symfony serve --dir=vendor/sylius/test-application/public
129-
```
31+
For more information about the **Test Application**, and on installation and configuration instructions,
32+
please refer to the [Sylius documentation](https://docs.sylius.com/sylius-plugins/plugins-development-guide/test-application).
13033

13134
## Example usage
13235

133-
See an example implementation in [the pull request](https://github.com/Sylius/CmsPlugin/pull/53) to Sylius/CmsPlugin.
36+
See an example implementation in [the pull request](https://github.com/Sylius/InvoicingPlugin/pull/373) to Sylius/InvoicingPlugin.
13437

13538
## Community
13639

config/bundles.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
return [
3+
$bundles = [
44
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
55
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
66
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
@@ -41,7 +41,6 @@
4141
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
4242
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
4343
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
44-
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
4544
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
4645
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
4746
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
@@ -61,3 +60,9 @@
6160
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true],
6261
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true],
6362
];
63+
64+
if (class_exists('FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle')) {
65+
$bundles[FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class] = ['test' => true, 'test_cached' => true];
66+
}
67+
68+
return $bundles;

config/services_test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
7+
return function (ContainerConfigurator $container) {
8+
if (class_exists('FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle')) {
9+
$container->import('../../sylius/src/Sylius/Behat/Resources/config/services.xml');
10+
}
11+
};

config/services_test.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"dependencies": {
1010
"@sylius-ui/admin": "file:../sylius/src/Sylius/Bundle/AdminBundle",
1111
"@sylius-ui/shop": "file:../sylius/src/Sylius/Bundle/ShopBundle",
12-
"@symfony/ux-autocomplete": "file:../../../vendor/symfony/ux-autocomplete/assets",
13-
"@symfony/ux-live-component": "file:../../../vendor/symfony/ux-live-component/assets"
12+
"@symfony/ux-autocomplete": "file:../../symfony/ux-autocomplete/assets",
13+
"@symfony/ux-live-component": "file:../../symfony/ux-live-component/assets"
1414
},
1515
"devDependencies": {
1616
"@hotwired/stimulus": "^3.0.0",

scripts/merge-plugin-dependencies.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ const pluginPackagePath = path.join(pluginRoot, 'tests', 'TestApplication', 'pac
1010
const pluginPackageExists = fs.existsSync(pluginPackagePath);
1111
const pluginPackage = pluginPackageExists
1212
? JSON.parse(fs.readFileSync(pluginPackagePath, 'utf-8'))
13-
: { dependencies: {}, devDependencies: {} }
14-
;
13+
: {
14+
dependencies: {},
15+
devDependencies: {},
16+
removeDependencies: [],
17+
removeDevDependencies: [],
18+
};
1519

1620
const basePackage = JSON.parse(fs.readFileSync(packageDistPath, 'utf-8'));
1721

@@ -24,10 +28,26 @@ function mergeDependencies(target = {}, source = {}) {
2428
return result;
2529
}
2630

31+
function removeDependencies(target = {}, packages = []) {
32+
const result = { ...target };
33+
34+
for (const pkg of packages) {
35+
delete result[pkg];
36+
}
37+
38+
return result;
39+
}
40+
2741
const finalPackage = {
2842
...basePackage,
29-
dependencies: mergeDependencies(basePackage.dependencies, pluginPackage.dependencies),
30-
devDependencies: mergeDependencies(basePackage.devDependencies, pluginPackage.devDependencies),
43+
dependencies: removeDependencies(
44+
mergeDependencies(basePackage.dependencies, pluginPackage.dependencies),
45+
pluginPackage.removeDependencies ?? []
46+
),
47+
devDependencies: removeDependencies(
48+
mergeDependencies(basePackage.devDependencies, pluginPackage.devDependencies),
49+
pluginPackage.removeDevDependencies ?? []
50+
),
3151
};
3252

3353
fs.writeFileSync(packagePath, JSON.stringify(finalPackage, null, 4));

templates/components/.gitkeep

Whitespace-only changes.

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Encore
2222
.setPublicPath('/build/app/shop')
2323
.addEntry('app-shop-entry', path.resolve(__dirname, './assets/shop/entrypoint.js'))
2424
.addAliases({
25-
'@vendor': path.resolve(__dirname, '../../vendor'),
25+
'@vendor': path.resolve(__dirname, '../..'),
2626
})
2727
.disableSingleRuntimeChunk()
2828
.cleanupOutputBeforeBuild()
@@ -53,7 +53,7 @@ Encore
5353
.setPublicPath('/build/app/admin')
5454
.addEntry('app-admin-entry', path.resolve(__dirname, './assets/admin/entrypoint.js'))
5555
.addAliases({
56-
'@vendor': path.resolve(__dirname, '../../vendor'),
56+
'@vendor': path.resolve(__dirname, '../..'),
5757
})
5858
.disableSingleRuntimeChunk()
5959
.cleanupOutputBeforeBuild()

0 commit comments

Comments
 (0)