Skip to content

Commit e5efabc

Browse files
authored
Add support for Symfony (#271)
Add the necessary scopers and patchers to be able to scope a Symfony application with its YAML or XML configuration files out of the box.
1 parent fecc042 commit e5efabc

35 files changed

+3319
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/fixtures/set004/scoper.inc.php
99
/fixtures/*/.box_dump/
1010
/fixtures/*/vendor/
11+
/fixtures/set028-symfony/expected-output
1112
.phpunit*
1213
/vendor/
1314
/vendor-bin/*/vendor/

Makefile

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ tm: bin/phpunit
6262

6363
.PHONY: e2e
6464
e2e: ## Run end-to-end tests
65-
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021 e2e_022 e2e_023 e2e_024 e2e_025 e2e_026 e2e_027
65+
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021 e2e_022 e2e_023 e2e_024 e2e_025 e2e_026 e2e_027 e2e_028
6666

6767
PHPSCOPER=bin/php-scoper.phar
6868

@@ -282,7 +282,6 @@ e2e_026: bin/php-scoper.phar fixtures/set026/vendor
282282
php build/set026/main.php > build/set026/output
283283
diff fixtures/set026/expected-output build/set026/output
284284

285-
286285
.PHONY: e2e_027
287286
e2e_027: ## Run end-to-end tests for the fixture set 027 — Laravel
288287
e2e_027: bin/php-scoper.phar fixtures/set027-laravel/vendor
@@ -298,6 +297,24 @@ e2e_027: bin/php-scoper.phar fixtures/set027-laravel/vendor
298297
php build/set027-laravel/artisan -V > build/set027-laravel/output
299298
diff fixtures/set027-laravel/expected-output build/set027-laravel/output
300299

300+
.PHONY: e2e_028
301+
e2e_028: ## Run end-to-end tests for the fixture set 028 — Symfony
302+
e2e_028: bin/php-scoper.phar fixtures/set028-symfony/vendor
303+
php $(PHPSCOPER) add-prefix \
304+
--working-dir=fixtures/set028-symfony \
305+
--output-dir=../../build/set028-symfony \
306+
--no-config \
307+
--force \
308+
--no-interaction \
309+
--stop-on-failure
310+
311+
APP_ENV=dev composer --working-dir=fixtures/set028-symfony dump-autoload --no-dev
312+
APP_ENV=dev php fixtures/set028-symfony/bin/console -V > fixtures/set028-symfony/expected-output
313+
314+
APP_ENV=dev composer --working-dir=build/set028-symfony dump-autoload --no-dev
315+
APP_ENV=dev php build/set028-symfony/bin/console -V > build/set028-symfony/output
316+
317+
diff fixtures/set028-symfony/expected-output build/set028-symfony/output
301318

302319
.PHONY: tb
303320
BLACKFIRE=blackfire
@@ -396,6 +413,10 @@ fixtures/set027-laravel/vendor: fixtures/set027-laravel/composer.lock
396413
composer --working-dir=fixtures/set027-laravel install --no-dev
397414
touch $@
398415

416+
fixtures/set028-symfony/vendor: fixtures/set028-symfony/composer.lock
417+
composer --working-dir=fixtures/set028-symfony install --no-dev --no-scripts
418+
touch $@
419+
399420
composer.lock: composer.json
400421
@echo composer.lock is not up to date.
401422

@@ -444,6 +465,9 @@ fixtures/set025/composer.lock: fixtures/set025/composer.json
444465
fixtures/set027-laravel/composer.lock: fixtures/set027-laravel/composer.json
445466
@echo fixtures/set027-laravel/composer.lock is not up to date.
446467

468+
fixtures/set028-symfony/composer.lock: fixtures/set028-symfony/composer.json
469+
@echo fixtures/set028-symfony/composer.lock is not up to date.
470+
447471
bin/php-scoper.phar: bin/php-scoper src vendor scoper.inc.php box.json.dist
448472
$(BOX) compile
449473
touch $@

composer.lock

Lines changed: 36 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/set028-symfony/.env.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is a "template" of which env vars need to be defined for your application
2+
# Copy this file to .env file for development, create environment variables when deploying to production
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=dev
7+
APP_SECRET=7379902cbd219672e341bc2d985138b1
8+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
9+
#TRUSTED_HOSTS=localhost,example.com
10+
###< symfony/framework-bundle ###

fixtures/set028-symfony/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
###> symfony/framework-bundle ###
3+
/.env
4+
/public/bundles/
5+
/var/
6+
/vendor/
7+
###< symfony/framework-bundle ###
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
use Symfony\Component\Dotenv\Dotenv;
9+
10+
set_time_limit(0);
11+
12+
require __DIR__.'/../vendor/autoload.php';
13+
14+
if (!class_exists(Application::class)) {
15+
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
16+
}
17+
18+
if (!isset($_SERVER['APP_ENV'])) {
19+
if (!class_exists(Dotenv::class)) {
20+
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.');
21+
}
22+
(new Dotenv())->load(__DIR__.'/../.env');
23+
}
24+
25+
$input = new ArgvInput();
26+
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
27+
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
28+
29+
if ($debug) {
30+
umask(0000);
31+
32+
if (class_exists(Debug::class)) {
33+
Debug::enable();
34+
}
35+
}
36+
37+
$kernel = new Kernel($env, $debug);
38+
$application = new Application($kernel);
39+
$application->run($input);

0 commit comments

Comments
 (0)