/** * @dataProvider syncBindEntitiesDataProvider * * @param WorkflowBindEntity[] $initialEntities * @param WorkflowBindEntity[] $syncEntities * @param WorkflowBindEntity[] $expectedEntities */ public function testSyncBindEntities(array $initialEntities, array $syncEntities, array $expectedEntities) { foreach ($initialEntities as $bindEntity) { $this->workflowItem->addBindEntity($bindEntity); } foreach ($expectedEntities as $expectedEntity) { $expectedEntity->setWorkflowItem($this->workflowItem); } $this->workflowItem->syncBindEntities($syncEntities); $this->assertEquals($expectedEntities, $this->workflowItem->getBindEntities()->getValues()); }
/** * Bind entities to workflow item * * @param WorkflowItem $workflowItem * @return bool Returns true if new entities were bound */ public function bindEntities(WorkflowItem $workflowItem) { $workflowData = $workflowItem->getData(); if (!$workflowData->isModified()) { return false; } $workflow = $this->workflowRegistry->getWorkflow($workflowItem->getWorkflowName()); $bindAttributeNames = $workflow->getAttributeManager()->getBindEntityAttributeNames(); $entitiesToBind = $workflowData->getValues($bindAttributeNames); return $workflowItem->syncBindEntities($this->createBindEntities($entitiesToBind)); }