Skip to content

Commit

Permalink
feat(phar): add test for run phar
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Jun 11, 2024
1 parent a58230e commit 0be9b5c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bin/build-run-phar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env php
<?php

$phar = new Phar(__DIR__ . '/../examples/run.phar');
$phar['index.php'] = '<?php array_shift($_SERVER["argv"]); var_dump($_SERVER["argv"]); exit(0);';
$phar->setDefaultStub('index.php', 'index.php');
$phar->stopBuffering();
13 changes: 13 additions & 0 deletions examples/run-phar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace run;

use Castor\Attribute\AsTask;

use function Castor\run_phar;

#[AsTask(description: 'Run a phar in a sub process')]
function phar(): void
{
run_phar('examples/run.phar', 'a', 'list', 'of', 'arguments');
}
Binary file added examples/run.phar
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/Generated/FilesystemFindTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Number of PHP files: 31
Number of PHP files: 32
1 change: 1 addition & 0 deletions tests/Generated/ListTest.php.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ remote-import:remote-task-class Use a class th
remote-import:remote-tasks Use functions imported from remote packages
run:exception Run a command that will fail
run:ls Run a sub-process and display information about it
run:phar Run a phar in a sub process
run:test-file Run a sub-process and return its exit code, with get_exit_code() function
run:variables Run a sub-process with environment variables and display information about it
run:whoami Run a sub-process and display information about it, with capture() function
Expand Down
22 changes: 22 additions & 0 deletions tests/Generated/RunPharTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Castor\Tests\Generated;

use Castor\Tests\TaskTestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;

class RunPharTest extends TaskTestCase
{
// run:phar
public function test(): void
{
$process = $this->runTask(['run:phar']);

if (0 !== $process->getExitCode()) {
throw new ProcessFailedException($process);
}

$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput());
$this->assertSame('', $process->getErrorOutput());
}
}
10 changes: 10 additions & 0 deletions tests/Generated/RunPharTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
array(4) {
[0]=>
string(3) "'a'"
[1]=>
string(6) "'list'"
[2]=>
string(4) "'of'"
[3]=>
string(11) "'arguments'"
}

0 comments on commit 0be9b5c

Please sign in to comment.