Skip to content

Commit 511d492

Browse files
Merge branch '11.5'
2 parents d81cfde + 60d34d3 commit 511d492

File tree

27 files changed

+357
-47
lines changed

27 files changed

+357
-47
lines changed

src/Event/Emitter/DispatchingEmitter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,12 @@ public function testTriggeredPhpDeprecation(Code\Test $test, string $message, st
716716
* @param non-empty-string $message
717717
* @param non-empty-string $file
718718
* @param positive-int $line
719+
* @param non-empty-string $stackTrace
719720
*
720721
* @throws InvalidArgumentException
721722
* @throws UnknownEventTypeException
722723
*/
723-
public function testTriggeredDeprecation(Code\Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger): void
724+
public function testTriggeredDeprecation(Code\Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger, string $stackTrace): void
724725
{
725726
$this->dispatcher->dispatch(
726727
new Test\DeprecationTriggered(
@@ -733,6 +734,7 @@ public function testTriggeredDeprecation(Code\Test $test, string $message, strin
733734
$ignoredByBaseline,
734735
$ignoredByTest,
735736
$trigger,
737+
$stackTrace,
736738
),
737739
);
738740
}

src/Event/Emitter/Emitter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ public function testTriggeredPhpDeprecation(Code\Test $test, string $message, st
166166
* @param non-empty-string $message
167167
* @param non-empty-string $file
168168
* @param positive-int $line
169+
* @param non-empty-string $stackTrace
169170
*/
170-
public function testTriggeredDeprecation(Code\Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger): void;
171+
public function testTriggeredDeprecation(Code\Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger, string $stackTrace): void;
171172

172173
/**
173174
* @param non-empty-string $message

src/Event/Events/Test/Issue/DeprecationTriggered.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@
4646
private bool $ignoredByTest;
4747
private IssueTrigger $trigger;
4848

49+
/**
50+
* @var non-empty-string
51+
*/
52+
private string $stackTrace;
53+
4954
/**
5055
* @param non-empty-string $message
5156
* @param non-empty-string $file
5257
* @param positive-int $line
58+
* @param non-empty-string $stackTrace
5359
*/
54-
public function __construct(Telemetry\Info $telemetryInfo, Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger)
60+
public function __construct(Telemetry\Info $telemetryInfo, Test $test, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, bool $ignoredByTest, IssueTrigger $trigger, string $stackTrace)
5561
{
5662
$this->telemetryInfo = $telemetryInfo;
5763
$this->test = $test;
@@ -62,6 +68,7 @@ public function __construct(Telemetry\Info $telemetryInfo, Test $test, string $m
6268
$this->ignoredByBaseline = $ignoredByBaseline;
6369
$this->ignoredByTest = $ignoredByTest;
6470
$this->trigger = $trigger;
71+
$this->stackTrace = $stackTrace;
6572
}
6673

6774
public function telemetryInfo(): Telemetry\Info
@@ -118,6 +125,14 @@ public function trigger(): IssueTrigger
118125
return $this->trigger;
119126
}
120127

128+
/**
129+
* @return non-empty-string
130+
*/
131+
public function stackTrace(): string
132+
{
133+
return $this->stackTrace;
134+
}
135+
121136
public function asString(): string
122137
{
123138
$message = $this->message;

src/Event/Value/ThrowableBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function from(\Throwable $t): Throwable
3737
$t::class,
3838
$t->getMessage(),
3939
ThrowableToStringMapper::map($t),
40-
Filter::getFilteredStacktrace($t, false),
40+
Filter::stackTraceFromThrowableAsString($t, false),
4141
$previous,
4242
);
4343
}

src/Framework/Constraint/Exception/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function failureDescription(mixed $other): string
6868

6969
if ($other instanceof Throwable) {
7070
$message = '. Message was: "' . $other->getMessage() . '" at'
71-
. "\n" . Filter::getFilteredStacktrace($other);
71+
. "\n" . Filter::stackTraceFromThrowableAsString($other);
7272
}
7373

7474
return sprintf(

src/Framework/TestSuite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,15 @@ private function throwableToString(Throwable $t): string
589589
return sprintf(
590590
"%s\n%s",
591591
$message,
592-
Filter::getFilteredStacktrace($t),
592+
Filter::stackTraceFromThrowableAsString($t),
593593
);
594594
}
595595

596596
return sprintf(
597597
"%s: %s\n%s",
598598
$t::class,
599599
$message,
600-
Filter::getFilteredStacktrace($t),
600+
Filter::stackTraceFromThrowableAsString($t),
601601
);
602602
}
603603

src/Runner/ErrorHandler.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use function error_reporting;
3333
use function restore_error_handler;
3434
use function set_error_handler;
35+
use function sprintf;
3536
use PHPUnit\Event;
3637
use PHPUnit\Event\Code\IssueTrigger\IssueTrigger;
3738
use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException;
@@ -175,6 +176,7 @@ public function __invoke(int $errorNumber, string $errorString, string $errorFil
175176
$ignoredByBaseline,
176177
$ignoredByTest,
177178
$this->trigger($test, true),
179+
$this->stackTrace(),
178180
);
179181

180182
break;
@@ -353,7 +355,7 @@ private function guessDeprecationFrame(): ?array
353355
}
354356

