Skip to content

Commit

Permalink
fix: Ensure the evaluated expression fails on warning (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Jan 16, 2025
1 parent 63b77b5 commit 09f8324
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Generator/Resolver/Value/Chainable/EvaluatedValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Nelmio\Alice\Generator\Resolver\Value\Chainable;

use ErrorException;
use Nelmio\Alice\Definition\Value\EvaluatedValue;
use Nelmio\Alice\Definition\ValueInterface;
use Nelmio\Alice\FixtureInterface;
Expand All @@ -25,6 +26,9 @@
use Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueExceptionFactory;
use Nelmio\Alice\Throwable\Exception\NoValueForCurrentException;
use Throwable;
use function error_reporting;
use function restore_error_handler;
use function set_error_handler;

final class EvaluatedValueResolver implements ChainableValueResolverInterface
{
Expand Down Expand Up @@ -75,9 +79,21 @@ public function resolve(
};

try {
set_error_handler(function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
$suppressed = !(error_reporting() & $errorNumber);

if ($suppressed) {
return false;
}

throw new ErrorException($errorString, 0, $errorNumber, $errorFile, $errorLine);
});

$evaluatedExpression = $evaluateExpression($expression);
} catch (Throwable $throwable) {
throw UnresolvableValueExceptionFactory::createForCouldNotEvaluateExpression($value, 0, $throwable);
} finally {
restore_error_handler();
}

return new ResolvedValueWithFixtureSet($evaluatedExpression, $fixtureSet);
Expand Down

0 comments on commit 09f8324

Please sign in to comment.