Remove unused step runner interface

[MAILPOET-5568]
This commit is contained in:
Jan Jakes
2023-08-31 15:34:23 +02:00
committed by Aschepikov
parent d8afb42d89
commit 9cd871c32e
6 changed files with 57 additions and 126 deletions

View File

@@ -3,39 +3,40 @@
namespace MailPoet\Test\Automation\Engine\Control;
use MailPoet\Automation\Engine\Control\StepHandler;
use MailPoet\Automation\Engine\Control\StepRunner;
use MailPoet\Automation\Engine\Data\Automation;
use MailPoet\Automation\Engine\Data\AutomationRun;
use MailPoet\Automation\Engine\Data\NextStep;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
use MailPoet\Automation\Engine\Integration\Action;
use MailPoet\Automation\Engine\Registry;
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
use MailPoet\Automation\Engine\Storage\AutomationStorage;
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
use MailPoet\Automation\Integrations\MailPoet\Triggers\SomeoneSubscribesTrigger;
class StepHandlerTest extends \MailPoetTest {
/** @var AutomationStorage */
private $automationStorage;
/** @var AutomationRunStorage */
private $automationRunStorage;
/** @var StepHandler */
private $testee;
/** @var array<string, StepRunner> */
private $originalRunners = [];
public function _before() {
$this->testee = $this->diContainer->get(StepHandler::class);
$this->automationStorage = $this->diContainer->get(AutomationStorage::class);
$this->automationRunStorage = $this->diContainer->get(AutomationRunStorage::class);
$this->originalRunners = $this->testee->getStepRunners();
}
public function testItDoesOnlyProcessActiveAndDeactivatingAutomations() {
// The run method will be called twice: Once for the active automation and once for the deactivating automation.
$step = $this->createMock(Action::class);
$step->expects(self::exactly(2))->method('run');
$registry = $this->createMock(Registry::class);
$registry->expects(self::exactly(2))->method('getStep')->willReturn($step);
$stepHandler = $this->getServiceWithOverrides(StepHandler::class, [
'registry' => $registry,
]);
$automation = $this->createAutomation();
$this->assertInstanceOf(Automation::class, $automation);
$steps = $automation->getSteps();
@@ -44,13 +45,9 @@ class StepHandlerTest extends \MailPoetTest {
$currentStep = current($steps);
$this->assertInstanceOf(Step::class, $currentStep);
$runner = $this->createMock(StepRunner::class);
$runner->expects(self::exactly(2))->method('run'); // The run method will be called twice: Once for the active automation and once for the deactivating automation.
$this->testee->addStepRunner($currentStep->getType(), $runner);
$this->assertSame(Automation::STATUS_ACTIVE, $automation->getStatus());
$this->testee->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
$stepHandler->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
// no exception thrown.
$newAutomationRun = $this->automationRunStorage->getAutomationRun($automationRun->getId());
$this->assertInstanceOf(AutomationRun::class, $newAutomationRun);
@@ -58,7 +55,7 @@ class StepHandlerTest extends \MailPoetTest {
$automation->setStatus(Automation::STATUS_DEACTIVATING);
$this->automationStorage->updateAutomation($automation);
$this->testee->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
$stepHandler->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
// no exception thrown.
$newAutomationRun = $this->automationRunStorage->getAutomationRun($automationRun->getId());
$this->assertInstanceOf(AutomationRun::class, $newAutomationRun);
@@ -78,7 +75,7 @@ class StepHandlerTest extends \MailPoetTest {
$this->assertInstanceOf(AutomationRun::class, $automationRun);
$error = null;
try {
$this->testee->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
$stepHandler->handle(['automation_run_id' => $automationRun->getId(), 'step_id' => $currentStep->getId()]);
} catch (InvalidStateException $error) {
$this->assertSame('mailpoet_automation_not_active', $error->getErrorCode(), "Automation with '$status' did not return expected error code.");
}
@@ -92,6 +89,14 @@ class StepHandlerTest extends \MailPoetTest {
}
public function testAnDeactivatingAutomationBecomesDraftAfterLastRunIsExecuted() {
$step = $this->createMock(Action::class);
$step->expects(self::exactly(2))->method('run');
$registry = $this->createMock(Registry::class);
$registry->expects(self::exactly(2))->method('getStep')->willReturn($step);
$stepHandler = $this->getServiceWithOverrides(StepHandler::class, [
'registry' => $registry,
]);
$automation = $this->createAutomation();
$this->assertInstanceOf(Automation::class, $automation);
$automationRun1 = $this->tester->createAutomationRun($automation);
@@ -104,10 +109,8 @@ class StepHandlerTest extends \MailPoetTest {
$steps = $automation->getSteps();
$lastStep = end($steps);
$this->assertInstanceOf(Step::class, $lastStep);
$runner = $this->createMock(StepRunner::class);
$this->testee->addStepRunner($lastStep->getType(), $runner);
$this->testee->handle(['automation_run_id' => $automationRun1->getId(), 'step_id' => $lastStep->getId()]);
$stepHandler->handle(['automation_run_id' => $automationRun1->getId(), 'step_id' => $lastStep->getId()]);
/** @var Automation $updatedAutomation */
$updatedAutomation = $this->automationStorage->getAutomation($automation->getId());
/** @var AutomationRun $updatedautomationRun */
@@ -115,7 +118,7 @@ class StepHandlerTest extends \MailPoetTest {
$this->assertSame(Automation::STATUS_DEACTIVATING, $updatedAutomation->getStatus());
$this->assertSame(AutomationRun::STATUS_COMPLETE, $updatedautomationRun->getStatus());
$this->testee->handle(['automation_run_id' => $automationRun2->getId(), 'step_id' => $lastStep->getId()]);
$stepHandler->handle(['automation_run_id' => $automationRun2->getId(), 'step_id' => $lastStep->getId()]);
/** @var Automation $updatedAutomation */
$updatedAutomation = $this->automationStorage->getAutomation($automation->getId());
/** @var AutomationRun $updatedautomationRun */
@@ -133,9 +136,4 @@ class StepHandlerTest extends \MailPoetTest {
new Step('delay', Step::TYPE_ACTION, $delay->getKey(), [], [])
);
}
public function _after() {
parent::_after();
$this->testee->setStepRunners($this->originalRunners);
}
}