Пример #1
0
 /**
  * @dataProvider buildDataProvider
  *
  * @param $channelReference
  * @param array $ids
  * @param array $expectedData
  */
 public function testBuild($channelReference, array $expectedData, array $ids = [])
 {
     /** @var Channel $channel */
     $channel = $this->getReference($channelReference);
     $this->builder->build($channel, $ids);
     $this->assertAnalyticBuild($channel, $expectedData);
 }
Пример #2
0
 /**
  * @param bool $supports
  * @param bool $expected
  * @param mixed $entityIndex
  * @param mixed $providerValue
  * @param mixed $expectedIndex
  * @param \PHPUnit_Framework_MockObject_MockObject|Channel $channel
  * @param int $channelId
  * @param array $categories
  *
  * @dataProvider buildDataProvider
  */
 public function testBuild($supports, $expected, $entityIndex = null, $providerValue = null, $expectedIndex = null, $channel = null, $channelId = null, array $categories = null)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|RFMProviderInterface $provider */
     $provider = $this->getMock('OroCRM\\Bundle\\AnalyticsBundle\\Builder\\RFMProviderInterface');
     $provider->expects($this->any())->method('getType')->will($this->returnValue(RFMMetricCategory::TYPE_FREQUENCY));
     $provider->expects($this->any())->method('getValue')->will($this->returnValue($providerValue));
     $provider->expects($this->any())->method('supports')->will($this->returnValue($supports));
     $this->builder->addProvider($provider);
     /** @var \PHPUnit_Framework_MockObject_MockObject|RFMAwareInterface $entity */
     $entity = $this->getMock('OroCRM\\Bundle\\AnalyticsBundle\\Model\\RFMAwareInterface');
     $entity->expects($this->any())->method('getDataChannel')->will($this->returnValue($channel));
     if ($expected) {
         $entity->expects($this->exactly(2))->method('setFrequency')->with($this->equalTo($expectedIndex));
     }
     if ($entityIndex) {
         $entity->expects($this->exactly(2))->method('getFrequency')->will($this->returnValue($entityIndex));
     }
     if ($channel) {
         $this->doctrineHelper->expects($this->exactly(2))->method('getSingleEntityIdentifier')->with($this->equalTo($channel))->will($this->returnValue($channelId));
     }
     if ($channel && is_array($categories)) {
         /** @var \PHPUnit_Framework_MockObject_MockObject|EntityRepository $repo */
         $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
         $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->will($this->returnValue($repo));
         $repo->expects($this->once())->method('findBy')->will($this->returnValue($categories));
     }
     $this->assertEquals($expected, $this->builder->build($entity));
     /** check cache, getEntityRepository should not be called anymore */
     $this->assertEquals($expected, $this->builder->build($entity));
 }
Пример #3
0
 /**
  * @dataProvider dataAnalytics
  * @param string $ref
  * @param array $expectedIndex
  */
 public function testAnalyticsMetrics($ref, array $expectedIndex)
 {
     $doctrineHelper = $this->getContainer()->get('oro_entity.doctrine_helper');
     /** @var Customer $customer */
     $customer = $this->getReference($ref);
     $className = 'OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer';
     $recencyProvider = new CustomerRecencyProvider($doctrineHelper, $className);
     $frequencyProvider = new CustomerFrequencyProvider($doctrineHelper, $className);
     $monetaryProvider = new CustomerMonetaryProvider($doctrineHelper, $className);
     $rfmBuilder = new RFMBuilder($doctrineHelper);
     $rfmBuilder->addProvider($recencyProvider);
     $rfmBuilder->addProvider($frequencyProvider);
     $rfmBuilder->addProvider($monetaryProvider);
     $analitycs = new AnalyticsBuilder();
     $analitycs->addBuilder($rfmBuilder);
     $analitycs->build($customer);
     $this->assertEquals($expectedIndex['recency'], $customer->getRecency());
     $this->assertEquals($expectedIndex['frequency'], $customer->getFrequency());
     $this->assertEquals($expectedIndex['monetary'], $customer->getMonetary());
 }
Пример #4
0
 /**
  * @param mixed $entity
  * @param bool $expected
  *
  * @dataProvider supportsDataProvider
  */
 public function testSupports($entity, $expected)
 {
     $this->assertEquals($expected, $this->builder->supports($entity));
 }