Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workflow] Introduce a Workflow interface
- Loading branch information
Amrouche Hamza
committed
Dec 4, 2017
1 parent
bf4b09f
commit e8351d8
Showing
15 changed files
with
314 additions
and
47 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
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
13 changes: 13 additions & 0 deletions
13
src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.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
41 changes: 41 additions & 0 deletions
41
src/Symfony/Component/Workflow/SupportStrategy/InstanceOfSupportStrategy.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,41 @@ | ||
<?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\SupportStrategy; | ||
|
||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
/** | ||
* @author Andreas Kleemann <akleemann@inviqa.com> | ||
* @author Amrouche Hamza <hamza.simperfit@gmail.com> | ||
*/ | ||
final class InstanceOfSupportStrategy implements WorkflowSupportStrategyInterface | ||
{ | ||
private $className; | ||
|
||
public function __construct(string $className) | ||
{ | ||
$this->className = $className; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports(WorkflowInterface $workflow, $subject): bool | ||
{ | ||
return $subject instanceof $this->className; | ||
} | ||
|
||
public function getClassName(): string | ||
{ | ||
return $this->className; | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/Symfony/Component/Workflow/SupportStrategy/WorkflowSupportStrategyInterface.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,22 @@ | ||
<?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\SupportStrategy; | ||
|
||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
/** | ||
* @author Amrouche Hamza <hamza.simperfit@gmail.com> | ||
*/ | ||
interface WorkflowSupportStrategyInterface | ||
{ | ||
public function supports(WorkflowInterface $workflow, $subject): bool; | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/Symfony/Component/Workflow/Tests/SupportStrategy/InstanceOfSupportStrategyTest.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,38 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Workflow\Tests\SupportStrategy; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy; | ||
use Symfony\Component\Workflow\Workflow; | ||
|
||
class InstanceOfSupportStrategyTest extends TestCase | ||
{ | ||
public function testSupportsIfClassInstance() | ||
{ | ||
$strategy = new InstanceOfSupportStrategy(Subject1::class); | ||
|
||
$this->assertTrue($strategy->supports($this->createWorkflow(), new Subject1())); | ||
} | ||
|
||
public function testSupportsIfNotClassInstance() | ||
{ | ||
$strategy = new InstanceOfSupportStrategy(Subject2::class); | ||
|
||
$this->assertFalse($strategy->supports($this->createWorkflow(), new Subject1())); | ||
} | ||
|
||
private function createWorkflow() | ||
{ | ||
return $this->getMockBuilder(Workflow::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
} | ||
|
||
class Subject1 | ||
{ | ||
} | ||
class Subject2 | ||
{ | ||
} |
Oops, something went wrong.