|
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
|
|
|
* @date 29.06.16 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Tests\Functional; |
|
13
|
|
|
|
|
14
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Tests\Functional\Configuration\EventTriggerWithGuardsCase\Fixtures\Event; |
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Tests\Functional\Configuration\EventTriggerWithGuardsCase\Fixtures\TargetWorkflowSubject; |
|
16
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
17
|
|
|
|
|
18
|
|
|
class EventTriggerWithGuardsCaseTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* WebClient emulator |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Symfony\Bundle\FrameworkBundle\Client |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $client; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::setUp(); |
|
33
|
|
|
|
|
34
|
|
|
$this->client = $this->createClient( |
|
35
|
|
|
array( |
|
36
|
|
|
"app_name" => "EventTriggerWithGuardsCaseTest", |
|
37
|
|
|
"test_case" => "EventTriggerWithGuardsCase", |
|
38
|
|
|
"root_config" => "config.yml", |
|
39
|
|
|
"config_dir" => __DIR__ . "/Configuration", |
|
40
|
|
|
"environment" => "test", |
|
41
|
|
|
"debug" => false |
|
42
|
|
|
) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @group functional |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testSimple() |
|
50
|
|
|
{ |
|
51
|
|
|
$container = $this->client->getContainer(); |
|
52
|
|
|
/** @var EventDispatcherInterface $eventDispatcher */ |
|
53
|
|
|
$eventDispatcher = $container->get('event_dispatcher'); |
|
54
|
|
|
|
|
55
|
|
|
$subject = new TargetWorkflowSubject(); |
|
56
|
|
|
$event = new Event($subject); |
|
57
|
|
|
|
|
58
|
|
|
$eventDispatcher->dispatch('processing.event', $event); |
|
59
|
|
|
self::assertEquals(['processing' => 1], $subject->getStatus()); |
|
60
|
|
|
|
|
61
|
|
|
$eventDispatcher->dispatch('processing.event', $event); |
|
62
|
|
|
self::assertEquals(['active' => 1, "regular" => 1], $subject->getStatus()); |
|
63
|
|
|
|
|
64
|
|
|
$eventDispatcher->dispatch('viping.event', $event); |
|
65
|
|
|
self::assertEquals(['active' => 1, 'vip' => 1], $subject->getStatus()); |
|
66
|
|
|
|
|
67
|
|
|
$eventDispatcher->dispatch('processing.event', $event); |
|
68
|
|
|
// nothing happens |
|
69
|
|
|
self::assertEquals(['active' => 1, 'vip' => 1], $subject->getStatus()); |
|
70
|
|
|
|
|
71
|
|
|
$eventDispatcher->dispatch('viping.event', $event); |
|
72
|
|
|
// guard prevents closing vips |
|
73
|
|
|
self::assertEquals(['active' => 1, 'vip' => 1], $subject->getStatus()); |
|
74
|
|
|
|
|
75
|
|
|
$eventDispatcher->dispatch('crazy_closing.event', $event); |
|
76
|
|
|
// guard allows closing only if there is only one place "active" in marking |
|
77
|
|
|
self::assertEquals(['active' => 1, 'vip' => 1], $subject->getStatus()); |
|
78
|
|
|
} |
|
79
|
|
|
} |