1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\AnalyticsBundle\Tests\Unit\Builder; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; |
6
|
|
|
use OroCRM\Bundle\AnalyticsBundle\Builder\RFMBuilder; |
7
|
|
|
use OroCRM\Bundle\AnalyticsBundle\Builder\RFMProviderInterface; |
8
|
|
|
use OroCRM\Bundle\AnalyticsBundle\Entity\RFMMetricCategory; |
9
|
|
|
use OroCRM\Bundle\AnalyticsBundle\Tests\Unit\Model\Stub\RFMAwareStub; |
10
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
11
|
|
|
|
12
|
|
|
class RFMBuilderTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var RFMBuilder |
16
|
|
|
*/ |
17
|
|
|
protected $builder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|DoctrineHelper |
21
|
|
|
*/ |
22
|
|
|
protected $doctrineHelper; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->doctrineHelper = $this->getMockBuilder('Oro\Bundle\EntityBundle\ORM\DoctrineHelper') |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->getMock(); |
29
|
|
|
|
30
|
|
|
$this->builder = new RFMBuilder($this->doctrineHelper); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @expectedException \InvalidArgumentException |
35
|
|
|
* @expectedExceptionMessage Expected one of "recency,frequency,monetary" type, "wrong_type" given |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function testAddProviderFailed() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|RFMProviderInterface $provider */ |
40
|
|
|
$provider = $this->getMock('OroCRM\Bundle\AnalyticsBundle\Builder\RFMProviderInterface'); |
41
|
|
|
$provider->expects($this->once()) |
|
|
|
|
42
|
|
|
->method('getType') |
43
|
|
|
->will($this->returnValue('wrong_type')); |
44
|
|
|
|
45
|
|
|
$this->builder->addProvider($provider); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function testAddProviderSuccess() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|RFMProviderInterface $provider */ |
51
|
|
|
$provider = $this->getMock('OroCRM\Bundle\AnalyticsBundle\Builder\RFMProviderInterface'); |
52
|
|
|
$provider->expects($this->once()) |
|
|
|
|
53
|
|
|
->method('getType') |
54
|
|
|
->will($this->returnValue(RFMMetricCategory::TYPE_FREQUENCY)); |
55
|
|
|
|
56
|
|
|
$this->builder->addProvider($provider); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param mixed $entity |
61
|
|
|
* @param bool $expected |
62
|
|
|
* |
63
|
|
|
* @dataProvider supportsDataProvider |
64
|
|
|
*/ |
65
|
|
|
public function testSupports($entity, $expected) |
66
|
|
|
{ |
67
|
|
|
$this->assertEquals( |
68
|
|
|
$expected, |
69
|
|
|
$this->builder->supports($entity) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function supportsDataProvider() |
77
|
|
|
{ |
78
|
|
|
$mock = $this->getMock('OroCRM\Bundle\ChannelBundle\Entity\Channel'); |
79
|
|
|
$mock->expects($this->once()) |
80
|
|
|
->method('getCustomerIdentity') |
81
|
|
|
->willReturn(new RFMAwareStub()); |
82
|
|
|
return [ |
83
|
|
|
[new Channel(), false], |
84
|
|
|
[$mock, true], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.