/**
  * Bind entities to workflow item
  *
  * @param WorkflowItem $workflowItem
  * @return bool
  * @throws \LogicException
  */
 public function bindEntities(WorkflowItem $workflowItem)
 {
     if (!$this->entityBinder) {
         throw new \LogicException('Entity binder is not set.');
     }
     return $this->entityBinder->bindEntities($workflowItem);
 }
 public function testBindEntities()
 {
     $workflowName = 'test_workflow';
     $bindAttributeNames = array('foo', 'bar');
     $fooEntity = $this->getMock('FooEntity');
     $fooIds = array('id' => 1);
     $barEntity = $this->getMock('BarEntity');
     $barIds = array('id' => 2);
     $this->workflowItem->expects($this->at(0))->method('getData')->will($this->returnValue($this->workflowData));
     $this->workflowData->expects($this->once())->method('isModified')->will($this->returnValue(true));
     $this->workflowItem->expects($this->at(1))->method('getWorkflowName')->will($this->returnValue($workflowName));
     $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($this->workflow));
     $this->attributeManager->expects($this->once())->method('getBindEntityAttributeNames')->will($this->returnValue($bindAttributeNames));
     $this->workflowData->expects($this->once())->method('getValues')->with($bindAttributeNames)->will($this->returnValue(array('foo' => $fooEntity, 'bar' => $barEntity)));
     $this->doctrineHelper->expects($this->at(0))->method('getEntityClass')->with($fooEntity)->will($this->returnValue(get_class($fooEntity)));
     $this->doctrineHelper->expects($this->at(1))->method('getEntityIdentifier')->with($fooEntity)->will($this->returnValue($fooIds));
     $this->doctrineHelper->expects($this->at(2))->method('getEntityClass')->with($barEntity)->will($this->returnValue(get_class($barEntity)));
     $this->doctrineHelper->expects($this->at(3))->method('getEntityIdentifier')->with($barEntity)->will($this->returnValue($barIds));
     $this->workflowItem->expects($this->once())->method('syncBindEntities')->with($this->callback(function (array $bindEntities) use($fooEntity, $fooIds, $barEntity, $barIds) {
         return count($bindEntities) == 2 && $bindEntities[0] instanceof WorkflowBindEntity && $bindEntities[0]->getEntityId() == $fooIds['id'] && $bindEntities[0]->getEntityClass() == get_class($fooEntity) && $bindEntities[1] instanceof WorkflowBindEntity && $bindEntities[1]->getEntityId() == $barIds['id'] && $bindEntities[1]->getEntityClass() == get_class($barEntity);
     }))->will($this->returnValue(true));
     $this->assertTrue($this->binder->bindEntities($this->workflowItem));
 }