|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * This file is part of the CleverAge/ProcessBundle package. |
| 4 | + * |
| 5 | + * Copyright (C) 2017-2019 Clever-Age |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace CleverAge\ProcessBundle\Tests; |
| 12 | + |
| 13 | +use CleverAge\ProcessBundle\Context\ContextualOptionResolver; |
| 14 | +use CleverAge\ProcessBundle\Event\ProcessEvent; |
| 15 | +use CleverAge\ProcessBundle\Logger\ProcessLogger; |
| 16 | +use CleverAge\ProcessBundle\Logger\TaskLogger; |
| 17 | +use CleverAge\ProcessBundle\Manager\ProcessManager; |
| 18 | +use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry; |
| 19 | +use Prophecy\Argument\Token\TypeToken; |
| 20 | +use Prophecy\Prophecy\MethodProphecy; |
| 21 | +use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 22 | + |
| 23 | +class ProcessManagerTest extends AbstractProcessTest |
| 24 | +{ |
| 25 | + |
| 26 | + public function testProcessEvents() |
| 27 | + { |
| 28 | + $edProphecy = $this->prophesize(EventDispatcherInterface::class); |
| 29 | + |
| 30 | + $dispatchStartProphecy = new MethodProphecy($edProphecy, 'dispatch', [ProcessEvent::EVENT_PROCESS_STARTED, new TypeToken(ProcessEvent::class)]); |
| 31 | + $dispatchStartProphecy->shouldBeCalled(); |
| 32 | + $edProphecy->addMethodProphecy($dispatchStartProphecy); |
| 33 | + |
| 34 | + $dispatchStartProphecy = new MethodProphecy($edProphecy, 'dispatch', [ProcessEvent::EVENT_PROCESS_ENDED, new TypeToken(ProcessEvent::class)]); |
| 35 | + $dispatchStartProphecy->shouldBeCalled(); |
| 36 | + $edProphecy->addMethodProphecy($dispatchStartProphecy); |
| 37 | + |
| 38 | + $dispatchStartProphecy = new MethodProphecy($edProphecy, 'dispatch', [ProcessEvent::EVENT_PROCESS_FAILED, new TypeToken(ProcessEvent::class)]); |
| 39 | + $dispatchStartProphecy->shouldNotBeCalled(); |
| 40 | + $edProphecy->addMethodProphecy($dispatchStartProphecy); |
| 41 | + |
| 42 | + /** @var EventDispatcherInterface $eventDispatcher */ |
| 43 | + $eventDispatcher = $edProphecy->reveal(); |
| 44 | + $processManager = new ProcessManager( |
| 45 | + self::$container, |
| 46 | + self::$container->get(ProcessLogger::class), |
| 47 | + self::$container->get(TaskLogger::class), |
| 48 | + self::$container->get(ProcessConfigurationRegistry::class), |
| 49 | + self::$container->get(ContextualOptionResolver::class), |
| 50 | + $eventDispatcher |
| 51 | + ); |
| 52 | + |
| 53 | + $processManager->execute('test.simple_process'); |
| 54 | + } |
| 55 | +} |
0 commit comments