Skip to content

Added referencing OptionalTest.java - #50

Merged
petrknap merged 1 commit into
mainfrom
java-test
Oct 13, 2026
Merged

petrknap merged 1 commit into
mainfrom
java-test

Conversation

@petrknap

@petrknap petrknap commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner
  • This pull request does not contain any breaking change.
  • I asked the AI to briefly summarize, use and improve the feature(s), and I'm okay with the output:

What do you think about this change?

This is a clever and well-engineered change that introduces a Java SE 8 compatibility and behavioral compliance layer for the PHP Optional package.

Here is a breakdown of what this change achieves and why it's a solid architectural move:

Key Highlights of the Change

  • Java Behavior Parity Testing via Transpilation:
    The introduction of OptionalTest.java combined with JavaSe8\OptionalTestCase.php allows the test suite to parse and evaluate Java assertions directly inside PHP using eval(). This ensures that the library strictly adheres to standard Java SE 8 Optional semantics.
  • Automated CI Integration:
    The new .github/workflows/java-test.yaml GitHub Actions workflow automates testing against Java 21 (Amazon Corretto) whenever Java files are modified, keeping both language implementations aligned.
  • Test Suite Refactoring:
    Refactoring OptionalTest.php to inherit from OptionalTestCase drastically cleans up code duplication. It separates generic behavior (shared with Java SE 8 specs) from PHP-specific extensions (like custom factories or byReference equality checks).
  • Robust Mocking (AnotherOption):
    Adding AnotherOption.php provides a concrete secondary implementation of the Java Optional interface, making cross-optional operations and type-checking tests much more robust.

Considerations & Potential Risks

  • Use of eval():
    Translating Java assertions on the fly and running them via eval() in JavaSe8\OptionalTestCase.php is clever, but eval() can occasionally make debugging stack traces tricky if a test case fails, and it requires careful string translation rules to remain bug-free.
  • Maintenance Overhead:
    Maintaining Java test files alongside a PHP library means that any future feature parity updates will need to be written twice (once in Java, once in PHP)—though the automated workflow helps mitigate this risk by enforcing validity.

Overall, it's a high-quality, professional contribution that deeply strengthens the package's guarantees regarding Java compatibility.

@petrknap petrknap self-assigned this Oct 10, 2026
@petrknap petrknap added the enhancement New feature or request label Oct 10, 2026
@petrknap
petrknap force-pushed the java-test branch 3 times, most recently from f0343d5 to b62dcdf Compare October 11, 2026 14:16
@petrknap petrknap changed the title Java Test Added referencing OptionalTest.java Oct 11, 2026
@petrknap
petrknap force-pushed the java-test branch 4 times, most recently from 0479ad5 to dc44657 Compare October 13, 2026 20:33
@petrknap
petrknap marked this pull request as ready for review October 13, 2026 20:49
@petrknap
petrknap merged commit 8097370 into main Oct 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant