8000 Provide current file as file path · symfony/symfony@d5302cb · GitHub
[go: up one dir, main page]

Skip to content

Commit d5302cb

Browse files
greg0irenicolas-grekas
authored andcommitted
Provide current file as file path
1 parent abeee5f commit d5302cb

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,13 @@ public static function collectDeprecations($outputFile)
104104
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
105105
}
106106

107-
$trace = debug_backtrace();
108107
$filesStack = [];
109-
foreach ($trace as $line) {
110-
if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
108+
foreach (debug_backtrace() as $frame) {
109+
if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
111110
continue;
112111
}
113112

114-
if (isset($line['file'])) {
115-
$filesStack[] = $line['file'];
116-
}
113+
$filesStack[] = $frame['file'];
117114
}
118115

119116
$deprecations[] = [error_reporting(), $msg, $file, $filesStack];

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,6 @@ public function isMuted()
165165
return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
166166
}
167167

168-
private function getOriginalFilesStack(): array
169-
{
170-
if (null === $this->originalFilesStack) {
171-
$this->originalFilesStack = [];
172-
foreach ($this->trace as $line) {
173-
if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
174-
continue;
175-
}
176-
if (!isset($line['file'])) {
177-
continue;
178-
}
179-
$this->originalFilesStack[] = $line['file'];
180-
}
181-
}
182-
183-
return $this->originalFilesStack;
184-
}
185-
186168
/**
187169
* Tells whether both the calling package and the called package are vendor
188170
* packages.
@@ -224,6 +206,22 @@ public function getType()
224206
return self::TYPE_DIRECT;
225207
}
226208

209+
private function getOriginalFilesStack(): array
210+
{
211+
if (null === $this->originalFilesStack) {
212+
$this->originalFilesStack = [];
213+
foreach ($this->trace as $frame) {
214+
if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
215+
continue;
216+
}
217+
218+
$this->originalFilesStack[] = $frame['file'];
219+
}
220+
}
221+
222+
return $this->originalFilesStack;
223+
}
224+
227225
/**
228226
* getPathType() should always be called prior to calling this method.
229227
*

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function providerGetTypeDetectsSelf(): array
157157
}
158158

159159
return [
160-
'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', ''],
160+
'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', __FILE__],
161161
'nonexistent_file' => [Deprecation::TYPE_UNDETERMINED, '', 'MyClass1', 'dummy_vendor_path'],
162162
'serialized_trace_with_nonexistent_triggering_file' => [
163163
Deprecation::TYPE_UNDETERMINED,

0 commit comments

Comments
 (0)
0