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

Allow to add non existent binary file when the content is provided #125

Merged
merged 1 commit into from
Apr 19, 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
6 changes: 5 additions & 1 deletion src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace KevinGH\Box;

use Assert\Assertion;
use function file_exists;
use KevinGH\Box\Compactor\PhpScoper;
use KevinGH\Box\Composer\ComposerOrchestrator;
use KevinGH\Box\PhpScoper\NullScoper;
Expand Down Expand Up @@ -240,7 +241,10 @@ public function addFile(string $file, string $contents = null, bool $binary = fa
}

if ($binary) {
$this->phar->addFile($file, $local);
true === file_exists($file)
? $this->phar->addFile($file, $local)
: $this->phar->addFromString($local, $contents)
;
} else {
$processedContents = self::compactContents(
$this->compactors,
Expand Down
17 changes: 17 additions & 0 deletions tests/BoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ public function test_it_can_add_a_non_exitent_file_with_contents_to_the_phar():
$this->assertSame($expectedContents, $actualContents);
}

public function test_it_can_add_a_non_existent_bin_file_with_contents_to_the_phar(): void
{
$file = 'foo';
$contents = 'test';

$this->box->addFile($file, $contents, true);

$expectedContents = $contents;
$expectedPharPath = 'phar://test.phar/'.$file;

$this->assertFileExists($expectedPharPath);

$actualContents = file_get_contents($expectedPharPath);

$this->assertSame($expectedContents, $actualContents);
}

public function test_it_can_add_a_file_with_absolute_path_to_the_phar(): void
{
$relativePath = 'path-to/foo';
Expand Down