1 | <?php |
||
20 | class VipTicketsTest extends Base |
||
21 | { |
||
22 | /** |
||
23 | * The setUpBeforeClass() and tearDownAfterClass() template methods are called before the first test of the test |
||
24 | * case class is run and after the last test of the test case class is run, respectively. |
||
25 | */ |
||
26 | public static function setUpBeforeClass() |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | * @group functional |
||
34 | */ |
||
35 | public function vipTicketsShouldAlwaysBeCreated() |
||
36 | { |
||
37 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
38 | $client = static::createClient(); |
||
39 | $container = $client->getContainer(); |
||
40 | $em = $container |
||
41 | ->get('doctrine') |
||
42 | ->getManager(); |
||
43 | |||
44 | $event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
||
45 | |||
46 | // Create normal registrations |
||
47 | $johnPays = new Payment(); |
||
48 | $johnPays->setTransactionId('johnpay'); |
||
49 | $johnPays->setMethod('cash'); |
||
50 | $em->persist($johnPays); |
||
51 | $john = new Registration(); |
||
52 | $john->setUuid('john'); |
||
53 | $john->setName('John'); |
||
54 | $john->setEvent($event); |
||
55 | $john->setEmail('[email protected]'); |
||
56 | $john->setSaturday(true); |
||
57 | $john->setPayment($johnPays); |
||
58 | $em->persist($john); |
||
59 | |||
60 | $maryPays = new Payment(); |
||
61 | $maryPays->setTransactionId('marypay'); |
||
62 | $maryPays->setMethod('cash'); |
||
63 | $em->persist($maryPays); |
||
64 | $mary = new Registration(); |
||
65 | $mary->setUuid('mary'); |
||
66 | $mary->setName('Mary'); |
||
67 | $mary->setEvent($event); |
||
68 | $mary->setEmail('[email protected]'); |
||
69 | $mary->setSaturday(true); |
||
70 | $mary->setPayment($maryPays); |
||
71 | $em->persist($mary); |
||
72 | |||
73 | $em->flush(); |
||
74 | |||
75 | $this->createTicketsCommand($container); |
||
|
|||
76 | |||
77 | $this->assertEquals(2, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
||
78 | 'event' => $event, |
||
79 | 'day' => Ticket::DAY_SATURDAY, |
||
80 | )))); |
||
81 | |||
82 | // Create VIP registration |
||
83 | $vip = new Registration(); |
||
84 | $vip->setUuid('VIP'); |
||
85 | $vip->setName('VIP'); |
||
86 | $vip->setEvent($event); |
||
87 | $vip->setEmail('[email protected]'); |
||
88 | $vip->setSaturday(true); |
||
89 | $vip->setType(Registration::TYPE_VIP); |
||
90 | $em->persist($vip); |
||
91 | |||
92 | // Create Sponsor registration |
||
93 | $sponsor = new Registration(); |
||
94 | $sponsor->setUuid('Sponsor'); |
||
95 | $sponsor->setName('Sponsor'); |
||
96 | $sponsor->setEvent($event); |
||
97 | $sponsor->setEmail('[email protected]'); |
||
98 | $sponsor->setSaturday(true); |
||
99 | $sponsor->setType(Registration::TYPE_SPONSOR); |
||
100 | $em->persist($sponsor); |
||
101 | |||
102 | $em->flush(); |
||
103 | |||
104 | $this->createTicketsCommand($container); |
||
105 | |||
106 | $this->assertEquals(4, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
||
107 | 'event' => $event, |
||
108 | 'day' => Ticket::DAY_SATURDAY, |
||
109 | )))); |
||
110 | } |
||
111 | |||
112 | protected function createTicketsCommand(ContainerInterface $container) |
||
116 | |||
117 | /** |
||
118 | * @test |
||
119 | * @depends vipTicketsShouldAlwaysBeCreated |
||
120 | */ |
||
121 | function vipTicketsShouldNotCountForEventCapacity() |
||
164 | |||
165 | /** |
||
166 | * @test |
||
167 | * @group functional |
||
168 | * @group regression |
||
169 | * @depends vipTicketsShouldNotCountForEventCapacity |
||
170 | */ |
||
171 | public function vipTicketsShouldBeCreatedIfEventIsOverCapacity() |
||
204 | } |
||
205 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: