Skip to content

Commit a90648c

Browse files
bug #46008 [Workflow] Catch error when trying to get an uninitialized marking (lyrixx)
This PR was merged into the 4.4 branch. Discussion ---------- [Workflow] Catch error when trying to get an uninitialized marking | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44213 | License | MIT | Doc PR | Commits ------- 141320d [Workflow] Catch error when trying to get an uninitialized marking
2 parents 58085fb + 141320d commit a90648c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public function getMarking($subject): Marking
5454
throw new LogicException(sprintf('The method "%s::%s()" does not exist.', \get_class($subject), $method));
5555
}
5656

57-
$marking = $subject->{$method}();
57+
$marking = null;
58+
try {
59+
$marking = $subject->{$method}();
60+
} catch (\Error $e) {
61+
$unInitializedPropertyMassage = sprintf('Typed property %s::$%s must not be accessed before initialization', get_debug_type($subject), $this->property);
62+
if ($e->getMessage() !== $unInitializedPropertyMassage) {
63+
throw $e;
64+
}
65+
}
5866

5967
if (null === $marking) {
6068
return new Marking();

src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,36 @@ public function testGetMarkingWithValueObject()
8787
$this->assertSame('first_place', (string) $subject->getMarking());
8888
}
8989

90+
/**
91+
* @requires PHP 7.4
92+
*/
93+
public function testGetMarkingWithUninitializedProperty()
94+
{
95+
$subject = new SubjectWithType();
96+
97+
$markingStore = new MethodMarkingStore(true);
98+
99+
$marking = $markingStore->getMarking($subject);
100+
101+
$this->assertInstanceOf(Marking::class, $marking);
102+
$this->assertCount(0, $marking->getPlaces());
103+
}
104+
105+
/**
106+
* @requires PHP 7.4
107+
*/
108+
public function testGetMarkingWithUninitializedProperty2()
109+
{
110+
$subject = new SubjectWithType();
111+
112+
$markingStore = new MethodMarkingStore(true, 'marking2');
113+
114+
$this->expectException(\Error::class);
115+
$this->expectExceptionMessage('Typed property Symfony\Component\Workflow\Tests\MarkingStore\SubjectWithType::$marking must not be accessed before initialization');
116+
117+
$markingStore->getMarking($subject);
118+
}
119+
90120
private function createValueObject(string $markingValue)
91121
{
92122
return new class($markingValue) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy