Fix error when we use VO for the marking property

Fix Illegal offset type when we use ValueObject instead of string for
the marking property #28203 #22031
This commit is contained in:
FabienSalles 2019-11-08 12:00:48 +01:00
parent a1fc280bf2
commit 6570d5cbe2
2 changed files with 32 additions and 1 deletions

View File

@ -61,7 +61,7 @@ final class MethodMarkingStore implements MarkingStoreInterface
}
if ($this->singleState) {
$marking = [$marking => 1];
$marking = [(string) $marking => 1];
}
return new Marking($marking);

View File

@ -52,4 +52,35 @@ class MethodMarkingStoreTest extends TestCase
$this->assertEquals($marking, $marking2);
}
public function testGetMarkingWithValueObject()
{
$subject = new Subject($this->createValueObject('first_place'));
$markingStore = new MethodMarkingStore(true);
$marking = $markingStore->getMarking($subject);
$this->assertInstanceOf(Marking::class, $marking);
$this->assertCount(1, $marking->getPlaces());
$this->assertSame('first_place', (string) $subject->getMarking());
}
private function createValueObject(string $markingValue)
{
return new class($markingValue) {
/** @var string */
private $markingValue;
public function __construct(string $markingValue)
{
$this->markingValue = $markingValue;
}
public function __toString()
{
return $this->markingValue;
}
};
}
}