Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c06ea

Browse files
committed
bug #41751 [Messenger] prevent reflection usages when classes do not exist (xabbuh)
This PR was merged into the 5.2 branch. Discussion ---------- [Messenger] prevent reflection usages when classes do not exist | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41748 | License | MIT | Doc PR | Commits ------- 017b4b3 prevent reflection usages when classes do not exist
2 parents 769a05b + 017b4b3 commit 53c06ea

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/Messenger/Envelope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ private function resolveAlias(string $fqcn): string
127127
{
128128
static $resolved;
129129

130-
return $resolved[$fqcn] ?? ($resolved[$fqcn] = (new \ReflectionClass($fqcn))->getName());
130+
return $resolved[$fqcn] ?? ($resolved[$fqcn] = class_exists($fqcn) ? (new \ReflectionClass($fqcn))->getName() : $fqcn);
131131
}
132132
}

src/Symfony/Component/Messenger/Tests/EnvelopeTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public function testWithoutAll()
5555
$this->assertCount(1, $envelope->all(DelayStamp::class));
5656
}
5757

58+
public function testWithoutAllWithNonExistentStampClass()
59+
{
60+
$envelope = new Envelope(new DummyMessage('dummy'));
61+
62+
$this->assertInstanceOf(Envelope::class, $envelope->withoutAll(NonExistentStamp::class));
63+
}
64+
5865
public function testWithoutStampsOfType()
5966
{
6067
$envelope = new Envelope(new DummyMessage('dummy'), [
@@ -77,6 +84,13 @@ public function testWithoutStampsOfType()
7784
$this->assertEmpty($envelope5->all());
7885
}
7986

87+
public function testWithoutStampsOfTypeWithNonExistentStampClass()
88+
{
89+
$envelope = new Envelope(new DummyMessage('dummy'));
90+
91+
$this->assertInstanceOf(Envelope::class, $envelope->withoutStampsOfType(NonExistentStamp::class));
92+
}
93+
8094
public function testLast()
8195
{
8296
$receivedStamp = new ReceivedStamp('transport');
@@ -86,6 +100,13 @@ public function testLast()
86100
$this->assertNull($envelope->last(ValidationStamp::class));
87101
}
88102

103+
public function testLastWithNonExistentStampClass()
104+
{
105+
$envelope = new Envelope(new DummyMessage('dummy'));
106+
107+
$this->assertNull($envelope->last(NonExistentStamp::class));
108+
}
109+
89110
public function testAll()
90111
{
91112
$envelope = (new Envelope($dummy = new DummyMessage('dummy')))
@@ -100,6 +121,13 @@ public function testAll()
100121
$this->assertSame($validationStamp, $stamps[ValidationStamp::class][0]);
101122
}
102123

124+
public function testAllWithNonExistentStampClass()
125+
{
126+
$envelope = new Envelope(new DummyMessage('dummy'));
127+
128+
$this->assertSame([], $envelope->all(NonExistentStamp::class));
129+
}
130+
103131
public function testWrapWithMessage()
104132
{
105133
$message = new \stdClass();

0 commit comments

Comments
 (0)