Skip to content

Respect Warning settings before calling custom handler - #1393

Draft
spawnia wants to merge 7 commits into
masterfrom
respect-warning-settings-before-custom-handler
Draft

Respect Warning settings before calling custom handler#1393
spawnia wants to merge 7 commits into
masterfrom
respect-warning-settings-before-custom-handler

Conversation

@spawnia

@spawnia spawnia commented Jun 5, 2023

Copy link
Copy Markdown
Collaborator

Check whether the warning is enabled before invoking the custom warning handler, matching the behavior for the default trigger_error handler.

spawnia and others added 5 commits June 5, 2023 08:58

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: e920ef9 Previous: 203d11e Ratio
DeferredBench::benchManyNestedDeferreds 21.952 ms 12.472 ms 1.76

This comment was automatically generated by workflow using github-action-benchmark.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the library’s warning emission logic so custom warning handlers respect Warning::enable() / Warning::suppress() settings, matching the default trigger_error behavior.

Changes:

  • Gate custom warning handler invocation behind the same enableWarnings bitmask check used for trigger_error.
  • Refactor warning emission to centralize “should warn” logic and streamline warnOnce() behavior.
  • Update the lazy schema executor test to assert warning handling behavior (currently needs fixes to actually execute).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/Executor/ExecutorLazySchemaTest.php Adds assertions for warning interception via a custom warning handler during lazy schema execution.
src/Error/Warning.php Ensures warnings are only emitted/handled when enabled; refactors warnOnce()/warn() and introduces shouldWarn().
CHANGELOG.md Documents the behavior change for custom warning handlers respecting suppression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Error/Warning.php
Comment on lines 59 to 63
public static function suppress($suppress = true): void
{
if ($suppress === true) {
self::$enableWarnings = 0;
self::$enableWarnings = self::NONE;
} elseif ($suppress === false) {
Comment thread src/Error/Warning.php
Comment on lines 86 to +90
{
if ($enable === true) {
self::$enableWarnings = self::ALL;
} elseif ($enable === false) {
self::$enableWarnings = 0;
self::$enableWarnings = self::NONE;
Comment on lines +132 to 136
$warnings = [];
Warning::setWarningHandler(function ($warning) use (&$warnings): void {
$warnings[] = $warning;
});
Warning::enable(Warning::WARNING_FULL_SCHEMA_SCAN);

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

tests/Executor/ExecutorLazySchemaTest.php:140

  • markTestIncomplete() aborts the test, so the new assertions and $warnings verification below it are unreachable. It also prevents resetting the global warning handler, which can leak into other tests.
        Warning::enable(Warning::WARNING_FULL_SCHEMA_SCAN);
        $result = Executor::execute($schema, Parser::parse($query));
        self::markTestIncomplete('No longer works with PHPUnit 10, reintroduce with https://github.com/webonyx/graphql-php/pull/1393');
        self::assertEquals($expected, $result);

src/Error/Warning.php:62

  • The suppress() docblock says it has no effect when a custom warning handler is set, but this PR changes behavior to respect suppression/enablement before invoking the custom handler. The doc comment should be updated to match.
    public static function suppress($suppress = true): void
    {
        if ($suppress === true) {
            self::$enableWarnings = self::NONE;

src/Error/Warning.php:90

  • The enable() docblock says it has no effect when a custom warning handler is set, but this PR makes enablement affect custom handlers too. Update the doc comment so it matches the new behavior.
    public static function enable($enable = true): void
    {
        if ($enable === true) {
            self::$enableWarnings = self::ALL;
        } elseif ($enable === false) {
            self::$enableWarnings = self::NONE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants