Skip to content

Commit 8916de1

Browse files
authored
bug #156 Update to Sylius 1.4-BETA (Zales0123, pamil)
This PR was merged into the 1.4-dev branch. Discussion ---------- Commits ------- 6d3d593 Use SymfonyExtension ^2.0 c89acd7 Switch to Symfony's dotenv file handling 097e20c Fix the build
2 parents c716705 + 097e20c commit 8916de1

17 files changed

+116
-127
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
!/etc/build/.gitignore
77

88
/tests/Application/yarn.lock
9+
10+
/behat.yml
11+
/phpspec.yml

.travis.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cache:
1515

1616
env:
1717
global:
18+
- APP_ENV=test
1819
- SYLIUS_CACHE_DIR=$HOME/.sylius-cache
1920
- SYLIUS_BUILD_DIR=etc/build
2021
matrix:
@@ -27,24 +28,20 @@ before_install:
2728
- mkdir -p "${SYLIUS_CACHE_DIR}"
2829
- mkdir -p tests/Application/web/media/image
2930

30-
- cp tests/Application/.env.test.dist tests/Application/.env.test
31-
- set -a && source tests/Application/.env.test && set +a
32-
3331
install:
3432
- composer require "symfony/browser-kit:${SYMFONY_VERSION}" --no-interaction --no-update
3533
- composer require "symfony/debug-bundle:${SYMFONY_VERSION}" --no-interaction --no-update
36-
- composer require "symfony/dotenv:${SYMFONY_VERSION}" --no-interaction --no-update
3734
- composer require "symfony/intl:${SYMFONY_VERSION}" --no-interaction --no-update
3835
- composer require "symfony/web-profiler-bundle:${SYMFONY_VERSION}" --no-interaction --no-update
3936
- composer require "symfony/web-server-bundle:${SYMFONY_VERSION}" --no-interaction --no-update
4037
- composer install --no-interaction --prefer-dist
4138
- (cd tests/Application && yarn install)
4239

4340
before_script:
44-
- (cd tests/Application && bin/console doctrine:database:create --env=test -vvv)
45-
- (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv)
46-
- (cd tests/Application && bin/console assets:install public --env=test -vvv)
47-
- (cd tests/Application && bin/console cache:warmup --env=test -vvv)
41+
- (cd tests/Application && bin/console doctrine:database:create -vvv)
42+
- (cd tests/Application && bin/console doctrine:schema:create -vvv)
43+
- (cd tests/Application && bin/console assets:install public -vvv)
44+
- (cd tests/Application && bin/console cache:warmup -vvv)
4845
- (cd tests/Application && yarn build)
4946

5047
# Configure display
@@ -74,7 +71,7 @@ before_script:
7471
- java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &
7572

7673
# Run webserver
77-
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d public --env=test --quiet > /dev/null 2>&1 &)
74+
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 --quiet > /dev/null 2>&1 &)
7875

7976
script:
8077
- composer validate --strict

behat.yml.dist

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
imports:
2-
- vendor/sylius/sylius/behat.yml.dist
2+
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml
33
- tests/Behat/Resources/suites.yml
44

55
default:
66
extensions:
7-
FriendsOfBehat\ContextServiceExtension:
8-
imports:
9-
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
10-
- tests/Behat/Resources/services.xml
7+
Lakion\Behat\MinkDebugExtension:
8+
directory: etc/build
9+
clean_start: false
10+
screenshot: true
11+
12+
Behat\MinkExtension:
13+
files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/"
14+
base_url: "http://localhost:8080/"
15+
default_session: symfony
16+
javascript_session: chrome
17+
sessions:
18+
symfony:
19+
symfony: ~
20+
chrome:
21+
selenium2:
22+
browser: chrome
23+
capabilities:
24+
browserName: chrome
25+
browser: chrome
26+
version: ""
27+
marionette: null # https://github.com/Behat/MinkExtension/pull/311
28+
chrome:
29+
switches:
30+
- "start-fullscreen"
31+
- "start-maximized"
32+
- "no-sandbox"
33+
firefox:
34+
selenium2:
35+
browser: firefox
36+
show_auto: false
1137

1238
FriendsOfBehat\SymfonyExtension:
13-
env_file: tests/Application/.env.test
39+
bootstrap: tests/Application/config/bootstrap.php
1440
kernel:
15-
env: test
16-
debug: true
1741
class: Tests\Acme\SyliusExamplePlugin\Application\Kernel
18-
path: tests/Application/Kernel.php
19-
bootstrap: ~
2042

