prevent reflection usages when classes do not exist

This commit is contained in:
Christian Flothmann 2021-06-19 21:27:24 +02:00
parent 769a05bdc5
commit 017b4b341c
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();