1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* (c) fduch <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Date: 19.10.16 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Tests\Action; |
14
|
|
|
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Executor; |
16
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Reference\ActionReferenceInterface; |
17
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Registry; |
18
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Tests\Action\Reference\ContainerAwareActionReferenceInterface; |
19
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowContext; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
22
|
|
|
use Symfony\Component\Workflow\Workflow; |
23
|
|
|
|
24
|
|
|
class ExecutorTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @dataProvider actionReferenceProvider |
28
|
|
|
*/ |
29
|
|
|
public function testEvaluatesAction($actionReferenceClass, $actionReferenceType, $inputArgs, $expectedArgs, WorkflowContext $wc) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$container = $this->getMock(ContainerInterface::class); |
32
|
|
|
|
33
|
|
|
$actionName = 'a1'; |
34
|
|
|
$actionReference = $this->getMockBuilder(ActionReferenceInterface::class)->disableOriginalConstructor()->getMock(); |
35
|
|
|
$actionReference->expects(self::once())->method('invoke')->with($expectedArgs); |
36
|
|
|
$actionReference->expects(self::once())->method('getType')->willReturn($actionReferenceType); |
37
|
|
|
|
38
|
|
|
$actionRegistry = $this->getMock(Registry::class); |
39
|
|
|
$actionRegistry->expects(self::once())->method('get')->with(self::equalTo($actionName))->willReturn($actionReference); |
40
|
|
|
|
41
|
|
|
$executor = new Executor($actionRegistry, $container); |
42
|
|
|
$executor->execute($wc, $actionName, $inputArgs); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function actionReferenceProvider() |
46
|
|
|
{ |
47
|
|
|
$data = []; |
48
|
|
|
|
49
|
|
|
$workflowContext = new WorkflowContext( |
50
|
|
|
$this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock(), |
51
|
|
|
new \StdClass(), |
52
|
|
|
1 |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$defaultInputActionArgs = ['some' => 'arg', 'more']; |
56
|
|
|
|
57
|
|
|
// regular action (non-container-aware) |
58
|
|
|
$data[] = [ActionReferenceInterface::class, ActionReferenceInterface::TYPE_REGULAR, $defaultInputActionArgs, $defaultInputActionArgs, $workflowContext]; |
59
|
|
|
|
60
|
|
|
// regular action (container-aware) |
61
|
|
|
$data[] = [ContainerAwareActionReferenceInterface::class, ActionReferenceInterface::TYPE_REGULAR, $defaultInputActionArgs, $defaultInputActionArgs, $workflowContext]; |
62
|
|
|
|
63
|
|
|
$workflowActionInputArgs = $defaultInputActionArgs; |
64
|
|
|
array_unshift($workflowActionInputArgs, $workflowContext); |
65
|
|
|
|
66
|
|
|
// workflow action (non-container-aware) |
67
|
|
|
$data[] = [ActionReferenceInterface::class, ActionReferenceInterface::TYPE_WORKFLOW, $defaultInputActionArgs, $workflowActionInputArgs, $workflowContext]; |
68
|
|
|
|
69
|
|
|
// workflow action (container-aware) |
70
|
|
|
$data[] = [ContainerAwareActionReferenceInterface::class, ActionReferenceInterface::TYPE_WORKFLOW, $defaultInputActionArgs, $workflowActionInputArgs, $workflowContext]; |
71
|
|
|
|
72
|
|
|
return $data; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.