21-
Lakion\Behat\MinkDebugExtension:
22-
directory: etc/build
23-
clean_start: false
24-
screenshot: true
43+
FriendsOfBehat\VariadicExtension: ~
44+
45+
FriendsOfBehat\SuiteSettingsExtension:
46+
paths:
47+
- "features"

composer.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
"behat/mink-browserkit-driver": "^1.3",
1616
"behat/mink-extension": "^2.2",
1717
"behat/mink-selenium2-driver": "^1.3",
18-
"friends-of-behat/context-service-extension": "^1.2",
19-
"friends-of-behat/cross-container-extension": "^1.1",
20-
"friends-of-behat/page-object-extension": "^0.2.1",
21-
"friends-of-behat/service-container-extension": "^1.0",
22-
"friends-of-behat/symfony-extension": "^1.2.1",
18+
"friends-of-behat/page-object-extension": "^0.3",
19+
"friends-of-behat/suite-settings-extension": "^1.0",
20+
"friends-of-behat/symfony-extension": "^2.0",
2321
"friends-of-behat/variadic-extension": "^1.1",
2422
"lakion/mink-debug-extension": "^1.2.3",
2523
"phpspec/phpspec": "^5.0",
@@ -32,7 +30,7 @@
3230
"sylius-labs/coding-standard": "^2.0",
3331
"symfony/browser-kit": "^3.4|^4.1",
3432
"symfony/debug-bundle": "^3.4|^4.1",
35-
"symfony/dotenv": "^3.4|^4.1",
33+
"symfony/dotenv": "^4.2",
3634
"symfony/intl": "^3.4|^4.1",
3735
"symfony/web-profiler-bundle": "^3.4|^4.1",
3836
"symfony/web-server-bundle": "^3.4|^4.1"
@@ -51,6 +49,9 @@
5149
"Tests\\Acme\\SyliusExamplePlugin\\": "tests/"
5250
}
5351
},
52+
"autoload-dev": {
53+
"classmap": ["tests/Application/Kernel.php"]
54+
},
5455
"extra": {
5556
"branch-alias": {
5657
"dev-master": "1.4-dev"

phpunit.xml.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
55
backupGlobals="false"
66
colors="true"
7-
bootstrap="vendor/autoload.php">
7+
bootstrap="tests/Application/config/bootstrap.php">
88
<testsuites>
99
<testsuite name="AcmeSyliusExamplePlugin Test Suite">
1010
<directory>tests</directory>
1111
</testsuite>
12+
<env name="APP_ENV" value="test"/>
13+
<env name="SHELL_VERBOSITY" value="-1" />
1214
</testsuites>
1315

1416
<php>
File renamed without changes.

tests/Application/.env.prod.dist

-23
This file was deleted.

tests/Application/.env.test

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
APP_SECRET='ch4mb3r0f5ecr3ts'
2+
3+
KERNEL_CLASS='Tests\Acme\SyliusExamplePlugin\Application\Kernel'

tests/Application/.env.test.dist

-23
This file was deleted.

tests/Application/.gitignore

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
/var/*
2-
!/var/.gitignore
3-
41
/public/assets
5-
/public/bundles
62
/public/css
73
/public/js
84
/public/media/*
95
!/public/media/image/
106
/public/media/image/*
117
!/public/media/image/.gitignore
128

13-
/vendor
149
/node_modules
1510

16-
/.env
17-
/.env.prod
18-
/.env.staging
19-
/.env.test
20-
/.env.test_cached
11+
###> symfony/framework-bundle ###
12+
/.env.*.local
13+
/.env.local
14+
/.env.local.php
15+
/public/bundles
16+
/var/
17+
/vendor/
18+
###< symfony/framework-bundle ###
19+
20+
###> symfony/web-server-bundle ###
21+
/.web-server-pid
22+
###< symfony/web-server-bundle ###

tests/Application/bin/console

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
#!/usr/bin/env php
22
<?php
33

4-
declare(strict_types=1);
5-
4+
use Tests\Acme\SyliusExamplePlugin\Application\Kernel;
65
use Symfony\Bundle\FrameworkBundle\Console\Application;
76
use Symfony\Component\Console\Input\ArgvInput;
87
use Symfony\Component\Debug\Debug;
9-
use Symfony\Component\Dotenv\Dotenv;
10-
use Tests\Acme\SyliusExamplePlugin\Application\Kernel;
118

129
set_time_limit(0);
1310

1411
require __DIR__.'/../../../vendor/autoload.php';
1512

1613
if (!class_exists(Application::class)) {
17-
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
14+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
1815
}
1916

20-
if (!isset($_SERVER['APP_ENV'])) {
21-
if (!class_exists(Dotenv::class)) {
22-
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
23-
}
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+
}
2421

25-
$envFile = file_exists(__DIR__.'/../.env') ? __DIR__.'/../.env' : __DIR__.'/../.env.dist';
26-
(new Dotenv())->load($envFile);
22+
if ($input->hasParameterOption('--no-debug', true)) {
23+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
2724
}
2825

29-
$input = new ArgvInput();
30-
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
31-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
26+
require dirname(__DIR__).'/config/bootstrap.php';
3227

33-
if ($debug) {
28+
if ($_SERVER['APP_DEBUG']) {
3429
umask(0000);
3530

3631
if (class_exists(Debug::class)) {
3732
Debug::enable();
3833
}
3934
}
4035

41-
$kernel = new Kernel($env, $debug);
36+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
4237
$application = new Application($kernel);
4338
$application->run($input);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Symfony\Component\Dotenv\Dotenv;
4+
5+
require dirname(__DIR__).'../../../vendor/autoload.php';
6+
7+
// Load cached env vars if the .env.local.php file exists
8+
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
9+
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
10+
$_SERVER += $env;
11+
$_ENV += $env;
12+
} elseif (!class_exists(Dotenv::class)) {
13+
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
14+
} else {
15+
// load all the .env files
16+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
17+
}
18+
19+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
20+
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
21+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

tests/Application/config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
Acme\SyliusExamplePlugin\AcmeSyliusExamplePlugin::class => ['all' => true],
5757
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
5858
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
59+
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
5960
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
imports:
2+
- { resource: "../../Behat/Resources/services.xml" }
3+
- { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" }

tests/Application/public/index.php

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
<?php
22

3-
declare(strict_types=1);
4-
3+
use Tests\Acme\SyliusExamplePlugin\Application\Kernel;
54
use Symfony\Component\Debug\Debug;
6-
use Symfony\Component\Dotenv\Dotenv;
75
use Symfony\Component\HttpFoundation\Request;
8-
use Tests\Acme\SyliusExamplePlugin\Application\Kernel;
9-
10-
require __DIR__.'/../../../vendor/autoload.php';
11-
12-
// The check is to ensure we don't use .env in production
13-
if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) {
14-
if (!class_exists(Dotenv::class)) {
15-
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
16-
}
17-
18-
$envFile = file_exists(__DIR__.'/../.env') ? __DIR__.'/../.env' : __DIR__.'/../.env.dist';
19-
(new Dotenv())->load($envFile);
20-
}
216

22-
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
23-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env));
7+
require dirname(__DIR__).'/config/bootstrap.php';
248

25-
if ($debug) {
9+
if ($_SERVER['APP_DEBUG']) {
2610
umask(0000);
2711

2812
Debug::enable();
2913
}
3014

31-
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
15+
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
3216
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
3317
}
3418

35-
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
36-
Request::setTrustedHosts(explode(',', $trustedHosts));
19+
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
20+
Request::setTrustedHosts([$trustedHosts]);
3721
}
3822

39-
$kernel = new Kernel($env, $debug);
23+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
4024
$request = Request::createFromGlobals();
4125
$response = $kernel->handle($request);
4226
$response->send();

tests/Behat/Resources/services.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
44
<services>
5+
<defaults public="true" />
56
<!-- Put your Behat services here -->
67

78
<service id="acme_sylius_example.context.ui.shop.welcome" class="Tests\Acme\SyliusExamplePlugin\Behat\Context\Ui\Shop\WelcomeContext">
89
<argument type="service" id="acme_sylius_example.page.shop.static_welcome" />
910
<argument type="service" id="acme_sylius_example.page.shop.dynamic_welcome" />
10-
<tag name="fob.context_service" />
1111
</service>
1212

1313
<service id="acme_sylius_example.page.shop.static_welcome" class="Tests\Acme\SyliusExamplePlugin\Behat\Page\Shop\StaticWelcomePage" parent="sylius.behat.symfony_page" public="false" />

0 commit comments

Comments
 (0)