Move createAutomationRun method to integration tester
[MAILPOET-4966]
This commit is contained in:
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
use Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore;
|
use Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore;
|
||||||
use MailPoet\Automation\Engine\Data\Automation;
|
use MailPoet\Automation\Engine\Data\Automation;
|
||||||
|
use MailPoet\Automation\Engine\Data\AutomationRun;
|
||||||
use MailPoet\Automation\Engine\Data\NextStep;
|
use MailPoet\Automation\Engine\Data\NextStep;
|
||||||
use MailPoet\Automation\Engine\Data\Step;
|
use MailPoet\Automation\Engine\Data\Step;
|
||||||
|
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
||||||
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
|
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
|
||||||
use MailPoet\DI\ContainerWrapper;
|
use MailPoet\DI\ContainerWrapper;
|
||||||
@ -146,4 +148,23 @@ class IntegrationTester extends \Codeception\Actor {
|
|||||||
$automation->setStatus(Automation::STATUS_ACTIVE);
|
$automation->setStatus(Automation::STATUS_ACTIVE);
|
||||||
return $automationStorage->getAutomation($automationStorage->createAutomation($automation));
|
return $automationStorage->getAutomation($automationStorage->createAutomation($automation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createAutomationRun(Automation $automation, $subjects = []): ?AutomationRun {
|
||||||
|
$trigger = array_filter($automation->getSteps(), function(Step $step): bool { return $step->getType() === Step::TYPE_TRIGGER;
|
||||||
|
|
||||||
|
});
|
||||||
|
$triggerKeys = array_map(function(Step $step): string { return $step->getKey();
|
||||||
|
|
||||||
|
}, $trigger);
|
||||||
|
$triggerKey = count($triggerKeys) > 0 ? current($triggerKeys) : '';
|
||||||
|
|
||||||
|
$automationRun = new AutomationRun(
|
||||||
|
$automation->getId(),
|
||||||
|
$automation->getVersionId(),
|
||||||
|
$triggerKey,
|
||||||
|
$subjects
|
||||||
|
);
|
||||||
|
$automationRunStorage = ContainerWrapper::getInstance()->get(AutomationRunStorage::class);
|
||||||
|
return $automationRunStorage->getAutomationRun($automationRunStorage->createAutomationRun($automationRun));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class StepHandlerTest extends \MailPoetTest {
|
|||||||
$automation = $this->createAutomation();
|
$automation = $this->createAutomation();
|
||||||
$this->assertInstanceOf(Automation::class, $automation);
|
$this->assertInstanceOf(Automation::class, $automation);
|
||||||
$steps = $automation->getSteps();
|
$steps = $automation->getSteps();
|
||||||
$automationRun = $this->createAutomationRun($automation);
|
$automationRun = $this->tester->createAutomationRun($automation);
|
||||||
$this->assertInstanceOf(AutomationRun::class, $automationRun);
|
$this->assertInstanceOf(AutomationRun::class, $automationRun);
|
||||||
|
|
||||||
$currentStep = current($steps);
|
$currentStep = current($steps);
|
||||||
@ -79,7 +79,7 @@ class StepHandlerTest extends \MailPoetTest {
|
|||||||
foreach ($invalidStati as $status) {
|
foreach ($invalidStati as $status) {
|
||||||
$automation->setStatus($status);
|
$automation->setStatus($status);
|
||||||
$this->automationStorage->updateAutomation($automation);
|
$this->automationStorage->updateAutomation($automation);
|
||||||
$automationRun = $this->createAutomationRun($automation);
|
$automationRun = $this->tester->createAutomationRun($automation);
|
||||||
$this->assertInstanceOf(AutomationRun::class, $automationRun);
|
$this->assertInstanceOf(AutomationRun::class, $automationRun);
|
||||||
$error = null;
|
$error = null;
|
||||||
try {
|
try {
|
||||||
@ -99,9 +99,9 @@ class StepHandlerTest extends \MailPoetTest {
|
|||||||
public function testAnDeactivatingAutomationBecomesDraftAfterLastRunIsExecuted() {
|
public function testAnDeactivatingAutomationBecomesDraftAfterLastRunIsExecuted() {
|
||||||
$automation = $this->createAutomation();
|
$automation = $this->createAutomation();
|
||||||
$this->assertInstanceOf(Automation::class, $automation);
|
$this->assertInstanceOf(Automation::class, $automation);
|
||||||
$automationRun1 = $this->createAutomationRun($automation);
|
$automationRun1 = $this->tester->createAutomationRun($automation);
|
||||||
$this->assertInstanceOf(AutomationRun::class, $automationRun1);
|
$this->assertInstanceOf(AutomationRun::class, $automationRun1);
|
||||||
$automationRun2 = $this->createAutomationRun($automation);
|
$automationRun2 = $this->tester->createAutomationRun($automation);
|
||||||
$this->assertInstanceOf(AutomationRun::class, $automationRun2);
|
$this->assertInstanceOf(AutomationRun::class, $automationRun2);
|
||||||
$automation->setStatus(Automation::STATUS_DEACTIVATING);
|
$automation->setStatus(Automation::STATUS_DEACTIVATING);
|
||||||
$this->automationStorage->updateAutomation($automation);
|
$this->automationStorage->updateAutomation($automation);
|
||||||
@ -139,24 +139,6 @@ class StepHandlerTest extends \MailPoetTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createAutomationRun(Automation $automation, $subjects = []): ?AutomationRun {
|
|
||||||
$trigger = array_filter($automation->getSteps(), function(Step $step): bool { return $step->getType() === Step::TYPE_TRIGGER;
|
|
||||||
|
|
||||||
});
|
|
||||||
$triggerKeys = array_map(function(Step $step): string { return $step->getKey();
|
|
||||||
|
|
||||||
}, $trigger);
|
|
||||||
$triggerKey = count($triggerKeys) > 0 ? current($triggerKeys) : '';
|
|
||||||
|
|
||||||
$automationRun = new AutomationRun(
|
|
||||||
$automation->getId(),
|
|
||||||
$automation->getVersionId(),
|
|
||||||
$triggerKey,
|
|
||||||
$subjects
|
|
||||||
);
|
|
||||||
return $this->automationRunStorage->getAutomationRun($this->automationRunStorage->createAutomationRun($automationRun));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function _after() {
|
public function _after() {
|
||||||
$this->automationStorage->truncate();
|
$this->automationStorage->truncate();
|
||||||
$this->automationRunStorage->truncate();
|
$this->automationRunStorage->truncate();
|
||||||
|
Reference in New Issue
Block a user