mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
Refactor workflow classes and forms
- the workflow controller add a context to each transition; - the state of the entity workflow is applyied using a dedicated marking store - the method EntityWorkflow::step use the context to associate the new step with the future destination user, cc users and email. This makes the step consistent at every step. - this allow to remove some logic which was processed in eventSubscribers, - as counterpart, each workflow must specify a dedicated marking_store: ```yaml framework: workflows: vendee_internal: # ... marking_store: service: Chill\MainBundle\Workflow\EntityWorkflowMarkingStore ```
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Tests\Entity\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ final class EntityWorkflowTest extends TestCase
|
||||
{
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
|
||||
$entityWorkflow->setStep('final');
|
||||
$entityWorkflow->setStep('final', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
$entityWorkflow->getCurrentStep()->setIsFinal(true);
|
||||
|
||||
$this->assertTrue($entityWorkflow->isFinal());
|
||||
@@ -37,16 +38,16 @@ final class EntityWorkflowTest extends TestCase
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFinal());
|
||||
|
||||
$entityWorkflow->setStep('two');
|
||||
$entityWorkflow->setStep('two', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFinal());
|
||||
|
||||
$entityWorkflow->setStep('previous_final');
|
||||
$entityWorkflow->setStep('previous_final', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFinal());
|
||||
|
||||
$entityWorkflow->getCurrentStep()->setIsFinal(true);
|
||||
$entityWorkflow->setStep('final');
|
||||
$entityWorkflow->setStep('final', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertTrue($entityWorkflow->isFinal());
|
||||
}
|
||||
@@ -57,20 +58,20 @@ final class EntityWorkflowTest extends TestCase
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFreeze());
|
||||
|
||||
$entityWorkflow->setStep('step_one');
|
||||
$entityWorkflow->setStep('step_one', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFreeze());
|
||||
|
||||
$entityWorkflow->setStep('step_three');
|
||||
$entityWorkflow->setStep('step_three', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertFalse($entityWorkflow->isFreeze());
|
||||
|
||||
$entityWorkflow->setStep('freezed');
|
||||
$entityWorkflow->setStep('freezed', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
$entityWorkflow->getCurrentStep()->setFreezeAfter(true);
|
||||
|
||||
$this->assertTrue($entityWorkflow->isFreeze());
|
||||
|
||||
$entityWorkflow->setStep('after_freeze');
|
||||
$entityWorkflow->setStep('after_freeze', new WorkflowTransitionContextDTO($entityWorkflow));
|
||||
|
||||
$this->assertTrue($entityWorkflow->isFreeze());
|
||||
|
||||
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowMarkingStore;
|
||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class EntityWorkflowMarkingStoreTest extends TestCase
|
||||
{
|
||||
public function testGetMarking(): void
|
||||
{
|
||||
$markingStore = $this->buildMarkingStore();
|
||||
$workflow = new EntityWorkflow();
|
||||
|
||||
$marking = $markingStore->getMarking($workflow);
|
||||
|
||||
self::assertEquals(['initial' => 1], $marking->getPlaces());
|
||||
}
|
||||
|
||||
public function testSetMarking(): void
|
||||
{
|
||||
$markingStore = $this->buildMarkingStore();
|
||||
$workflow = new EntityWorkflow();
|
||||
|
||||
$dto = new WorkflowTransitionContextDTO($workflow);
|
||||
$dto->futureCcUsers[] = $user1 = new User();
|
||||
$dto->futureDestUsers[] = $user2 = new User();
|
||||
$dto->futureDestEmails[] = $email = 'test@example.com';
|
||||
|
||||
$markingStore->setMarking($workflow, new Marking(['foo' => 1]), ['context' => $dto]);
|
||||
|
||||
$currentStep = $workflow->getCurrentStep();
|
||||
self::assertEquals('foo', $currentStep->getCurrentStep());
|
||||
self::assertContains($email, $currentStep->getDestEmail());
|
||||
self::assertContains($user1, $currentStep->getCcUser());
|
||||
self::assertContains($user2, $currentStep->getDestUser());
|
||||
}
|
||||
|
||||
private function buildMarkingStore(): EntityWorkflowMarkingStore
|
||||
{
|
||||
return new EntityWorkflowMarkingStore();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user