-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workflow] Add support for storing the marking in a property
- Loading branch information
Showing
5 changed files
with
203 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/Symfony/Component/Workflow/Tests/MarkingStore/PropertiesMarkingStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?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; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore; | ||
|
||
class PropertiesMarkingStoreTest extends TestCase | ||
{ | ||
public function testGetSetMarkingWithMultipleState() | ||
{ | ||
$subject = new SubjectWithProperties(); | ||
$markingStore = new MethodMarkingStore(false); | ||
|
||
$marking = $markingStore->getMarking($subject); | ||
|
||
$this->assertCount(0, $marking->getPlaces()); | ||
|
||
$marking->mark('first_place'); | ||
|
||
$markingStore->setMarking($subject, $marking, ['foo' => 'bar']); | ||
|
||
$this->assertSame(['first_place' => 1], $subject->marking); | ||
|
||
$marking2 = $markingStore->getMarking($subject); | ||
|
||
$this->assertEquals($marking, $marking2); | ||
} | ||
|
||
public function testGetSetMarkingWithSingleState() | ||
{ | ||
$subject = new SubjectWithProperties(); | ||
$markingStore = new MethodMarkingStore(true, 'place', 'placeContext'); | ||
|
||
$marking = $markingStore->getMarking($subject); | ||
|
||
$this->assertCount(0, $marking->getPlaces()); | ||
|
||
$marking->mark('first_place'); | ||
|
||
$markingStore->setMarking($subject, $marking, ['foo' => 'bar']); | ||
|
||
$this->assertSame('first_place', $subject->place); | ||
|
||
$marking2 = $markingStore->getMarking($subject); | ||
|
||
$this->assertEquals($marking, $marking2); | ||
} | ||
|
||
public function testGetSetMarkingWithSingleStateAndAlmostEmptyPlaceName() | ||
{ | ||
$subject = new SubjectWithProperties(); | ||
$subject->place = 0; | ||
|
||
$markingStore = new MethodMarkingStore(true, 'place'); | ||
|
||
$marking = $markingStore->getMarking($subject); | ||
|
||
$this->assertCount(1, $marking->getPlaces()); | ||
} | ||
|
||
public function testGetMarkingWithValueObject() | ||
{ | ||
$subject = new SubjectWithProperties(); | ||
$subject->place = $this->createValueObject('first_place'); | ||
|
||
$markingStore = new MethodMarkingStore(true, 'place'); | ||
|
||
$marking = $markingStore->getMarking($subject); | ||
|
||
$this->assertCount(1, $marking->getPlaces()); | ||
$this->assertSame('first_place', (string) $subject->place); | ||
} | ||
|
||
public function testGetMarkingWithUninitializedProperty() | ||
{ | ||
$subject = new SubjectWithProperties(); | ||
|
||
$markingStore = new MethodMarkingStore(true, 'place'); | ||
|
||
$marking = $markingStore->getMarking($subject); | ||
|
||
$this->assertCount(0, $marking->getPlaces()); | ||
} | ||
|
||
private function createValueObject(string $markingValue): object | ||
{ | ||
return new class($markingValue) { | ||
public function __construct( | ||
private string $markingValue, | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->markingValue; | ||
} | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Symfony/Component/Workflow/Tests/MarkingStore/SubjectWithProperties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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; | ||
|
||
final class SubjectWithProperties | ||
{ | ||
// for type=workflow | ||
public array $marking; | ||
|
||
// for type=state_machine | ||
public string $place; | ||
|
||
private function getMarking(): array | ||
{ | ||
return $this->marking; | ||
} | ||
} |