/** * Create a task schema from an array of schema properties * * @param array $arr * @param string $name * @param string $version * @return TaskSchema */ public static function fromArray(array $arr, $name, $version) { $vars = ['requires' => [], 'retry' => 0, 'class' => null, 'input' => null, 'input_factory' => null, 'tasklist' => null, 'control' => null, 'schedule_to_close_timeout' => null, 'schedule_to_start_timeout' => null, 'start_to_close_timeout' => null, 'heartbeat_timeout' => null]; $schema = new TaskSchema(); $schema->setActivityName($name); $schema->setActivityVersion($version); foreach ($vars as $key => $default) { $fn = self::snakeToCamel('set_' . $key); $value = array_key_exists($key, $arr) ? $arr[$key] : $default; if (is_array($default) && !is_array($value)) { if ($value === null) { $value = []; } else { $value = [$value]; } } $schema->{$fn}($value); } return $schema; }
public function testCounts() { $history = new WorkflowHistory(); $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::COMPLETED(), 'alpha')); $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::COMPLETED(), 'bravo')); $history->add($this->createHistoryItem('test-activity', '2', HistoryItemState::COMPLETED(), 'charlie')); $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::SCHEDULED(), 'delta')); $history->add($this->createHistoryItem('other-activity', '1', HistoryItemState::COMPLETED(), 'echo')); $history->add($this->createHistoryItem('other-activity', '1', HistoryItemState::RUNNING(), 'foxtrot')); $inspector = new HistoryInspector($history); $schema_test = TaskSchema::fromKey('test-activity/1'); $schema_other = TaskSchema::fromKey('other-activity/1'); $this->assertEquals(0, $inspector->countTask($schema_test, HistoryItemState::RUNNING())); $this->assertEquals(0, $inspector->countTask($schema_test, HistoryItemState::FAILED())); $this->assertEquals(2, $inspector->countTask($schema_test, HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countTask($schema_test, HistoryItemState::SCHEDULED())); $this->assertEquals(1, $inspector->countTask($schema_other, HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countTask($schema_other, HistoryItemState::RUNNING())); $this->assertEquals(0, $inspector->countTask($schema_other, HistoryItemState::SCHEDULED())); $this->assertEquals(0, $inspector->countTask($schema_other, HistoryItemState::FAILED())); $this->assertEquals(1, $inspector->countControl('alpha', HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countControl('bravo', HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countControl('charlie', HistoryItemState::COMPLETED())); $this->assertEquals(0, $inspector->countControl('delta', HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countControl('echo', HistoryItemState::COMPLETED())); $this->assertEquals(0, $inspector->countControl('foxtrot', HistoryItemState::COMPLETED())); $this->assertTrue($inspector->haveOpenActivities()); $alpha = new TaskSchema(); $alpha->setActivityName('test-activity')->setActivityVersion('1')->setControl('alpha'); $this->assertEquals(2, $inspector->countTask($alpha, HistoryItemState::COMPLETED())); $this->assertEquals(1, $inspector->countTask($alpha, HistoryItemState::SCHEDULED())); $omega = new TaskSchema(); $omega->setActivityName('test-activity')->setActivityVersion('10'); $this->assertEquals(0, $inspector->countTask($omega, HistoryItemState::COMPLETED())); $this->assertTrue($inspector->hasTaskBeenScheduled($alpha)); $this->assertFalse($inspector->hasTaskBeenScheduled($omega)); }