Skip to content

Commit

Permalink
Fix the compactors order and compress the composer.lock file (#228)
Browse files Browse the repository at this point in the history
Fix the compactors order:
- Run the PHP Compactor before PHP-Scoper which can remove the useless spaces since will print again
  each file
- Compress the JSON files after PHP-Scoper since PHP-Scoper will pretty print the scoped JSON files

Also ensure that the JSON compactor can compress the `composer.lock` files.

Closes #219
  • Loading branch information
theofidry authored May 19, 2018
1 parent ec7ab5b commit 1351392
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

"compression": "GZ",
"compactors": [
"Herrera\\Box\\Compactor\\Json",
"Herrera\\Box\\Compactor\\Php",
"KevinGH\\Box\\Compactor\\PhpScoper",
"Herrera\\Box\\Compactor\\Php"
"Herrera\\Box\\Compactor\\Json"
],
"git-commit": "git-commit",
"git-version": "git-version"
Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Json extends FileExtensionCompactor
/**
* {@inheritdoc}
*/
public function __construct(array $extensions = ['json'])
public function __construct(array $extensions = ['json', 'lock'])
{
parent::__construct($extensions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
* @internal
* @private
*/
const NO_PARALLEL_PROCESSING = 'KevinGH\Box\BOX_NO_PARALLEL_PROCESSING';
const _NO_PARALLEL_PROCESSING = '_BOX_NO_PARALLEL_PROCESSING';
4 changes: 2 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ class_alias(\KevinGH\Box\Compactor\Php::class, \Herrera\Box\Compactor\Php::class
*/
function disable_parallel_processing(): void
{
define(NO_PARALLEL_PROCESSING, true);
define(_NO_PARALLEL_PROCESSING, true);
}

/**
* @private
*/
function is_parallel_processing_enabled(): bool
{
return false === defined(NO_PARALLEL_PROCESSING) || false === constant(NO_PARALLEL_PROCESSING);
return false === defined(_NO_PARALLEL_PROCESSING) || false === constant(_NO_PARALLEL_PROCESSING);
}
12 changes: 12 additions & 0 deletions tests/Compactor/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public function test_it_compacts_JSON_files(string $content, string $expected):
$this->assertSame($expected, $actual);
}

/**
* @dataProvider provideJsonContent
*/
public function test_it_compacts_Composer_lock_files(string $content, string $expected): void
{
$file = 'composer.lock';

$actual = $this->compactor->compact($file, $content);

$this->assertSame($expected, $actual);
}

public function provideFiles()
{
yield 'no extension' => ['test', false];
Expand Down

0 comments on commit 1351392

Please sign in to comment.