Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In callback there is no "file" in trace #5822

Open
wants to merge 4 commits into
base: 11.1
Choose a base branch
from

Conversation

DarkSide666
Copy link

In callback there is no "file" in trace.

For example, trace will look like

    [0] => Array
        (
            [file] => C:\wamp\www\atk4\validate\vendor\vlucas\valitron\src\Valitron\Validator.php
            [line] => 760
            [function] => strtotime
        )
    [1] => Array
        (
            [function] => validateDate
            [class] => Valitron\Validator
            [type] => ->
        )
    [2] => Array
        (
            [file] => C:\wamp\www\atk4\validate\vendor\vlucas\valitron\src\Valitron\Validator.php
            [line] => 1251
            [function] => call_user_func
        )
   ...

and [1] element has only function, class and type attributes, but no file and line.

@sebastianbergmann
Copy link
Owner

Thank you for your pull request.

Please include a minimal, self-contained, reproducing test case that shows the problem you are aiming to solve.

Also note that pull requests for bug fixes should not target main but the oldest release branch that still receives bug fixes where the problem exists.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Apr 20, 2024
Copy link

codecov bot commented Apr 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.86%. Comparing base (d724b7f) to head (d2a4b10).

Additional details and impacted files
@@            Coverage Diff            @@
##               11.1    #5822   +/-   ##
=========================================
  Coverage     89.86%   89.86%           
- Complexity     6560     6562    +2     
=========================================
  Files           693      693           
  Lines         19850    19850           
=========================================
  Hits          17838    17838           
  Misses         2012     2012           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DarkSide666 DarkSide666 changed the base branch from main to 11.1 April 22, 2024 10:56
@DarkSide666 DarkSide666 marked this pull request as draft April 22, 2024 13:19
@DarkSide666
Copy link
Author

DarkSide666 commented Apr 23, 2024

I've rebased this PR to 11.1 branch. In versions 10.x this is not relevant.

Speaking about tests I'm really not sure how to write proper one for phpunit.
This simple test class shows that in case debug_backtrace is called from callback method, then it do not contain file and line array keys. So asserting that file and line keys are always present in backtrace in phpunit ErrorHandler class is wrong and will throw error in such cases.

class MyTest extends TestCase
{
    public function testDebugBacktrace()
    {
        $result = $this->callUserFuncExample();

        // Check if the debug_backtrace has been generated
        $this->assertNotNull($result);

        // Check if the first element of the debug_backtrace is missing file and line elements
        $this->assertArrayHasKey('function', $result[0]);
        $this->assertArrayNotHasKey('file', $result[0]);
        $this->assertArrayNotHasKey('line', $result[0]);
    }

    private function callUserFuncExample()
    {
        return call_user_func([$this, 'exampleCallback']);
    }

    private function exampleCallback()
    {
        return debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
    }
}

Can anyone please help me to write test for this for phpunit lib ?

@DarkSide666
Copy link
Author

Added testcase which after fix will no more fail, but before fix fails.

@DarkSide666 DarkSide666 marked this pull request as ready for review April 23, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants