Skip to content

Commit

Permalink
Fix usage of isolated Composer (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Mar 4, 2018
1 parent b0239f0 commit 561bcde
Show file tree
Hide file tree
Showing 4 changed files with 845 additions and 32 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tm: vendor/bin/phpunit
$(MAKE) e2e_020

e2e: ## Run end-to-end tests
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020
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_004: ## Run end-to-end tests for the fixture set 004: source code case
e2e_004: bin/php-scoper.phar
Expand Down Expand Up @@ -161,6 +161,16 @@ e2e_020: bin/php-scoper.phar fixtures/set020-infection/vendor clover.xml

diff build/set020-infection/expected-output build/set020-infection/output

e2e_021: ## Run end-to-end tests for the fixture set 020: Composer
e2e_021: bin/php-scoper.phar fixtures/set021-composer/vendor clover.xml
php -d zend.enable_gc=0 $(PHPSCOPER) add-prefix --working-dir=fixtures/set021-composer --output-dir=../../build/set021-composer --force --no-interaction --stop-on-failure --no-config
composer --working-dir=build/set021-composer dump-autoload

php fixtures/set021-composer/vendor/composer/composer/bin/composer licenses --no-plugins > build/set021-composer/expected-output
php build/set021-composer/vendor/composer/composer/bin/composer licenses --no-plugins > build/set021-composer/output

diff build/set021-composer/expected-output build/set021-composer/output

tb: ## Run Blackfire profiling
tb: vendor
rm -rf build
Expand Down Expand Up @@ -217,6 +227,9 @@ fixtures/set019-symfony-console/vendor: fixtures/set019-symfony-console/composer
fixtures/set020-infection/vendor: fixtures/set020-infection/composer.lock
composer --working-dir=fixtures/set020-infection install

fixtures/set021-composer/vendor: fixtures/set021-composer/composer.lock
composer --working-dir=fixtures/set021-composer install

composer.lock: composer.json
@echo composer.lock is not up to date.

Expand Down Expand Up @@ -247,6 +260,9 @@ fixtures/set019-symfony-console/composer.lock: fixtures/set019-symfony-console/c
fixtures/set020-infection/composer.lock: fixtures/set020-infection/composer.json
@echo fixtures/set020-infection/composer.lock is not up to date.

fixtures/set021-composer/composer.lock: fixtures/set021-composer/composer.json
@echo fixtures/set021-composer/composer.lock is not up to date.

bin/php-scoper.phar: bin/php-scoper src vendor vendor-bin/box/vendor scoper.inc.php box.json
$(MAKE) build

Expand Down
52 changes: 21 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
- [Configuration](#configuration)
- [Finders and paths](#finders-and-paths)
- [Patchers](#patchers)
- [Global Namespace Whitelisting](#global-namespace-whitelisting)
- [Whitelist](#whitelist)
- [Whitelist][whitelist]
- [Building A Scoped PHAR](#building-a-scoped-phar)
- [Step 1: Configure build location and prep vendors](#step-1-configure-build-location-and-prep-vendors)
- [Step 2: Run PHP-Scoper](#step-2-run-php-scoper)
Expand All @@ -46,6 +45,8 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
- [PSR-0 support](#psr-0-support)
- [String values](#string-values)
- [Native functions and constants shadowing](#native-functions-shadowing)
- [Composer](#composer)
- [Composer Plugins](#composer-plugins)
- [Contributing](#contributing)
- [Credits](#credits)

Expand Down Expand Up @@ -244,35 +245,6 @@ return [
];
```

### Global Namespace Whitelisting

By default, PHP-Scoper only scopes (or prefixes) code where the namespace is
non-global. In other words, non-namespaced code is not scoped. This leaves the
majority of classes, functions and constants in PHP, and most extensions,
untouched.

This is not necessarily a desirable outcome for vendor dependencies which are
also not namespaced. To ensure they are isolated, you can configure PHP-Scoper to
allow their prefixing from `scoper.inc.php` using basic strings or callables:

```php
<?php declare(strict_types=1);

// scoper.inc.php

return [
'global_namespace_whitelist' => [
'AppKernel',
function ($className) {
return 'PHPUnit' === substr($className, 0, 6);
},
],
];
```

In this example, we're ensuring that the `AppKernal` class, and any
non-namespaced PHPUnit packages are prefixed.


### Whitelist

Expand Down Expand Up @@ -473,6 +445,23 @@ is_array([]);
The situation is exactly the same for constants.


### Composer

PHP-Scoper does not support prefixing the dumped Composer autoloader and autoloading files. This is why you have to
manually dump the autoloader again after prefixing an application.


### Composer Plugins

Composer plugins are not supported. The issue is that for [whitelisting symbols](#whitelist) PHP-Scoper relies on the
fact that you should load the `vendor/scoper-autoload.php` file instead of `vendor/autoload.php` to trigger the loading
of the right classes with their class aliases. However Composer does not do that and as a result interfaces such as
`Composer\Plugin\Capability\Capable` are prefixed but the alias is not registered.

This cannot be changed easily so for now when you are using an isolated version of Composer, you will need to use the
`--no-plugins` option.


## Contributing

[Contribution Guide](CONTRIBUTING.md)
Expand All @@ -493,3 +482,4 @@ now been moved under the
[releases]: https://github.com/humbug/php-scoper/releases
[symfony_finder]: https://symfony.com/doc/current/components/finder.html
[releases]: https://github.com/humbug/php-scoper/releases
[whitelist]: #whitelist
5 changes: 5 additions & 0 deletions fixtures/set021-composer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"composer/composer": "^1.6"
}
}
Loading

0 comments on commit 561bcde

Please sign in to comment.