8000 bug #35597 [PHPunit bridge] Provide current file as file path (greg0ire) · symfony/symfony@b6acfae · GitHub
[go: up one dir, main page]

Skip to content

Commit b6acfae

Browse files
bug #35597 [PHPunit bridge] Provide current file as file path (greg0ire)
This PR was merged into the 4.4 branch. Discussion ---------- [PHPunit bridge] Provide current file as file path I failed to apply perfectly this comment: #33820 (comment) It should fix one failing test in the bridge. | Q | A | ------------- | --- | Branch? |4.4 | Bug fix? | not for the end user | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- d5302cb Provide current file as file path
2 parents abeee5f + d5302cb commit b6acfae

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