1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\CampaignBundle\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use Starkerxp\CampaignBundle\Entity\Event; |
6
|
|
|
use Starkerxp\CampaignBundle\Manager\EventManager; |
7
|
|
|
use Starkerxp\StructureBundle\Test\WebTest; |
8
|
|
|
|
9
|
|
|
class EventManagerTest extends WebTest |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** @var EventManager */ |
13
|
|
|
protected $manager; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
$this->manager = $this->getContainer()->get('starkerxp_campaign.manager.event'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @group event |
23
|
|
|
* @group manager |
24
|
|
|
*/ |
25
|
|
|
public function testFindAll() |
26
|
|
|
{ |
27
|
|
|
$this->loadFixtureFiles( |
28
|
|
|
[ |
29
|
|
|
'@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml', |
30
|
|
|
|
31
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/DefaultCampaign.yml', |
32
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/TemplateManager.yml', |
33
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/EventManager/EventManager.yml', |
34
|
|
|
] |
35
|
|
|
); |
36
|
|
|
$this->assertCount(10, $this->manager->findAll()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @group event |
41
|
|
|
* @group manager |
42
|
|
|
*/ |
43
|
|
|
public function testInsertNewEvent() |
44
|
|
|
{ |
45
|
|
|
$this->loadFixtureFiles( |
46
|
|
|
[ |
47
|
|
|
'@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml', |
48
|
|
|
|
49
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/CampaignManager.yml', |
50
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/TemplateManager.yml', |
51
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml', |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
$campaigns = $this->getRepository("StarkerxpCampaignBundle:Campaign")->findBy([], ['id' => 'ASC']); |
55
|
|
|
$templates = $this->getRepository("StarkerxpCampaignBundle:Template")->findBy([], ['id' => 'ASC']); |
56
|
|
|
$event = new Event(); |
57
|
|
|
$event->setCampaign($campaigns[1]); |
58
|
|
|
$event->setTemplate($templates[1]); |
59
|
|
|
$this->manager->insert($event); |
60
|
|
|
$this->assertCount(2, $this->manager->findAll()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @group event |
65
|
|
|
* @group manager |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function testUpdateEvent() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$this->loadFixtureFiles( |
70
|
|
|
[ |
71
|
|
|
'@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml', |
72
|
|
|
|
73
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/DefaultCampaign.yml', |
74
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/TemplateManager.yml', |
75
|
|
|
'@StarkerxpCampaignBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml', |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
$criteria = ['createdAt' => new \DateTime("2016-08-05 12:12:12")]; |
79
|
|
|
$event = $this->manager->findOneBy($criteria); |
80
|
|
|
$this->manager->update($event); |
|
|
|
|
81
|
|
|
$eventPostUpdate = $this->manager->findOneBy($criteria); |
82
|
|
|
$this->assertNotEmpty($eventPostUpdate->getUpdatedAt()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
|
|
|
|
86
|
|
|
|
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.