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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Runner/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use const E_WARNING;
use function array_keys;
use function array_values;
use function assert;
use function debug_backtrace;
use function error_reporting;
use function restore_error_handler;
Expand Down Expand Up @@ -254,19 +253,20 @@ private function trigger(TestMethod $test, bool $filterTrigger): IssueTrigger

$trace = $this->filteredStackTrace($filterTrigger);

assert(isset($trace[0]['file']));
assert(isset($trace[1]['file']));

$triggeredInFirstPartyCode = false;
$triggerCalledFromFirstPartyCode = false;

if ($trace[0]['file'] === $test->file() ||
$this->sourceFilter->includes($this->source, $trace[0]['file'])) {
if (isset($trace[0]['file']) && (
$trace[0]['file'] === $test->file() ||
$this->sourceFilter->includes($this->source, $trace[0]['file'])
)) {
$triggeredInFirstPartyCode = true;
}

if ($trace[1]['file'] === $test->file() ||
$this->sourceFilter->includes($this->source, $trace[1]['file'])) {
if (isset($trace[1]['file']) && (
$trace[1]['file'] === $test->file() ||
$this->sourceFilter->includes($this->source, $trace[1]['file'])
)) {
$triggerCalledFromFirstPartyCode = true;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/5822.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/pull/5592
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/5822/phpunit.xml';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s
Configuration: %s

D 1 / 1 (100%)

Time: %s, Memory: %s

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.
15 changes: 15 additions & 0 deletions tests/end-to-end/regression/5822/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
4 changes: 4 additions & 0 deletions tests/end-to-end/regression/5822/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
34 changes: 34 additions & 0 deletions tests/end-to-end/regression/5822/tests/Issue5822Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5822;

use const E_USER_DEPRECATED;
use function call_user_func;
use function trigger_error;
use PHPUnit\Framework\TestCase;

class Issue5822Test extends TestCase
{
public function testDebugBacktrace(): void
{
$this->callUserFuncExample();
$this->assertTrue(true);
}

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

private function exampleCallback(): void
{
trigger_error('My Deprecation Error', E_USER_DEPRECATED);
}
}