Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cd php-compiler
composer install
./phpc test # full PHPUnit suite (VM, compliance, JIT, AOT)
./phpc run -r 'echo 1;' # VM mode (or: php bin/vm.php -r 'echo 1;')
./phpc run -q 'name=Dev' examples/001-SimpleWeb/example.php # web example without TCP
make web-smoke # VM: examples/001-SimpleWeb
./phpc serve examples/001-SimpleWeb # http://127.0.0.1:8080/ (or: make serve)
```
Expand Down
7 changes: 5 additions & 2 deletions bin/phpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Usage:
* phpc serve [host:port] [docroot]
* phpc serve --aot [host:port] [docroot] [--binary path]
* phpc run script.php [args...]
* phpc run [-q 'name=World'] [-p 'field=val'] script.php [args...]
* phpc build [-o outfile] entry.php
* phpc lint [-r 'code'] [--json] entry.php
* phpc test [-- phpunit/ci-local args...]
Expand All @@ -27,7 +27,10 @@
phpc serve [host:port] [docroot] Start HTTP dev server (VM)
phpc serve --aot [host:port] [docroot] Serve precompiled AOT binary (CGI env)
[--binary path] Explicit binary or phpc.json "binary"
phpc run <script.php> [args...] Run a script in the VM
phpc run <script.php> [vm.php flags...] Run a script in the VM
-q 'name=World' CGI-style QUERY_STRING → $_GET
-p 'field=value' CGI-style POST body → $_POST
Example: phpc run -q 'name=Dev' examples/001-SimpleWeb/example.php
phpc build [-o out] <entry.php> AOT compile to a native binary
phpc lint [-r 'code'] [--json] <entry.php> Report unsupported syntax (line-accurate)
phpc test [args...] Run ./script/ci-local.sh
Expand Down
27 changes: 27 additions & 0 deletions test/unit/PhpcCliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ public function testHelpListsSubcommands(): void
$this->assertStringContainsString('phpc build', $out !== false ? $out : '');
$this->assertStringContainsString('phpc test', $out !== false ? $out : '');
$this->assertStringContainsString('phpc lint', $out !== false ? $out : '');
$this->assertStringContainsString('-q', $out !== false ? $out : '');
$this->assertStringContainsString('$_GET', $out !== false ? $out : '');
}

public function testRunSimpleWebWithQueryFlag(): void
{
$repoRoot = dirname(__DIR__, 2);
$script = $repoRoot.'/examples/001-SimpleWeb/example.php';
$cmd = array_merge(
self::phpCommand(),
[$repoRoot.'/bin/phpc.php', 'run', '-q', 'name=Dev', $script]
);
$descriptorSpec = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$proc = proc_open($cmd, $descriptorSpec, $pipes, $repoRoot);
$this->assertIsResource($proc);
fclose($pipes[0]);
$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$exit = proc_close($proc);
$this->assertSame(0, $exit, $err !== false ? $err : '');
$this->assertStringContainsString('Hello Dev', $out !== false ? $out : '');
}

/**
Expand Down
Loading