Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Workflow] Catch error when trying to get an uninitialized marking #46008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ public function getMarking($subject): Marking
throw new LogicException(sprintf('The method "%s::%s()" does not exist.', \get_class($subject), $method));
}

$marking = $subject->{$method}();
$marking = null;
try {
$marking = $subject->{$method}();
} catch (\Error $e) {
$unInitializedPropertyMassage = sprintf('Typed property %s::$%s must not be accessed before initialization', get_debug_type($subject), $this->property);
if ($e->getMessage() !== $unInitializedPropertyMassage) {
throw $e;
}
}

if (null === $marking) {
return new Marking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ public function testGetMarkingWithValueObject()
$this->assertSame('first_place', (string) $subject->getMarking());
}

/**
* @requires PHP 7.4
*/
public function testGetMarkingWithUninitializedProperty()
{
$subject = new SubjectWithType();

$markingStore = new MethodMarkingStore(true);

$marking = $markingStore->getMarking($subject);

$this->assertInstanceOf(Marking::class, $marking);
$this->assertCount(0, $marking->getPlaces());
}

/**
* @requires PHP 7.4
*/
public function testGetMarkingWithUninitializedProperty2()
{
$subject = new SubjectWithType();

$markingStore = new MethodMarkingStore(true, 'marking2');

$this->expectException(\Error::class);
$this->expectExceptionMessage('Typed property Symfony\Component\Workflow\Tests\MarkingStore\SubjectWithType::$marking must not be accessed before initialization');

$markingStore->getMarking($subject);
}

private function createValueObject(string $markingValue)
{
return new class($markingValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Workflow\Tests\MarkingStore;
lyrixx marked this conversation as resolved.
Show resolved Hide resolved

class SubjectWithType
{
private string $marking;

public function getMarking(): string
{
return $this->marking;
}

public function setMarking(string $type): void
{
$this->marking = $type;
}

public function getMarking2(): string
{
// Typo made on purpose!
return $this->marking;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.