protected function prepareEvent()
 {
     $this->entity->setEntities(['OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1', 'OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2']);
     $this->event->expects($this->atLeastOnce())->method('getChannel')->will($this->returnValue($this->entity));
     $this->settingProvider->expects($this->at(0))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1')->will($this->returnValue('TestConnector1'));
     $this->settingProvider->expects($this->at(1))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2')->will($this->returnValue('TestConnector2'));
     $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em));
     $this->em->expects($this->once())->method('persist')->with($this->integration);
     $this->em->expects($this->once())->method('flush');
 }
 public function testOnChannelSucceedSave()
 {
     $this->entity->setEntities(['OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1', 'OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2']);
     $this->event->expects($this->once())->method('getChannel')->will($this->returnValue($this->entity));
     $this->settingProvider->expects($this->at(0))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1')->will($this->returnValue('TestConnector1'));
     $this->settingProvider->expects($this->at(1))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2')->will($this->returnValue('TestConnector2'));
     $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em));
     $this->em->expects($this->once())->method('persist')->with($this->integration);
     $this->em->expects($this->once())->method('flush');
     $channelSaveSucceedListener = new ChannelSaveSucceedListener($this->settingProvider, $this->registry);
     $channelSaveSucceedListener->onChannelSucceedSave($this->event);
     $this->assertEquals($this->integration->getConnectors(), ['TestConnector1', 'TestConnector2']);
 }
Esempio n. 3
0
 /**
  * Returns built channel
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @return Channel
  */
 public function getChannel()
 {
     $type = $this->getDefaultType();
     $name = $this->getDefaultName($type);
     $identity = $this->settingsProvider->getCustomerIdentityFromConfig($type);
     if ($this->populateEntities) {
         $this->entities = $this->settingsProvider->getEntitiesByChannelType($type);
     }
     $this->addEntity($identity, true);
     $owner = $this->owner;
     if (!$owner) {
         $owner = $this->getDefaultOrganization();
     }
     $this->channel->setChannelType($type);
     $this->channel->setName($name);
     $this->channel->setOwner($owner);
     $this->channel->setCustomerIdentity($identity);
     $this->channel->setEntities($this->entities);
     $this->channel->setStatus($this->status);
     $this->channel->setDataSource($this->dataSource);
     if (null !== $this->createdAt) {
         // set created at only whn not nullable, otherwise update scenario will fail
         $this->channel->setCreatedAt($this->createdAt);
     }
     return $this->channel;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $this->em = $manager;
     $date = new \DateTime('now');
     $channel = new Channel();
     $channel->setName('some name');
     $channel->setOwner($this->loadOwner());
     $channel->setChannelType('testType');
     $channel->setCreatedAt($date);
     $channel->setUpdatedAt($date);
     $channel->setCustomerIdentity('test1');
     $channel->setEntities(['test1', 'test2']);
     $manager->persist($channel);
     $this->setReference('default_channel', $channel);
     $manager->flush();
 }
Esempio n. 5
0
 /**
  * Returns built channel
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @return Channel
  */
 public function getChannel()
 {
     $type = $this->getDefaultType();
     $name = $this->getDefaultName($type);
     $identity = $this->settingsProvider->getCustomerIdentityFromConfig($type);
     if ($this->populateEntities) {
         $this->entities = $this->settingsProvider->getEntitiesByChannelType($type);
     }
     $this->addEntity($identity, true);
     $owner = $this->owner;
     if (!$owner) {
         $owner = $this->getDefaultOrganization();
     }
     $this->channel->setChannelType($type);
     $this->channel->setName($name);
     $this->channel->setOwner($owner);
     $this->channel->setCustomerIdentity($identity);
     $this->channel->setEntities($this->entities);
     $this->channel->setStatus($this->status);
     $this->channel->setDataSource($this->dataSource);
     return $this->channel;
 }
Esempio n. 6
0
 /**
  * @param Channel $channel
  * @param array   $entitiesToAdd
  */
 protected function addEntitiesToChannel(Channel $channel, array $entitiesToAdd)
 {
     $entities = $channel->getEntities();
     $entities = is_array($entities) ? $entities : [];
     $combinedEntities = array_unique(array_merge($entities, $entitiesToAdd));
     $channel->setEntities($combinedEntities);
 }