test: make compile-fixture verify files explicit typed closures#26
Conversation
Each executable verify file under test/fixture/compile/*/verify/ relied on
an implicit, untyped $fixture variable being in the enclosing test method's
scope at the point of `require`. The dependency was invisible from the file,
untyped, and enforced only by a docblock convention across 26 driver methods.
Each verify file now returns a `function (CompiledFixture $fixture): void`
that runs its assertions when invoked, and each driver calls it explicitly:
$runtime = require __DIR__ . '/.../verify/runtime.php';
$runtime($fixture);
The fixture dependency is now an explicit typed parameter. Behavior is
unchanged: the inner `require $fixture->targetDir . '/Use.php'` still runs in
the closure scope (so locals like $result are produced as before), assertion
failures still propagate through the invocation, and the try/finally still
cleans up the temp dir.
Also drop the decorative `echo "OK\n"` lines from the 11 files that had them:
stdout is never inspected, so the `Assert::` calls already signal pass/fail.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
| Filename | Overview |
|---|---|
| test/TestSupport/CompiledFixture.php | Updated docblock to document the new closure-return contract with a corrected usage example; no behavioral changes to the class itself. |
| test/Transpiler/Monomorphize/GenericFunctionIntegrationTest.php | Driver updated to $runtime = require ...; $runtime($fixture) for both verify files; pre-existing snapshot assertions are untouched. |
| test/Transpiler/Monomorphize/EnclosingParamBoundIntegrationTest.php | Largest driver file; all 11+ require call-sites consistently updated to the new two-line pattern. |
| test/Transpiler/Monomorphize/ClosureConformanceIntegrationTest.php | All 11 require call-sites correctly updated to the two-line pattern. |
| test/fixture/compile/array_sugar/verify/nullable_return.php | Wrapped in closure; $fixture parameter declared but never used inside the body — safe but may trigger static-analysis unused-parameter warnings. |
| test/fixture/compile/closure_use_by_ref/verify/runtime.php | require inside closure preserves by-reference variable semantics from the generated Use.php; assertions remain valid. |
| test/fixture/compile/generic_function/verify/runtime_execution.php | require funcs.php inside closure still registers free functions into the global symbol table; FQN assertions unaffected. |
| test/fixture/compile/builtin_interface_via_use/verify/runtime.php | Large verify file; try/catch block fully enclosed inside the returned closure, preserving exception-catch semantics. |
| test/fixture/compile/generic_exception_catch/verify/catch_runtime.php | All assertSame and assertTrue(is_subclass_of(...)) checks preserved inside the closure; no regressions. |
| test/fixture/compile/multi_type/verify/type_error_on_wrong_slot.php | try/catch for TypeError is inside the returned closure; exception propagation behavior is unchanged. |
Sequence Diagram
sequenceDiagram
participant Driver as Test Driver (testFoo method)
participant VerifyFile as verify/runtime.php
participant UsePhp as $fixture->targetDir/Use.php
participant Assert as PHPUnit Assert
Note over Driver,Assert: New pattern (this PR)
Driver->>Driver: "$fixture = CompiledFixture::compile(...)"
Driver->>Driver: "$fixture->registerAutoload(...)"
Driver->>VerifyFile: "$runtime = require 'verify/runtime.php'"
VerifyFile-->>Driver: returns Closure(CompiledFixture $fixture): void
Driver->>VerifyFile: $runtime($fixture)
VerifyFile->>UsePhp: "require $fixture->targetDir . '/Use.php'"
UsePhp-->>VerifyFile: populates $result, $a, $y... in closure scope
VerifyFile->>Assert: Assert::assertSame(...)
Assert-->>Driver: pass / throws on failure
Driver->>Driver: "$fixture->cleanup() [in finally]"
Reviews (1): Last reviewed commit: "test: make compile-fixture verify files ..." | Re-trigger Greptile
Each executable verify file under test/fixture/compile/*/verify/ relied on an implicit, untyped $fixture variable being in the enclosing test method's scope at the point of
require. The dependency was invisible from the file, untyped, and enforced only by a docblock convention across 26 driver methods.Each verify file now returns a
function (CompiledFixture $fixture): voidthat runs its assertions when invoked, and each driver calls it explicitly:The fixture dependency is now an explicit typed parameter. Behavior is unchanged: the inner
require $fixture->targetDir . '/Use.php'still runs in the closure scope (so locals like $result are produced as before), assertion failures still propagate through the invocation, and the try/finally still cleans up the temp dir.Also drop the decorative
echo "OK\n"lines from the 11 files that had them: stdout is never inspected, so theAssert::calls already signal pass/fail.