Skip to content

Implemented JavaSe11\Optional - #62

Merged
petrknap merged 1 commit into
mainfrom
java-bump
Oct 30, 2026
Merged

petrknap merged 1 commit into
mainfrom
java-bump

Conversation

@petrknap

@petrknap petrknap commented Oct 30, 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:

This pull request introduces support for Java SE 11 Optional::isEmpty() into the PHP implementation. It adds the corresponding interface specification, updates the base Optional class, adds comprehensive Java-to-PHP test coverage for Java SE 11, and updates documentation (README.md and GitHub actions matrix).


Detailed Code & Diff Review

1. Core Feature (src/JavaSe11/Optional.php & src/Optional.php)

  • New Interface: Created PetrKnap\Optional\JavaSe11\Optional which extends JavaSe10\Optional and introduces isEmpty(): bool.
  • Class Updates:
  • PetrKnap\Optional\Optional now implements JavaSe11\Optional instead of JavaSe10\Optional.
  • Implements isEmpty(): bool returning true when $this->value === null, perfectly aligning with Java's behavior.
  • Includes a helpful developer note: @note do not use it internally, compare self::$value to null directly.

2. Testing & Parity (tests/JavaSe11/)

  • Java Test File (tests/JavaSe11/OptionalTest.java): Added a new Java test checking that .isEmpty() returns false for present values and true for empty optional instances.
  • PHP Test Case Adapter (tests/JavaSe11/OptionalTestCase.php): Extends JavaSe10\OptionalTestCase and dynamically loads the Java SE 11 test lines to ensure the PHP implementation matches Java semantics.
  • Test Hierarchy Update (tests/JavaSe16/OptionalTestCase.php): Correctly refactored the inheritance chain from JavaSe10 to JavaSe11 (JavaSe16 tests now properly inherit from JavaSe11\OptionalTestCase).

3. CI/CD & Documentation (.github/workflows/java-test.yaml & README.md)

  • GitHub Actions Matrix: Updated java-test.yaml to include a dedicated entry for se: 11 (lts: 11) to run validation tests.
  • README: Added JavaSe11/OptionalTest.java to the list of specifications explicitly checking and describing the feature set, keeping documentation aligned with the code changes.

Strengths & Best Practices

  • Strict Specification Alignment: Following the pattern of mirroring Java SE specifications (JavaSe8, JavaSe9, JavaSe10, and now JavaSe11) ensures high reliability and predictable behavior.
  • Automated Parity Tests: Reusing Java test assertions through reflection and automated translation strings (OptionalTestCase) guarantees that the PHP behavior will continue to match Java's standard library.
  • Clean Commit Scope: The changes are focused, well-structured, and touch only what is necessary to introduce isEmpty().

Recommendation

  • Status: Approved / Ready to Merge. The implementation is clean, properly tested, fully typed, and preserves backward compatibility while smoothly expanding Java API parity.

@petrknap petrknap self-assigned this Oct 30, 2026
@petrknap petrknap added the enhancement New feature or request label Oct 30, 2026
@petrknap
petrknap marked this pull request as ready for review October 30, 2026 17:28
@petrknap
petrknap merged commit b799daa into main Oct 30, 2026
7 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