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
-------

017b4b341c prevent reflection usages when classes do not exist
This commit is contained in:
Christian Flothmann 2021-06-21 08:56:53 +02:00
commit 53c06ea546
2 changed files with 29 additions and 1 deletions

View File

@ -127,6 +127,6 @@ final class Envelope
{
static $resolved;
return $resolved[$fqcn] ?? ($resolved[$fqcn] = (new \ReflectionClass($fqcn))->getName());
return $resolved[$fqcn] ?? ($resolved[$fqcn] = class_exists($fqcn) ? (new \ReflectionClass($fqcn))->getName() : $fqcn);
}
}

View File

@ -55,6 +55,13 @@ class EnvelopeTest extends TestCase
$this->assertCount(1, $envelope->all(DelayStamp::class));
}
public function testWithoutAllWithNonExistentStampClass()
{
$envelope = new Envelope(new DummyMessage('dummy'));
$this->assertInstanceOf(Envelope::class, $envelope->withoutAll(NonExistentStamp::class));
}
public function testWithoutStampsOfType()
{
$envelope = new Envelope(new DummyMessage('dummy'), [
@ -77,6 +84,13 @@ class EnvelopeTest extends TestCase
$this->assertEmpty($envelope5->all());
}
public function testWithoutStampsOfTypeWithNonExistentStampClass()
{
$envelope = new Envelope(new DummyMessage('dummy'));
$this->assertInstanceOf(Envelope::class, $envelope->withoutStampsOfType(NonExistentStamp::class));
}
public function testLast()
{
$receivedStamp = new ReceivedStamp('transport');
@ -86,6 +100,13 @@ class EnvelopeTest extends TestCase
$this->assertNull($envelope->last(ValidationStamp::class));
}
public function testLastWithNonExistentStampClass()
{
$envelope = new Envelope(new DummyMessage('dummy'));
$this->assertNull($envelope->last(NonExistentStamp::class));
}
public function testAll()
{
$envelope = (new Envelope($dummy = new DummyMessage('dummy')))
@ -100,6 +121,13 @@ class EnvelopeTest extends TestCase
$this->assertSame($validationStamp, $stamps[ValidationStamp::class][0]);
}
public function testAllWithNonExistentStampClass()
{
$envelope = new Envelope(new DummyMessage('dummy'));
$this->assertSame([], $envelope->all(NonExistentStamp::class));
}
public function testWrapWithMessage()
{
$message = new \stdClass();