355357
/**
356-
* @return list<array{file: string, line: int, class?: class-string, function?: string, type: string}>
358+
* @return list<array{file: string, line: ?int, class?: class-string, function?: string, type: string}>
357359
*/
358360
private function errorStackTrace(): array
359361
{
@@ -388,4 +390,27 @@ private function frameIsMethod(array $frame, array $method): bool
388390
isset($frame['function']) &&
389391
$frame['function'] === $method['methodName'];
390392
}
393+
394+
/**
395+
* @return non-empty-string
396+
*/
397+
private function stackTrace(): string
398+
{
399+
$buffer = '';
400+
$excludeList = new ExcludeList(true);
401+
402+
foreach ($this->errorStackTrace() as $frame) {
403+
if ($excludeList->isExcluded($frame['file'])) {
404+
continue;
405+
}
406+
407+
$buffer .= sprintf(
408+
"%s:%s\n",
409+
$frame['file'],
410+
$frame['line'] ?? '?',
411+
);
412+
}
413+
414+
return $buffer;
415+
}
391416
}

src/Runner/TestResult/Collector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
363363
$event->line(),
364364
$event->message(),
365365
$event->test(),
366+
$event->stackTrace(),
366367
);
367368

368369
return;

src/Runner/TestResult/Facade.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
*/
1010
namespace PHPUnit\TestRunner\TestResult;
1111

12+
use function str_contains;
1213
use PHPUnit\Event\EventFacadeIsSealedException;
1314
use PHPUnit\Event\Facade as EventFacade;
1415
use PHPUnit\Event\UnknownSubscriberTypeException;
16+
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollectorFacade;
1517
use PHPUnit\TestRunner\IssueFilter;
18+
use PHPUnit\TextUI\Configuration\Configuration;
1619
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
1720

1821
/**
@@ -67,7 +70,7 @@ public static function shouldStop(): bool
6770
return true;
6871
}
6972

70-
if ($configuration->stopOnDeprecation() && $collector->hasDeprecations()) {
73+
if (self::stopOnDeprecation($configuration)) {
7174
return true;
7275
}
7376

@@ -103,4 +106,25 @@ private static function collector(): Collector
103106

104107
return self::$collector;
105108
}
109+
110+
private static function stopOnDeprecation(Configuration $configuration): bool
111+
{
112+
if (!$configuration->stopOnDeprecation()) {
113+
return false;
114+
}
115+
116+
$deprecations = DeprecationCollectorFacade::deprecations();
117+
118+
if (!$configuration->hasSpecificDeprecationToStopOn()) {
119+
return $deprecations !== [];
120+
}
121+
122+
foreach ($deprecations as $deprecation) {
123+
if (str_contains($deprecation, $configuration->specificDeprecationToStopOn())) {
124+
return true;
125+
}
126+
}
127+
128+
return false;
129+
}
106130
}

src/Runner/TestResult/Issue.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,32 @@ final class Issue
3838
*/
3939
private array $triggeringTests;
4040

41+
/**
42+
* @var ?non-empty-string
43+
*/
44+
private ?string $stackTrace;
45+
4146
/**
4247
* @param non-empty-string $file
4348
* @param positive-int $line
4449
* @param non-empty-string $description
4550
*/
46-
public static function from(string $file, int $line, string $description, Test $triggeringTest): self
51+
public static function from(string $file, int $line, string $description, Test $triggeringTest, ?string $stackTrace = null): self
4752
{
48-
return new self($file, $line, $description, $triggeringTest);
53+
return new self($file, $line, $description, $triggeringTest, $stackTrace);
4954
}
5055

5156
/**
5257
* @param non-empty-string $file
5358
* @param positive-int $line
5459
* @param non-empty-string $description
5560
*/
56-
private function __construct(string $file, int $line, string $description, Test $triggeringTest)
61+
private function __construct(string $file, int $line, string $description, Test $triggeringTest, ?string $stackTrace)
5762
{
5863
$this->file = $file;
5964
$this->line = $line;
6065
$this->description = $description;
66+
$this->stackTrace = $stackTrace;
6167

6268
$this->triggeringTests = [
6369
$triggeringTest->id() => [
@@ -112,4 +118,20 @@ public function triggeringTests(): array
112118
{
113119
return $this->triggeringTests;
114120
}
121+
122+
/**
123+
* @phpstan-assert-if-true !null $this->stackTrace
124+
*/
125+
public function hasStackTrace(): bool
126+
{
127+
return $this->stackTrace !== null;
128+
}
129+
130+
/**
131+
* @return ?non-empty-string
132+
*/
133+
public function stackTrace(): ?string
134+
{
135+
return $this->stackTrace;
136+
}
115137
}

0 commit comments

Comments
 (0)