Skip to content

Commit 9154d8c

Browse files
authored
Make the build faster (#96)
1 parent f505f88 commit 9154d8c

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ build: src vendor vendor-bin/box/vendor
2020
rm -f bin/php-scoper.phar
2121
rm -rf build
2222

23+
# Remove unnecessary packages
2324
composer install --no-dev --prefer-dist
2425

26+
# Prefixes the code to be bundled
2527
php -d zend.enable_gc=0 bin/php-scoper add-prefix --force
26-
composer dump-autoload -d build --classmap-authoritative
28+
29+
# Re-dump the loader to account for the prefixing
30+
# and optimize the loader
31+
composer dump-autoload -d build --classmap-authoritative
32+
33+
# Build the PHAR
2734
php -d zend.enable_gc=0 -d phar.readonly=0 $(BOX) build $(CONFIG)
2835

2936
# Install back all the dependencies

box.json.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"chmod": "0755",
44
"main": "bin/php-scoper",
55
"output": "bin/php-scoper.phar",
6-
"directories": [
7-
"src",
8-
"tests"
9-
],
6+
"directories": ["src"],
107
"finder": [
118
{
129
"notName": "/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/",

scoper.inc.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,35 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Symfony\Component\Finder\Finder;
16+
1517
return [
1618
'global_namespace_whitelist' => [
1719
'AppKernel',
1820
function (string $className): bool {
1921
return 'PHPUnit' === substr($className, 0, 6);
2022
},
2123
],
24+
'finders' => [
25+
Finder::create()->files()->in('src'),
26+
Finder::create()
27+
->files()
28+
->ignoreVCS(true)
29+
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
30+
->exclude([
31+
'doc',
32+
'test',
33+
'test_old',
34+
'tests',
35+
'Tests',
36+
'vendor-bin',
37+
])
38+
->in('vendor'),
39+
Finder::create()->append([
40+
'bin/php-scoper',
41+
'composer.json',
42+
]),
43+
],
2244
'patchers' => [
2345
function (string $filePath, string $prefix, string $content): string {
2446
//

src/Console/Command/AddPrefixCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private function retrieveConfig(InputInterface $input, OutputStyle $io): Configu
272272
if (false === file_exists($configFile)) {
273273
$io->writeln(
274274
sprintf(
275-
'Patch file "%s" not found. Skipping.',
275+
'Config file "%s" not found. Skipping.',
276276
$configFile
277277
),
278278
OutputStyle::VERBOSITY_DEBUG

tests/Console/Command/AddPrefixCommandIntegrationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ protected function setUp()
6565

6666
$this->cwd = getcwd();
6767
$this->tmp = make_tmp_dir('scoper', __CLASS__);
68+
69+
chdir($this->tmp);
6870
}
6971

7072
/**

tests/Console/Command/AddPrefixCommandTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ protected function setUp()
7979
$this->handleProphecy = $this->prophesize(HandleAddPrefix::class);
8080

8181
$this->appTester = $this->createAppTester();
82+
83+
chdir($this->tmp);
8284
}
8385

8486
public function test_get_help_menu()
@@ -366,7 +368,7 @@ public function test_scope_the_current_working_directory_if_no_path_given()
366368
->__invoke(
367369
'MyPrefix',
368370
[
369-
$this->cwd,
371+
$this->tmp,
370372
],
371373
$this->tmp,
372374
Argument::type('array'),
@@ -414,8 +416,8 @@ public function test_relative_paths_are_relative_to_the_current_working_director
414416
'MyPrefix',
415417
[
416418
escape_path('/path/to/dir1'),
417-
escape_path($this->cwd.'/relative-path/to/dir2'),
418-
escape_path($this->cwd.'/relative-path/to/file'),
419+
escape_path($this->tmp.'/relative-path/to/dir2'),
420+
escape_path($this->tmp.'/relative-path/to/file'),
419421
],
420422
$this->tmp,
421423
Argument::type('array'),
@@ -702,7 +704,7 @@ public function test_throws_an_error_when_passing_a_non_existent_path_file()
702704

703705
$this->fail('Expected exception to be thrown.');
704706
} catch (RuntimeException $exception) {
705-
$patchFile = escape_path($this->cwd.'/unknown');
707+
$patchFile = escape_path($this->tmp.'/unknown');
706708

707709
$this->assertSame(
708710
"Could not find the file \"$patchFile\".",

0 commit comments

Comments
 (0)