/**
  * @param array $options
  * @param mixed $context
  *
  * @dataProvider executeOptionsDataProvider
  */
 public function testExecute(array $options, $context)
 {
     $matched = new \stdClass();
     $this->automaticDiscovery->expects($this->once())->method('discoverSimilar')->willReturn($matched);
     $this->action->initialize($options);
     $this->action->execute($context);
     $this->assertSame($matched, $this->contextAccessor->getValue($context, new PropertyPath('attribute')));
 }
 /**
  * @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);
 }