Skip to content

Commit 29018b0

Browse files
authored
[UPMERGE] 2.0 -> 2.1 (#22)
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 cac47d7 + 6325397 commit 29018b0

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ This package solves that problem by:
4545

4646
```dotenv
4747
DATABASE_URL=mysql://root@127.0.0.1/test_application_%kernel.environment%
48-
CONFIGS_TO_IMPORT="@AcmePlugin/tests/TestApplication/config/config.yaml"
49-
ROUTES_TO_IMPORT="@AcmePlugin/config/routes.yaml"
50-
TEST_APP_BUNDLES_PATH="tests/TestApplication/config/bundles.php"
51-
# Optional: fall back to a semicolon-separated list of bundles
52-
BUNDLES_TO_ENABLE="Acme\Plugin\AcmePlugin"
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"
5356
```
5457

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

bin/console

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,26 @@ if ($_SERVER['APP_DEBUG']) {
3939
}
4040
}
4141

42-
if (isset($_ENV['CONFIGS_TO_IMPORT'])) {
43-
$_SERVER['CONFIGS_TO_IMPORT'] = $_ENV['CONFIGS_TO_IMPORT'];
42+
if (isset($_ENV['SYLIUS_TEST_APP_CONFIGS_TO_IMPORT']) || isset($_ENV['CONFIGS_TO_IMPORT'])) {
43+
$_SERVER['SYLIUS_TEST_APP_CONFIGS_TO_IMPORT'] = $_ENV['SYLIUS_TEST_APP_CONFIGS_TO_IMPORT'] ?? $_ENV['CONFIGS_TO_IMPORT'];
4444
}
4545

46-
if (isset($_ENV['ROUTES_TO_IMPORT'])) {
47-
$_SERVER['ROUTES_TO_IMPORT'] = $_ENV['ROUTES_TO_IMPORT'];
46+
if (isset($_ENV['SYLIUS_TEST_APP_ROUTES_TO_IMPORT']) || isset($_ENV['ROUTES_TO_IMPORT'])) {
47+
$_SERVER['SYLIUS_TEST_APP_ROUTES_TO_IMPORT'] = $_ENV['SYLIUS_TEST_APP_ROUTES_TO_IMPORT'] ?? $_ENV['ROUTES_TO_IMPORT'];
4848
}
4949

50-
if (isset($_ENV["BUNDLES_TO_ENABLE"])) {
51-
$_SERVER["BUNDLES_TO_ENABLE"] = $_ENV["BUNDLES_TO_ENABLE"];
50+
if (isset($_ENV['SYLIUS_TEST_APP_BUNDLES_TO_ENABLE']) || isset($_ENV['BUNDLES_TO_ENABLE'])) {
51+
$_SERVER['SYLIUS_TEST_APP_BUNDLES_TO_ENABLE'] = $_ENV['SYLIUS_TEST_APP_BUNDLES_TO_ENABLE'] ?? $_ENV['BUNDLES_TO_ENABLE'];
5252
}
5353

54-
if (isset($_ENV["TEST_APP_BUNDLES_PATH"])) {
55-
$_SERVER["TEST_APP_BUNDLES_PATH"] = $_ENV["TEST_APP_BUNDLES_PATH"];
54+
if (isset($_ENV['SYLIUS_TEST_APP_BUNDLES_PATH']) || isset($_ENV['TEST_APP_BUNDLES_PATH'])) {
55+
$_SERVER['SYLIUS_TEST_APP_BUNDLES_PATH'] = $_ENV['SYLIUS_TEST_APP_BUNDLES_PATH'] ?? $_ENV['TEST_APP_BUNDLES_PATH'];
56+
}
57+
58+
if (isset($_ENV["SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH"])) {
59+
$_SERVER["SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH"] = $_ENV["SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH"];
5660
}
5761

5862
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
5963
$application = new Application($kernel);
6064
$application->run($input);
61-

config/bootstrap.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
88

9-
$pluginEnvPath = dirname(__DIR__, 4) . '/tests/TestApplication/.env';
10-
if (file_exists($pluginEnvPath)) {
9+
$pluginDir = dirname(__DIR__, 4);
10+
if (file_exists($pluginEnvPath = $pluginDir . '/tests/TestApplication/.env')) {
1111
(new Dotenv())->bootEnv($pluginEnvPath);
12+
13+
$_SERVER['APP_CACHE_DIR'] = $_SERVER['APP_CACHE_DIR'] ?? $pluginDir . '/var/cache';
14+
$_SERVER['APP_LOG_DIR'] = $_SERVER['APP_LOG_DIR'] ?? $pluginDir . '/var/log';
1215
}
1316

1417
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';

src/Kernel.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
7676

7777
$container->setAlias($kernelClass, 'kernel')->setPublic(true);
7878

79-
if (isset($_SERVER['CONFIGS_TO_IMPORT'])) {
80-
foreach (explode(';', $_SERVER['CONFIGS_TO_IMPORT']) as $filePath) {
79+
$configsToImport = $_SERVER['SYLIUS_TEST_APP_CONFIGS_TO_IMPORT'] ?? null;
80+
if (null !== $configsToImport) {
81+
foreach (explode(';', $configsToImport) as $filePath) {
8182
$kernelLoader->import($filePath);
8283
}
8384
}
@@ -88,7 +89,8 @@ public function registerBundles(): iterable
8889
{
8990
$env = $this->getEnvironment();
9091

91-
if (!is_file($bundlesPath = $this->getBundlesPath())) {
92+
$bundlesPath = $this->resolveBundlesPath();
93+
if (!is_file($bundlesPath)) {
9294
yield new FrameworkBundle();
9395
return;
9496
}
@@ -119,8 +121,9 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
119121
$routes = new RoutingConfigurator($collection, $kernelLoader, $file, $file, $this->getEnvironment());
120122
$configureRoutes->getClosure($this)($routes);
121123

122-
if (isset($_SERVER['ROUTES_TO_IMPORT'])) {
123-
foreach (explode(';', $_SERVER['ROUTES_TO_IMPORT']) as $filePath) {
124+
$routesToImport = $_SERVER['SYLIUS_TEST_APP_ROUTES_TO_IMPORT'] ?? null;
125+
if (null !== $routesToImport) {
126+
foreach (explode(';', $routesToImport) as $filePath) {
124127
$routes->import($filePath);
125128
}
126129
}
@@ -145,12 +148,12 @@ private function loadMainBundles(string $path): array
145148

146149
private function loadAdditionalBundlesFromEnv(array &$contents): bool
147150
{
148-
if (!isset($_SERVER['TEST_APP_BUNDLES_PATH'])) {
151+
$bundlesPathEnv = $_SERVER['SYLIUS_TEST_APP_BUNDLES_PATH'] ?? null;
152+
if (null === $bundlesPathEnv) {
149153
return false;
150154
}
151155

152-
$relativePath = $_SERVER['TEST_APP_BUNDLES_PATH'];
153-
$absolutePath = \dirname($this->getProjectDir(), 3) . '/' . ltrim($relativePath, '/');
156+
$absolutePath = \dirname($this->getProjectDir(), 3) . '/' . ltrim($bundlesPathEnv, '/');
154157

155158
if (!is_file($absolutePath)) {
156159
return false;
@@ -172,14 +175,29 @@ private function loadAdditionalBundlesFromEnv(array &$contents): bool
172175

173176
private function loadBundlesToEnable(array &$contents): void
174177
{
175-
if (!isset($_SERVER['BUNDLES_TO_ENABLE'])) {
178+
$bundlesToEnable = $_SERVER['SYLIUS_TEST_APP_BUNDLES_TO_ENABLE'] ?? null;
179+
if (null === $bundlesToEnable) {
176180
return;
177181
}
178182

179-
foreach (explode(';', $_SERVER['BUNDLES_TO_ENABLE']) as $bundleClass) {
183+
foreach (explode(';', $bundlesToEnable) as $bundleClass) {
180184
if (\class_exists($bundleClass)) {
181185
$contents[$bundleClass] = ['all' => true];
182186
}
183187
}
184188
}
189+
190+
private function resolveBundlesPath(): string
191+
{
192+
if (isset($_SERVER['SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH'])) {
193+
$relativePath = $_SERVER['SYLIUS_TEST_APP_BUNDLES_REPLACE_PATH'];
194+
$absolutePath = \dirname($this->getProjectDir(), 3) . '/' . ltrim($relativePath, '/');
195+
196+
if (is_file($absolutePath)) {
197+
return $absolutePath;
198+
}
199+
}
200+
201+
return $this->getBundlesPath();
202+
}
185203
}

0 commit comments

Comments
 (0)