/**
  * @dataProvider defaultIntegrationOwnerProvider
  *
  * @param Integration $integration
  * @param string      $ownerType
  * @param bool        $expectedReload
  * @param bool        $expectedSet
  * @param bool        $expectedSetOrganization
  */
 public function testPopulateChannelOwner(Integration $integration, $ownerType, $expectedReload, $expectedSet, $expectedSetOrganization = false)
 {
     $entity = new \stdClass();
     $owner = $integration->getDefaultUserOwner();
     $organization = $integration->getOrganization();
     $doctrineMetadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($doctrineMetadata));
     if ($expectedReload) {
         $this->uow->expects($this->once())->method('getEntityState')->with($this->identicalTo($owner))->will($this->returnValue(UnitOfWork::STATE_DETACHED));
         $this->em->expects($this->once())->method('find')->with($this->equalTo(get_class($owner)))->will($this->returnValue($owner));
     }
     $ownerMetadata = new OwnershipMetadata($ownerType, self::USER_OWNER_FIELD_NAME, self::USER_OWNER_COLUMN_NAME, self::ORGANIZATION_FIELD_NAME);
     $this->metadataProvider->expects($this->any())->method('getMetadata')->with(get_class($entity))->will($this->returnValue($ownerMetadata));
     if ($expectedSet) {
         $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::USER_OWNER_FIELD_NAME, $this->identicalTo($owner));
     } elseif ($expectedSetOrganization) {
         $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::ORGANIZATION_FIELD_NAME, $this->identicalTo($organization));
     } else {
         $doctrineMetadata->expects($this->never())->method('setFieldValue');
     }
     $this->helper->populateChannelOwner($entity, $integration);
 }
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject $qb
  * @param object $entity
  * @param int|null $id
  * @param array $config
  * @param AutomaticDiscovery $service
  */
 protected function assertDiscoveryCalls($qb, $entity, $id, $config, AutomaticDiscovery $service)
 {
     $metadata = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\Metadata\\OwnershipMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataProvider->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $metadata->expects($this->any())->method('getOrganizationFieldName')->willReturn('organization');
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getOneOrNullResult'])->getMockForAbstractClass();
     $query->expects($this->once())->method('getOneOrNullResult')->will($this->returnValue($entity));
     $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $qb->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('createQueryBuilder')->with(AutomaticDiscovery::ROOT_ALIAS)->will($this->returnValue($qb));
     $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifierFieldName')->with($this->entityClass)->will($this->returnValue('id'));
     $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($id));
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with($this->entityClass)->will($this->returnValue($repository));
     $this->defaultStrategy->expects($this->once())->method('apply')->with($qb, AutomaticDiscovery::ROOT_ALIAS, 'test1', $config[Configuration::DISCOVERY_NODE], $entity);
     /** @var \PHPUnit_Framework_MockObject_MockObject|DiscoveryStrategyInterface $customStrategy */
     $customStrategy = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Service\\AutomaticDiscovery\\DiscoveryStrategyInterface');
     $customStrategy->expects($this->once())->method('apply')->with($qb, AutomaticDiscovery::ROOT_ALIAS, 'test2', $config[Configuration::DISCOVERY_NODE], $entity);
     $service->addStrategy('test2', $customStrategy);
 }