1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
|
8
|
|
|
use Oro\Bundle\DashboardBundle\Entity\Dashboard; |
9
|
|
|
use Oro\Bundle\DashboardBundle\Entity\Widget; |
10
|
|
|
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper; |
11
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\Opportunity; |
12
|
|
|
|
13
|
|
|
class LoadForecastWidgetFixtures extends AbstractFixture |
14
|
|
|
{ |
15
|
|
|
private $organization; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @inheritDoc |
19
|
|
|
*/ |
20
|
|
|
public function load(ObjectManager $manager) |
21
|
|
|
{ |
22
|
|
|
$this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); |
23
|
|
|
|
24
|
|
|
$this->addWidget($manager); |
25
|
|
|
$this->createOpportunity($manager); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param ObjectManager $manager |
30
|
|
|
*/ |
31
|
|
|
private function addWidget(ObjectManager $manager) |
32
|
|
|
{ |
33
|
|
|
$dashboard = new Dashboard(); |
34
|
|
|
$dashboard->setName('Test dashboard'); |
35
|
|
|
|
36
|
|
|
$leadStaticsWidget = new Widget(); |
37
|
|
|
$leadStaticsWidget |
38
|
|
|
->setDashboard($dashboard) |
39
|
|
|
->setName('forecast_of_opportunities') |
40
|
|
|
->setLayoutPosition([1, 1]); |
41
|
|
|
|
42
|
|
|
$dashboard->addWidget($leadStaticsWidget); |
43
|
|
|
|
44
|
|
|
if (!$this->hasReference('widget_forecast')) { |
45
|
|
|
$this->setReference('widget_forecast', $leadStaticsWidget); |
46
|
|
|
} |
47
|
|
|
$manager->persist($dashboard); |
48
|
|
|
$manager->flush(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ObjectManager $manager |
53
|
|
|
*/ |
54
|
|
|
private function createOpportunity(ObjectManager $manager) |
55
|
|
|
{ |
56
|
|
|
$opportunityList = [ |
57
|
|
|
[ |
58
|
|
|
'status' => 'in_progress', |
59
|
|
|
'close_date' => null, |
60
|
|
|
'probability' => 10, //percents |
61
|
|
|
'budget_amount' => 100, //USD |
62
|
|
|
], |
63
|
|
|
[ |
64
|
|
|
'status' => 'in_progress', |
65
|
|
|
'close_date' => new \DateTime('now'), |
66
|
|
|
'probability' => 10, //percents |
67
|
|
|
'budget_amount' => 100, //USD |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'status' => 'in_progress', |
71
|
|
|
'close_date' => new \DateTime('now'), |
72
|
|
|
'probability' => 100, //percents |
73
|
|
|
'budget_amount' => 100, //USD |
74
|
|
|
], |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
foreach ($opportunityList as $opportunityName => $opportunityData) { |
78
|
|
|
$opportunity = new Opportunity(); |
79
|
|
|
$opportunity->setName(sprintf('test_opportunity_%s', $opportunityName)); |
80
|
|
|
$opportunity->setBudgetAmount($opportunityData['budget_amount']); |
81
|
|
|
$opportunity->setProbability($opportunityData['probability']); |
82
|
|
|
$opportunity->setOrganization($this->organization); |
83
|
|
|
$opportunity->setCloseDate($opportunityData['close_date']); |
84
|
|
|
|
85
|
|
|
$enumClass = ExtendHelper::buildEnumValueClassName(Opportunity::INTERNAL_STATUS_CODE); |
86
|
|
|
$opportunity->setStatus($manager->getReference($enumClass, $opportunityData['status'])); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$manager->persist($opportunity); |
89
|
|
|
$manager->flush(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: