Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bootstrap feature #88

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ final class Configuration
private $basePath;
private $files;
private $binaryFiles;
private $bootstrapFile;
private $compactors;
private $compressionAlgorithm;
private $mainScriptPath;
Expand Down Expand Up @@ -93,7 +92,6 @@ final class Configuration
* @param string $basePath Utility to private the base path used and be able to retrieve a path relative to it (the base path)
* @param SplFileInfo[] $files List of files
* @param SplFileInfo[] $binaryFiles List of binary files
* @param null|string $bootstrapFile The bootstrap file path
* @param Compactor[] $compactors List of file contents compactors
* @param null|int $compressionAlgorithm Compression algorithm constant value. See the \Phar class constants
* @param null|int $fileMode File mode in octal form
Expand Down Expand Up @@ -121,7 +119,6 @@ private function __construct(
string $basePath,
array $files,
array $binaryFiles,
?string $bootstrapFile,
array $compactors,
?int $compressionAlgorithm,
?int $fileMode,
Expand Down Expand Up @@ -156,7 +153,6 @@ private function __construct(
$this->basePath = $basePath;
$this->files = $files;
$this->binaryFiles = $binaryFiles;
$this->bootstrapFile = $bootstrapFile;
$this->compactors = $compactors;
$this->compressionAlgorithm = $compressionAlgorithm;
$this->fileMode = $fileMode;
Expand Down Expand Up @@ -209,8 +205,6 @@ public static function create(?string $file, stdClass $raw): self
$binaryFilesAggregate = array_unique(iterator_to_array(chain($binaryFiles, $binaryDirectories, ...$binaryFilesFromFinders)));
}

$bootstrapFile = self::retrieveBootstrapFile($raw, $basePath);

$compactors = self::retrieveCompactors($raw, $basePath);
$compressionAlgorithm = self::retrieveCompressionAlgorithm($raw);

Expand Down Expand Up @@ -254,7 +248,6 @@ public static function create(?string $file, stdClass $raw): self
$basePath,
$filesAggregate,
$binaryFilesAggregate,
$bootstrapFile,
$compactors,
$compressionAlgorithm,
$fileMode,
Expand Down Expand Up @@ -304,20 +297,6 @@ public function getBinaryFiles(): array
return $this->binaryFiles;
}

public function getBootstrapFile(): ?string
{
return $this->bootstrapFile;
}

public function loadBootstrap(): void
{
$file = $this->bootstrapFile;

if (null !== $file) {
include $file;
}
}

/**
* @return Compactor[] the list of compactors
*/
Expand Down Expand Up @@ -728,7 +707,7 @@ function (SplFileInfo $fileInfo) use ($devPackages): bool {
);
}

//TODO: add fileExists (as file or directory) to Assert
// TODO: add fileExists (as file or directory) to Assert
if (false === is_file($fileOrDirectory)) {
Assertion::directory($fileOrDirectory);
} else {
Expand Down Expand Up @@ -854,21 +833,6 @@ private static function normalizePath(string $file, string $basePath): string
return make_path_absolute(trim($file), $basePath);
}

private static function retrieveBootstrapFile(stdClass $raw, string $basePath): ?string
{
// TODO: deprecate its usage & document this BC break. Compactors will not be configurable
// through that extension point so this is pretty much useless unless proven otherwise.
if (false === isset($raw->bootstrap)) {
return null;
}

$file = self::normalizePath($raw->bootstrap, $basePath);

Assertion::file($file, 'The bootstrap path "%s" is not a file or does not exist.');

return $file;
}

/**
* @return Compactor[]
*/
Expand Down
20 changes: 0 additions & 20 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ protected function execute(InputInterface $input, OutputInterface $output): void

$startTime = microtime(true);

$this->loadBootstrapFile($config, $logger);
$this->removeExistingPhar($config, $logger);

$logger->logStartBuilding($path);
Expand Down Expand Up @@ -167,25 +166,6 @@ private function createPhar(
}
}

private function loadBootstrapFile(Configuration $config, BuildLogger $logger): void
{
$file = $config->getBootstrapFile();

if (null === $file) {
return;
}

$logger->log(
BuildLogger::QUESTION_MARK_PREFIX,
sprintf(
'Loading the bootstrap file "%s"',
$file
)
);

$config->loadBootstrap();
}

private function removeExistingPhar(Configuration $config, BuildLogger $logger): void
{
$path = $config->getOutputPath();
Expand Down
57 changes: 0 additions & 57 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1725,27 +1725,6 @@ public function test_the_blacklist_setting_is_applied_to_all_the_files_found_in_
$this->assertCount(0, $this->config->getBinaryFiles());
}

public function test_no_bootstrap_file_is_configured_by_default(): void
{
$this->assertNull($this->config->getBootstrapFile());
$this->assertNull($this->getNoFileConfig()->getBootstrapFile());
}

public function test_configure_the_bootstrap_file(): void
{
touch('test.php');

$this->setconfig([
'bootstrap' => 'test.php',
'files' => [self::DEFAULT_FILE],
]);

$this->assertSame(
$this->tmp.DIRECTORY_SEPARATOR.'test.php',
$this->config->getBootstrapFile()
);
}

public function test_no_compactors_is_configured_by_default(): void
{
$this->assertSame([], $this->config->getCompactors());
Expand Down Expand Up @@ -2579,42 +2558,6 @@ public function testIsPrivateKeyPromptSetString(): void
$this->assertFalse($this->config->isPrivateKeyPrompt());
}

public function testLoadBootstrap(): void
{
file_put_contents(
'test.php',
<<<'CODE'
<?php define('TEST_BOOTSTRAP_FILE_LOADED', true);
CODE
);

$this->setConfig([
'bootstrap' => 'test.php',
'files' => [self::DEFAULT_FILE],
]);

$this->config->loadBootstrap();

$this->assertTrue(defined('TEST_BOOTSTRAP_FILE_LOADED'));
}

public function testLoadBootstrapNotExist(): void
{
try {
$this->setConfig([
'bootstrap' => 'test.php',
'files' => [self::DEFAULT_FILE],
]);

$this->fail('Expected exception to be thrown.');
} catch (InvalidArgumentException $exception) {
$this->assertSame(
'The bootstrap path "'.$this->tmp.DIRECTORY_SEPARATOR.'test.php" is not a file or does not exist.',
$exception->getMessage()
);
}
}

public function provideInvalidCompressionAlgorithms(): Generator
{
yield 'Invalid string key' => [
Expand Down
14 changes: 1 addition & 13 deletions tests/Console/Command/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function test_it_can_build_a_PHAR_file(): void
[
'alias' => 'alias-test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -94,7 +93,6 @@ public function test_it_can_build_a_PHAR_file(): void

// Loading the configuration file "/path/to/box.json.dist".

? Loading the bootstrap file "/path/to/tmp/bootstrap.php"
? Removing the existing PHAR "/path/to/tmp/test.phar"
Building the PHAR "/path/to/tmp/test.phar"
? Registering compactors
Expand Down Expand Up @@ -191,7 +189,6 @@ public function test_it_can_build_a_PHAR_from_a_different_directory(): void
[
'alias' => 'alias-test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -302,12 +299,12 @@ public function test_it_can_build_a_PHAR_without_any_configuration(): void
'/a/deep/test/',
'/a/deep/test/directory/',
'/a/deep/test/directory/test.php',
'/bootstrap.php',
'/one/',
'/one/test.php',
'/two/',
'/two/test.png',
'/binary',
'/bootstrap.php',
'/private.key',
'/test.phar',
'/test.phar.pubkey',
Expand All @@ -329,7 +326,6 @@ public function test_it_can_build_a_PHAR_with_complete_mapping(): void
json_encode(
[
'alias' => 'alias-test.phar',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -372,7 +368,6 @@ public function test_it_can_build_a_PHAR_with_complete_mapping(): void

// Loading the configuration file "/path/to/box.json.dist".

? Loading the bootstrap file "/path/to/tmp/bootstrap.php"
? Removing the existing PHAR "/path/to/tmp/test.phar"
Building the PHAR "/path/to/tmp/test.phar"
? Registering compactors
Expand Down Expand Up @@ -476,7 +471,6 @@ public function test_it_can_build_a_PHAR_file_in_verbose_mode(): void
[
'alias' => 'test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -523,7 +517,6 @@ public function test_it_can_build_a_PHAR_file_in_verbose_mode(): void

// Loading the configuration file "/path/to/box.json.dist".

? Loading the bootstrap file "/path/to/tmp/bootstrap.php"
? Removing the existing PHAR "/path/to/tmp/test.phar"
* Building the PHAR "/path/to/tmp/test.phar"
? Registering compactors
Expand Down Expand Up @@ -577,7 +570,6 @@ public function test_it_can_build_a_PHAR_file_in_very_verbose_mode(): void
'multiline',
'custom banner',
],
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -624,7 +616,6 @@ public function test_it_can_build_a_PHAR_file_in_very_verbose_mode(): void

// Loading the configuration file "/path/to/box.json.dist".

? Loading the bootstrap file "/path/to/tmp/bootstrap.php"
? Removing the existing PHAR "/path/to/tmp/test.phar"
* Building the PHAR "/path/to/tmp/test.phar"
? Registering compactors
Expand Down Expand Up @@ -681,7 +672,6 @@ public function test_it_can_build_a_PHAR_file_in_quiet_mode(): void
[
'alias' => 'test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -762,7 +752,6 @@ public function test_it_can_build_a_PHAR_file_using_the_PHAR_default_stub(): voi
[
'alias' => 'alias-test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down Expand Up @@ -831,7 +820,6 @@ public function test_it_can_build_a_PHAR_file_using_a_custom_stub(): void
[
'alias' => 'alias-test.phar',
'banner' => 'custom banner',
'bootstrap' => 'bootstrap.php',
'chmod' => '0755',
'compactors' => [Php::class],
'directories' => ['a'],
Expand Down