Skip to content

Commit ac1af41

Browse files
authored
refactor #128 [DX] Usable test application (Zales0123)
This PR was merged into the 1.8-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Let's finally move from the XIX century to the modern era 🚀 I've also added the `lint:container` command to ensure the configuration is runnable 🖖 Commits ------- 10b7f18 Move to modern test application structure af35291 Lint container in workflow to ensure working application bb77be6 Small fixes in workflow and Kernel
2 parents d539d03 + bb77be6 commit ac1af41

File tree

14 files changed

+130
-82
lines changed

14 files changed

+130
-82
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ jobs:
6464
-
6565
name: Run bundle tests
6666
run: composer test
67+
68+
-
69+
name: Run lint container
70+
run: (cd src/Bundle/test && bin/console lint:container)

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"phpunit/phpunit": "^9.4",
4646
"sylius-labs/coding-standard": "^4.0",
4747
"symfony/console": "^5.4",
48+
"symfony/dotenv": "^5.4",
4849
"symfony/swiftmailer-bundle": "^3.1",
4950
"symfony/twig-bundle": "^5.4",
5051
"vimeo/psalm": "^4.22",
@@ -64,11 +65,9 @@
6465
"autoload-dev": {
6566
"psr-4": {
6667
"Sylius\\Bundle\\MailerBundle\\spec\\": "src/Bundle/spec/",
67-
"Sylius\\Component\\Mailer\\spec\\": "src/Component/spec/"
68-
},
69-
"classmap": [
70-
"src/Bundle/test/app/AppKernel.php"
71-
]
68+
"Sylius\\Component\\Mailer\\spec\\": "src/Component/spec/",
69+
"App\\": "src/Bundle/test/src/"
70+
}
7271
},
7372
"scripts": {
7473
"analyse": [

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
colors="true"
66
>
77
<php>
8-
<server name="KERNEL_CLASS" value="AppKernel" />
8+
<server name="KERNEL_CLASS" value="App\Kernel" />
99
</php>
1010

1111
<testsuites>

src/Bundle/test/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_ENV=test

src/Bundle/test/app/AppKernel.php

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

src/Bundle/test/app/config/config.yml

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

src/Bundle/test/app/console

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

src/Bundle/test/bin/console

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
9+
set_time_limit(0);
10+
11+
require dirname(__DIR__).'/../../../vendor/autoload.php';
12+
13+
if (!class_exists(Application::class)) {
14+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
15+
}
16+
17+
$input = new ArgvInput();
18+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
19+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
20+
}
21+
22+
if ($input->hasParameterOption('--no-debug', true)) {
23+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
24+
}
25+
26+
require dirname(__DIR__).'/config/bootstrap.php';
27+
28+
if ($_SERVER['APP_DEBUG']) {
29+
umask(0000);
30+
31+
if (class_exists(Debug::class)) {
32+
Debug::enable();
33+
}
34+
}
35+
36+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
37+
$application = new Application($kernel);
38+
$application->run($input);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
use Symfony\Component\Dotenv\Dotenv;
15+
16+
require dirname(__DIR__) . '/../../../vendor/autoload.php';
17+
18+
// Load cached env vars if the .env.local.php file exists
19+
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
20+
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) {
21+
$_SERVER += $env;
22+
$_ENV += $env;
23+
} elseif (!class_exists(Dotenv::class)) {
24+
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
25+
} else {
26+
// load all the .env files
27+
(new Dotenv(true))->loadEnv(dirname(__DIR__) . '/.env');
28+
}
29+
30+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'test';
31+
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
32+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

src/Bundle/test/config/bundles.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
return [
15+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
16+
Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
17+
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
18+
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
19+
];

0 commit comments

Comments
 (0)