Php unit10 (#124) - #1
Closed
javiermarinros wants to merge 20 commits into
Closed
Conversation
javiermarinros
commented
Sep 7, 2026
- Static PHPUnit providers
- Limit PHP upgrades till new PHP version is tested
- Upgrade PHPUnit config schema
* Static PHPUnit providers * Limit PHP upgrades till new PHP version is tested * Upgrade PHPUnit config schema
… is deprecated (neonxp#123)
* Correct average typo * Update to PHP CS FIxer V3.21
* Correct average typo * Update to PHP CS FIxer V3.21 * Update available functions
* PHPCSFixer V3.23 * Run PHPCSFixer
Fix typo Paretheses -> Parentheses
…#134) * Update tests with log using base parameter * Ensure base parameter is allowed for log function
Replace the wrong method name `calculate()` with `execute()`
* Update to PHPStan 2.0 * Update to PHPUnit 12 * Remove prefer-lowest from test config * Drop 8.0 testing due to PHPUnit issues
* Update to PHPStan 2.0 * Update to PHPUnit 12 * Remove prefer-lowest from test config * Drop 8.0 testing due to PHPUnit issues * Update addOperator docs * trying to fix PHPUnit failures that work locally
Arithmetic and ordering operators hand their operands straight to PHP, so
a value that is not a number leaks a raw \TypeError out of the library
("Unsupported operand types: string / string") instead of one of its own
NXP\Exception\* types, and there is no supported way to say what such a
value should mean short of re-registering every arithmetic operator.
setNonNumericHandler() takes a callable($value, $operator) whose return
value is used in place of the original operand. It is applied to the
operators that require a number (+, -, *, /, %, ^, uNeg, uPos, >, >=, <
and <=), including the ones redefined by setDivisionByZeroIsZero() and
useBCMath(). Operators with defined string or boolean semantics (==, !=,
&&, || and !) are left untouched, as are numeric, null and boolean values.
Without a handler the behaviour is unchanged, which the existing suite and
the new testNonNumericWithoutHandler cases assert.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EWvvUoaHC1SaNQ23nVrCk
Two cases where installing a handler changed results that were already meaningful without one, breaking the promise that the handler only affects values that have no sensible numeric reading: Arrays are a supported variable type, accepted by defaultVarValidation and used by avg(), min() and max(), and PHP gives + a defined meaning for them. "[1, 2] + [3, 4]" returned the array union but 0 once any handler was set, and the handler was invoked with an array in a parameter documented as a scalar. Arrays now short circuit in normalizeOperand along with numeric, null and boolean values. The ordering operators normalized both operands unconditionally, so "'apple' < 'banana'" flipped from true to false once a handler was set, while == and != deliberately keep their strcmp semantics. Comparing two non-numeric values is now left alone, and the handler only applies when the other side is a number, which is the case this feature is about: PHP would otherwise compare that number as a string, so "rating > 1" still resolves through the handler. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EWvvUoaHC1SaNQ23nVrCk
Modulo by zero leaked PHP's raw \DivisionByZeroError out of the library instead of NXP\Exception\DivisionByZeroException, and setDivisionByZeroIsZero() did not cover %, so "10 % 0" threw a PHP Error that callers catching MathExecutorException could not catch and that setDivisionByZeroIsZero() could not turn off. useBCMath()'s bcmod() had the same behaviour. % now mirrors / in all three places: it throws the library's exception, setDivisionByZeroIsZero() registers it alongside /, and the BCMath variant checks the divisor before calling bcmod(). This is the one behaviour change in this branch for callers that set no non-numeric handler: "10 % 0" throws DivisionByZeroException where it previously threw \DivisionByZeroError. Operands that are non-numeric without a handler are unaffected, because 0 == 'SC' is false on PHP 8, so they still reach the operator and raise the same \TypeError as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EWvvUoaHC1SaNQ23nVrCk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.