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

Start Amp only if PHP-Scoper is used #171

Merged
merged 2 commits into from
Apr 28, 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
2 changes: 1 addition & 1 deletion src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private function processContents(array $files, string $cwd): array
return [$local, $processedContents];
};

return is_parallel_processing_enabled()
return is_parallel_processing_enabled() && false === ($this->scoper instanceof NullScoper)
? wait(parallelMap($files, $processFile))
: array_map($processFile, $files)
;
Expand Down
23 changes: 11 additions & 12 deletions tests/BoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace KevinGH\Box;

use Amp\MultiReasonException;
use Exception;
use InvalidArgumentException;
use KevinGH\Box\Compactor\FakeCompactor;
Expand Down Expand Up @@ -768,7 +767,7 @@ public function test_the_temporary_directory_created_for_box_is_removed_upon_fai
$this->box->addFiles(['/nowhere/foo'], false);

$this->fail('Expected exception to be thrown.');
} catch (MultiReasonException $exception) {
} catch (InvalidArgumentException $exception) {
$tmpDirs = iterator_to_array(
Finder::create()
->directories()
Expand All @@ -777,20 +776,20 @@ public function test_the_temporary_directory_created_for_box_is_removed_upon_fai
);

$boxDir = current(
array_filter(
$tmpDirs,
function (SplFileInfo $fileInfo) use ($boxTmp): bool {
return false === in_array(
$fileInfo->getRealPath(),
[realpath($boxTmp), realpath($this->tmp)],
true
);
}
array_filter(
$tmpDirs,
function (SplFileInfo $fileInfo) use ($boxTmp): bool {
return false === in_array(
$fileInfo->getRealPath(),
[realpath($boxTmp), realpath($this->tmp)],
true
);
}
)
);

$this->assertFalse(
$boxDir,
$boxDir,
sprintf(
'Did not expect to find the directory "%s".',
$boxDir
Expand Down
25 changes: 12 additions & 13 deletions tests/Console/Command/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

namespace KevinGH\Box\Console\Command;

use Amp\MultiReasonException;
use Amp\Parallel\Worker\TaskException;
use DirectoryIterator;
use Generator;
use InvalidArgumentException;
use KevinGH\Box\Compactor\Php;
use KevinGH\Box\Console\DisplayNormalizer;
use KevinGH\Box\Test\CommandTestCase;
Expand All @@ -33,10 +32,13 @@
use function preg_replace;
use function sort;

///**
// * @covers \KevinGH\Box\Console\Command\Compile
// * @runTestsInSeparateProcesses This is necessary as instantiating a PHAR in memory may load/autoload some stuff which
// * can create undesirable side-effects.
// */
/**
* @covers \KevinGH\Box\Console\Command\Compile
* @runTestsInSeparateProcesses This is necessary as instantiating a PHAR in memory may load/autoload some stuff which
* can create undesirable side-effects.
* @coversNothing
*/
class CompileTest extends CommandTestCase
{
Expand Down Expand Up @@ -408,6 +410,8 @@ public function test_it_can_build_a_PHAR_without_any_configuration(): void

$this->assertEquals($expectedFiles, $actualFiles, '', .0, 10, true);

unset($phar);
Phar::unlinkArchive('index.phar');
// Executes the compilation again

$commandTester->execute(
Expand Down Expand Up @@ -1103,15 +1107,10 @@ public function test_it_cannot_build_a_PHAR_using_unreadable_files(): void
);

$this->fail('Expected exception to be thrown.');
} catch (MultiReasonException $exception) {
$this->assertCount(1, $exception->getReasons());

/** @var TaskException $reason */
$reason = current($exception->getReasons());

} catch (InvalidArgumentException $exception) {
$this->assertRegExp(
'/^Uncaught .+?ArgumentException in worker with message ".+?" was expected to be readable\.".*$/',
$reason->getMessage()
'/^Path ".+?" was expected to be readable\.$/',
$exception->getMessage()
);
}
}
Expand Down