Skip to content

Commit a2e26c7

Browse files
authored
Fix build step (#57)
- The build step _should_ work once the above is fixed - The e2e test requires the generated PHAR - `Composer` namespaces are whitelisted: not sure if it's a good idea but it's mandatory if we want to get it working for now otherwise things break as soon as you have a dependency which is a composer plugin (e.g. `ocramius/version-package`)
1 parent ad4a98d commit a2e26c7

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
BOX=vendor-bin/box/vendor/bin/box
22
PHPUNIT=vendor/bin/phpunit
3+
PHPSCOPER=bin/php-scoper.phar
34

45
.DEFAULT_GOAL := help
56
.PHONY: build test tu tc e2e
@@ -14,14 +15,23 @@ help:
1415
##---------------------------------------------------------------------------
1516

1617
build: ## Build the PHAR
17-
build: bin/php-scoper
18+
build: vendor
19+
rm -f bin/php-scoper.phar
1820
rm -rf build
1921
rm composer.lock
20-
composer install --no-dev --prefer-dist --classmap-authoritative
21-
php -d zend.enable_gc=0 bin/php-scoper add-prefix --force
22+
#
23+
# As of now, files included in `autoload-dev` are not excluded from the
24+
# classmap.
25+
#
26+
# See: https://github.com/composer/composer/issues/6457
27+
#
28+
# As a result, the the flag `--no-dev` for `composer install` cannot
29+
# be used and `box.json.dist` must include the `tests` directory
30+
#
31+
composer install --prefer-dist --classmap-authoritative
32+
php -d zend.enable_gc=0 bin/php-scoper.php add-prefix --force
2233
cd build && composer dump-autoload --classmap-authoritative
2334
php -d zend.enable_gc=0 $(BOX) build
24-
mv build/bin/php-scoper.phar bin/
2535
composer install
2636

2737

@@ -41,8 +51,8 @@ tc: vendor
4151
phpdbg -qrr -d zend.enable_gc=0 $(PHPUNIT) --coverage-html=dist/coverage --coverage-text
4252

4353
e2e: ## Run end-to-end tests
44-
e2e: vendor
45-
php -d zend.enable_gc=0 bin/php-scoper add-prefix fixtures/set004 -o build/set004 -f
54+
e2e: scoper
55+
php -d zend.enable_gc=0 $(PHPSCOPER) add-prefix fixtures/set004 -o build/set004 -f
4656
composer -d=build/set004 dump-autoload
4757
php -d zend.enable_gc=0 $(BOX) build -c build/set004/box.json.dist
4858
php build/set004/bin/greet.phar > build/output
@@ -74,3 +84,6 @@ vendor: composer.lock
7484

7585
composer.lock: composer.json
7686
@echo compose.lock is not up to date.
87+
88+
scoper: build
89+
File renamed without changes.

box.json.dist

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"output": "bin/php-scoper.phar",
3-
"main": "bin/php-scoper",
42
"base-path": "build",
3+
"main": "bin/php-scoper.php",
4+
"output": "bin/php-scoper.phar",
55
"directories": [
6-
"src"
6+
"src",
7+
"tests"
78
],
89
"finder": [
910
{

src/NodeVisitor/IgnoreNamespaceScoperNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function enterNode(Node $node)
3636
if ($node instanceof UseUse
3737
&& $node->hasAttribute('parent')
3838
&& false === ($node->getAttribute('parent') instanceof GroupUse)
39-
&& 1 === count($node->name->parts)
39+
&& (1 === count($node->name->parts) || 'Composer' === $node->name->getFirst())
4040
) {
4141
$node->setAttribute('phpscoper_ignore', true);
4242
}

tests/Scoper/PhpScoperTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,23 @@ public function provideValidFiles()
512512
use Humbug\Bar\FooNamespace;
513513
use Humbug\Bar\FooNamespace;
514514

515+
PHP
516+
];
517+
518+
yield '[Use statement for a class] composer use statement' => [
519+
<<<'PHP'
520+
<?php
521+
522+
use Composer\Unknown;
523+
524+
PHP
525+
,
526+
'Humbug',
527+
<<<'PHP'
528+
<?php
529+
530+
use Composer\Unknown;
531+
515532
PHP
516533
];
517534

0 commit comments

Comments
 (0)