diff --git a/.env.dist b/.env similarity index 100% rename from .env.dist rename to .env diff --git a/.env.test b/.env.test new file mode 100644 index 00000000000..1556a53206c --- /dev/null +++ b/.env.test @@ -0,0 +1,3 @@ +APP_SECRET='s$cretf0rt3st' + +KERNEL_CLASS='App\Kernel' diff --git a/.env.test.dist b/.env.test.dist deleted file mode 100644 index 919b4ad083f..00000000000 --- a/.env.test.dist +++ /dev/null @@ -1,23 +0,0 @@ -# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file -# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. -# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration - -###> symfony/framework-bundle ### -APP_ENV=test -APP_DEBUG=1 -APP_SECRET=EDITME -###< symfony/framework-bundle ### - -###> doctrine/doctrine-bundle ### -# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" -# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_%kernel.environment% -###< doctrine/doctrine-bundle ### - -###> symfony/swiftmailer-bundle ### -# For Gmail as a transport, use: "gmail://username:password@localhost" -# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" -# Delivery is disabled by default via "null://localhost" -MAILER_URL=null://localhost -###< symfony/swiftmailer-bundle ### diff --git a/.env.test_cached b/.env.test_cached new file mode 100644 index 00000000000..dc9cf85b703 --- /dev/null +++ b/.env.test_cached @@ -0,0 +1,4 @@ +APP_DEBUG=0 +APP_SECRET='s$cretf0rt3st' + +KERNEL_CLASS='App\Kernel' diff --git a/.env.test_cached.dist b/.env.test_cached.dist deleted file mode 100644 index 9788dd07493..00000000000 --- a/.env.test_cached.dist +++ /dev/null @@ -1,23 +0,0 @@ -# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file -# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. -# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration - -###> symfony/framework-bundle ### -APP_ENV=test_cached -APP_DEBUG=0 -APP_SECRET=EDITME -###< symfony/framework-bundle ### - -###> doctrine/doctrine-bundle ### -# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" -# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_${APP_ENV} -###< doctrine/doctrine-bundle ### - -###> symfony/swiftmailer-bundle ### -# For Gmail as a transport, use: "gmail://username:password@localhost" -# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" -# Delivery is disabled by default via "null://localhost" -MAILER_URL=null://localhost -###< symfony/swiftmailer-bundle ### diff --git a/.gitignore b/.gitignore index f43b8b5ebb0..5ec5edf91e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,4 @@ -/var/* -!/var/.gitkeep - /public/assets -/public/bundles /public/css /public/js /public/media @@ -15,7 +11,6 @@ /docs/.doctrees /composer.lock -/vendor /node_modules /etc/build/* @@ -24,11 +19,14 @@ /behat.yml /phpspec.yml -/.env -/.env.prod -/.env.staging -/.env.test -/.env.test_cached +###> symfony/framework-bundle ### +/.env.*.local +/.env.local +/.env.local.php +/public/bundles +/var/ +/vendor/ +###< symfony/framework-bundle ### ###> symfony/web-server-bundle ### /.web-server-pid diff --git a/.travis.yml b/.travis.yml index d50b12bf470..afb51280bdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ sudo: false env: global: + - APP_ENV=test_cached - SYLIUS_CACHE_DIR=$HOME/.sylius-cache - SYLIUS_BUILD_DIR=etc/build @@ -71,9 +72,6 @@ cache: - $SYLIUS_CACHE_DIR before_install: - - mv .env.test_cached.dist .env.test_cached - - set -a && source .env.test_cached && set +a - - etc/travis/run-suite before_install "${SYLIUS_SUITE}" install: diff --git a/app/AppKernel.php b/app/AppKernel.php deleted file mode 100644 index 411beb4c8c6..00000000000 --- a/app/AppKernel.php +++ /dev/null @@ -1,20 +0,0 @@ -getParameterOption(['--env', '-e'], null, true)) { + putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); +} - $envFile = file_exists(__DIR__.'/../.env') ? __DIR__.'/../.env' : __DIR__.'/../.env.dist'; - (new Dotenv())->load($envFile); +if ($input->hasParameterOption('--no-debug', true)) { + putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); } -$input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true); -$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true); +require dirname(__DIR__).'/config/bootstrap.php'; -if ($debug) { +if ($_SERVER['APP_DEBUG']) { umask(0000); if (class_exists(Debug::class)) { @@ -35,6 +33,6 @@ if ($debug) { } } -$kernel = new Kernel($env, $debug); +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $application = new Application($kernel); $application->run($input); diff --git a/bin/require-symfony-version b/bin/require-symfony-version index 8d7beafeeb8..d8f6a961ca2 100755 --- a/bin/require-symfony-version +++ b/bin/require-symfony-version @@ -13,7 +13,6 @@ $packages = [ 'symfony/dependency-injection', 'symfony/doctrine-bridge', 'symfony/dom-crawler', - 'symfony/dotenv', 'symfony/event-dispatcher', 'symfony/expression-language', 'symfony/filesystem', diff --git a/composer.json b/composer.json index 8c88796908c..15058eac8e5 100644 --- a/composer.json +++ b/composer.json @@ -121,7 +121,7 @@ "sylius-labs/coding-standard": "^3.0", "symfony/browser-kit": "^3.4|^4.1", "symfony/debug-bundle": "^3.4|^4.1", - "symfony/dotenv": "^3.4|^4.1", + "symfony/dotenv": "^4.2", "symfony/flex": "^1.1", "symfony/intl": "^3.4|^4.1", "symfony/web-profiler-bundle": "^3.4|^4.1", @@ -254,7 +254,7 @@ "spec\\Sylius\\Bundle\\UiBundle\\": "src/Sylius/Bundle/UiBundle/spec/", "spec\\Sylius\\Bundle\\UserBundle\\": "src/Sylius/Bundle/UserBundle/spec/" }, - "classmap": ["app/AppKernel.php", "app/TestAppKernel.php", "src/Kernel.php"] + "classmap": ["src/Kernel.php"] }, "scripts": { "auto-scripts": { diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 00000000000..f6afb404295 --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,21 @@ +=1.2) +if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { + // load all the .env files + (new Dotenv())->loadEnv(dirname(__DIR__).'/.env'); +} + +$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; +$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/etc/travis/suites/application/before_script.sh b/etc/travis/suites/application/before_script.sh index a3691e76754..11d55b91d73 100755 --- a/etc/travis/suites/application/before_script.sh +++ b/etc/travis/suites/application/before_script.sh @@ -4,13 +4,13 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/common.lib.s source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/application.sh" print_header "Setting the application up" "Sylius" -run_command "bin/console doctrine:database:create --env=test_cached -vvv" || exit $? # Have to be run with debug = true, to omit generating proxies before setting up the database -run_command "APP_DEBUG=1 bin/console cache:warmup --env=dev -vvv" || exit $? # For PHPStan -run_command "bin/console cache:warmup --env=test_cached --no-debug -vvv" || exit $? # For tests -run_command "bin/console doctrine:migrations:migrate --no-interaction --env=test_cached --no-debug -vvv" || exit $? +run_command "APP_DEBUG=1 bin/console doctrine:database:create -vvv" || exit $? # Have to be run with debug = true, to omit generating proxies before setting up the database +run_command "APP_DEBUG=1 APP_ENV=dev bin/console cache:warmup -vvv" || exit $? # For PHPStan +run_command "bin/console cache:warmup -vvv" || exit $? # For tests +run_command "bin/console doctrine:migrations:migrate --no-interaction -vvv" || exit $? print_header "Setting the web assets up" "Sylius" -run_command "bin/console assets:install public --env=test_cached --no-debug -vvv" || exit $? +run_command "bin/console assets:install public -vvv" || exit $? run_command "yarn build" || exit $? print_header "Making filesystem readonly" "Sylius" diff --git a/etc/travis/suites/application/script/test-behat-with-javascript b/etc/travis/suites/application/script/test-behat-with-javascript index caea2d84c84..c5d95c04b1a 100755 --- a/etc/travis/suites/application/script/test-behat-with-javascript +++ b/etc/travis/suites/application/script/test-behat-with-javascript @@ -28,7 +28,7 @@ prepare_for_behat_with_js() { run_command "java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &" # Run webserver - run_command "bin/console server:run 127.0.0.1:8080 -d public --env=test_cached --no-debug --quiet > /dev/null 2>&1 &" + run_command "bin/console server:run 127.0.0.1:8080 -d public --quiet > /dev/null 2>&1 &" } run_behat() { diff --git a/etc/travis/suites/application/script/test-fixtures b/etc/travis/suites/application/script/test-fixtures index 04c32ceb7a3..93f7beef376 100755 --- a/etc/travis/suites/application/script/test-fixtures +++ b/etc/travis/suites/application/script/test-fixtures @@ -3,4 +3,4 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" print_header "Testing (Fixtures)" "Sylius" -retry_run_command "bin/console sylius:fixtures:load default --env=test_cached --no-interaction --no-debug" +retry_run_command "bin/console sylius:fixtures:load default --no-interaction" diff --git a/etc/travis/suites/application/script/test-installer b/etc/travis/suites/application/script/test-installer index 0268565b2b3..249a8512355 100755 --- a/etc/travis/suites/application/script/test-installer +++ b/etc/travis/suites/application/script/test-installer @@ -3,4 +3,4 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" print_header "Testing (Installer)" "Sylius" -run_command "bin/console sylius:install --no-interaction --env=test_cached --no-debug -vvv" +run_command "bin/console sylius:install --no-interaction -vvv" diff --git a/etc/travis/suites/application/script/validate-doctrine-schema b/etc/travis/suites/application/script/validate-doctrine-schema index 1a60917e871..0a34a7d4042 100755 --- a/etc/travis/suites/application/script/validate-doctrine-schema +++ b/etc/travis/suites/application/script/validate-doctrine-schema @@ -3,4 +3,4 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" print_header "Validating (Doctrine schema)" "Sylius" -run_command "bin/console doctrine:schema:validate --env=test_cached --no-debug -vvv" +run_command "bin/console doctrine:schema:validate -vvv" diff --git a/etc/travis/suites/application/script/validate-twig b/etc/travis/suites/application/script/validate-twig index ab659363f5a..b8b023aadd6 100755 --- a/etc/travis/suites/application/script/validate-twig +++ b/etc/travis/suites/application/script/validate-twig @@ -3,4 +3,4 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" print_header "Validating (Twig templates)" "Sylius" -run_command "bin/console lint:twig src --env=test_cached --no-debug" +run_command "bin/console lint:twig src" diff --git a/etc/travis/suites/application/script/validate-yaml-files b/etc/travis/suites/application/script/validate-yaml-files index 66c209c41ba..034829e3786 100755 --- a/etc/travis/suites/application/script/validate-yaml-files +++ b/etc/travis/suites/application/script/validate-yaml-files @@ -3,4 +3,4 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" print_header "Validating (Yaml files)" "Sylius" -run_command "bin/console lint:yaml src --env=test_cached --no-debug" +run_command "bin/console lint:yaml src" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4e7d62388b3..ad0a95adc39 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,11 @@ + + bootstrap="config/bootstrap.php" +> tests @@ -14,16 +16,10 @@ - - - - - + + - - - diff --git a/public/index.php b/public/index.php index e6296baa88b..e30f90c0357 100644 --- a/public/index.php +++ b/public/index.php @@ -1,39 +1,26 @@ load($envFile); -} - -$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev'; -$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env)); - -if ($debug) { +if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); } -if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { +if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) { Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); } -if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) { - Request::setTrustedHosts(explode(',', $trustedHosts)); +if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) { + Request::setTrustedHosts([$trustedHosts]); } -$kernel = new Kernel($env, $debug); +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); diff --git a/src/Kernel.php b/src/Kernel.php index 0f3e3f41991..677b8d30fee 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -11,6 +11,8 @@ declare(strict_types=1); +namespace App; + use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\DelegatingLoader; diff --git a/src/Sylius/Behat/Resources/config/profiles/cached.yml b/src/Sylius/Behat/Resources/config/profiles/cached.yml index d6c128203b0..25390db08f0 100644 --- a/src/Sylius/Behat/Resources/config/profiles/cached.yml +++ b/src/Sylius/Behat/Resources/config/profiles/cached.yml @@ -4,7 +4,7 @@ cached: extensions: FriendsOfBehat\SymfonyExtension: - env_file: .env.test_cached kernel: - env: test_cached + bootstrap: config/bootstrap.php debug: false + env: test_cached diff --git a/src/Sylius/Behat/Resources/config/profiles/default.yml b/src/Sylius/Behat/Resources/config/profiles/default.yml index 312d3d61fae..08a59040dbc 100644 --- a/src/Sylius/Behat/Resources/config/profiles/default.yml +++ b/src/Sylius/Behat/Resources/config/profiles/default.yml @@ -41,11 +41,10 @@ default: show_auto: false FriendsOfBehat\SymfonyExtension: - env_file: .env.test kernel: - class: TestAppKernel - path: app/TestAppKernel.php - bootstrap: ~ + bootstrap: config/bootstrap.php + class: App\Kernel + env: test FriendsOfBehat\ContextServiceExtension: imports: diff --git a/symfony.lock b/symfony.lock index 6313345b86b..e85ea2b10b0 100644 --- a/symfony.lock +++ b/symfony.lock @@ -749,6 +749,9 @@ "symfony/var-dumper": { "version": "v4.1.3" }, + "symfony/var-exporter": { + "version": "v4.2.2" + }, "symfony/web-profiler-bundle": { "version": "3.3", "recipe": {