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
2 changes: 1 addition & 1 deletion docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Auto-generated by `script/capability-matrix.php`. Do not edit by hand.
| `is_object` | yes | yes | yes | types | |
| `is_scalar` | yes | yes | yes | standard | |
| `is_string` | yes | yes | yes | types | JIT PHPT |
| `json_encode` | yes | yes | yes | standard | JIT PHPT |
| `json_encode` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `lcfirst` | yes | yes | yes | standard | |
| `log` | yes | yes | yes | standard | |
| `ltrim` | yes | yes | yes | standard | AOT PHPT |
Expand Down
11 changes: 11 additions & 0 deletions test/aot/ExampleWebAotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public function testStaticWebExampleFile(): void
$this->assertStringContainsString('<h1>Hello World</h1>', $result);
}

public function testApiJsonExampleFile(): void
{
$source = realpath(__DIR__ . '/../../examples/004-ApiJson/example.php');
$this->assertNotFalse($source);
$result = $this->compileAndRun($source, []);
$this->assertStringContainsString('Content-Type: application/json', $result);
$this->assertStringContainsString('Status: 200', $result);
$this->assertStringContainsString('"ok":true', $result);
$this->assertStringContainsString('php-compiler', $result);
}

/**
* @param list<string> $compileExtraArgs
*/
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/aot/cases/json_encode_api.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
AOT: json_encode API body with Content-Type and Status 200 (issues #61, #270)
--FILE--
<?php
header('Content-Type: application/json');
http_response_code(200);
echo json_encode(['ok' => true, 'service' => 'php-compiler']);
--EXPECT--
Content-Type: application/json
Status: 200
{"ok":true,"service":"php-compiler"}
--EXPECT_EXIT--
0
31 changes: 31 additions & 0 deletions test/unit/ExamplesCompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,37 @@ public function testAotExecuteSimpleWebPost(): void
@unlink($binary);
}

/**
* Shipped 004-ApiJson: compile.php -o temp binary — json_encode + http_response_code(200) AOT smoke.
*
* @group llvm
* @group aot
*
* @see https://github.com/PurHur/php-compiler/issues/270
*/
public function testAotExecuteSmoke004ApiJson(): void
{
if (!self::isLlvmReady()) {
$this->markTestSkipped(
'LLVM 9 toolchain not available. Run script/install-llvm9.sh from the repository root.'
);
}
$repoRoot = dirname(__DIR__, 2);
$source = realpath($repoRoot.'/examples/004-ApiJson/example.php');
$this->assertNotFalse($source);

$env = $this->llvmProcessEnv($repoRoot);
$binary = $this->compileAotBinaryNoQueryBaking($source, $repoRoot, $env);
$out = $this->runAotBinary($binary, $env);
$this->assertStringContainsString('Content-Type: application/json', $out);
$this->assertStringContainsString('Status: 200', $out);
foreach (self::smokeNeedles('004-ApiJson') as $needle) {
$this->assertStringContainsString($needle, $out);
}

@unlink($binary);
}

/**
* Shipped 002-StaticWeb: compile.php -o temp binary, run once — AOT link + runtime smoke (no superglobals).
*
Expand Down
Loading