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 file if the content is provided #120

Merged
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
7 changes: 3 additions & 4 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ function ($file): string {
*/
public function addFile(string $file, string $contents = null, bool $binary = false): string
{
Assertion::file($file);
Assertion::readable($file);

$contents = null === $contents ? file_get_contents($file) : $contents;
if (null === $contents) {
$contents = file_contents($file);
}

$relativePath = make_path_relative($file, $this->basePath);
$local = ($this->mapFile)($relativePath);
Expand Down
17 changes: 17 additions & 0 deletions tests/BoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ public function test_it_can_add_a_file_to_the_phar(): void
$this->assertSame($expectedContents, $actualContents);
}

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

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

$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