-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from reinfi/fix-access-to-unknown-index
fix access of undefined array index file
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\DeveloperTools\EventLogging; | ||
|
||
use Laminas\DeveloperTools\EventLogging\EventContextProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function array_map; | ||
|
||
/** @covers \Laminas\DeveloperTools\EventLogging\EventContextProvider */ | ||
class EventContextProviderTest extends TestCase | ||
{ | ||
public function testEventTriggerFileDetectsEmptyFileLocationWhenStackFrameIsInPhpItself(): void | ||
{ | ||
self::assertSame( | ||
[ | ||
'stack frame on this file: EventLogging/EventContextProviderTest.php', | ||
'stack frame in php core: ', | ||
'stack frame on this file: EventLogging/EventContextProviderTest.php', | ||
], | ||
// Important: `array_map()` needed here, as it produces a stack frame without "file" location | ||
array_map( | ||
[$this, 'callEventContextProviderWithStackTraceNestingLevelAndName'], | ||
[ | ||
'stack frame on this file', | ||
'stack frame in php core', | ||
'stack frame on this file', | ||
], | ||
[ | ||
3, | ||
4, | ||
5, | ||
] | ||
), | ||
'trigger file should be empty because user function calls do not refer to a file' | ||
); | ||
} | ||
|
||
private function callEventContextProviderWithStackTraceNestingLevelAndName(string $name, int $level): string | ||
{ | ||
if ($level > 0) { | ||
return $this->callEventContextProviderWithStackTraceNestingLevelAndName($name, $level - 1); | ||
} | ||
|
||
return $name . ': ' . (new EventContextProvider())->getEventTriggerFile(); | ||
} | ||
} |