VipTicketsTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 5
dl 0
loc 185
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 4 1
A createTicketsCommand() 0 4 1
B vipTicketsShouldAlwaysBeCreated() 0 76 1
B vipTicketsShouldNotCountForEventCapacity() 0 43 1
B vipTicketsShouldBeCreatedIfEventIsOverCapacity() 0 33 1
1
<?php
2
3
/**
4
 * @author    Markus Tacker <[email protected]>
5
 * @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/
6
 */
7
8
namespace BCRM\WebBundle\Tests\Functional;
9
10
use BCRM\BackendBundle\Command\CreateTicketsCommand;
11
use BCRM\BackendBundle\Entity\Event\Registration;
12
use BCRM\BackendBundle\Entity\Event\Ticket;
13
use BCRM\BackendBundle\Entity\Payment;
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
/**
17
 * - VIPs and Sponsors must always be given tickets.
18
 * - The events capacity must only be applied to the regular tickets.
19
 */
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()
27
    {
28
        static::resetDatabase();
29
    }
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);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 39 can be null; however, BCRM\WebBundle\Tests\Fun...:createTicketsCommand() does not accept null, maybe add an additional type check?

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:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 39 can be null; however, BCRM\WebBundle\Tests\Fun...:createTicketsCommand() does not accept null, maybe add an additional type check?

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:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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)
113
    {
114
        $this->runCommand($container, new CreateTicketsCommand(), 'bcrm:tickets:create');
115
    }
116
117
    /**
118
     * @test
119
     * @depends vipTicketsShouldAlwaysBeCreated
120
     */
121
    function vipTicketsShouldNotCountForEventCapacity()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
122
    {
123
        /* @var $em \Doctrine\Common\Persistence\ObjectManager */
124
        $client    = static::createClient();
125
        $container = $client->getContainer();
126
        $em        = $container
127
            ->get('doctrine')
128
            ->getManager();
129
130
        $event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0];
131
132
        // Create two other normal registrations
133
        $joePays = new Payment();
134
        $joePays->setTransactionId('joepay');
135
        $joePays->setMethod('cash');
136
        $em->persist($joePays);
137
        $joe = new Registration();
138
        $joe->setName('Joe');
139
        $joe->setUuid('Joe');
140
        $joe->setEvent($event);
141
        $joe->setEmail('[email protected]');
142
        $joe->setSaturday(true);
143
        $joe->setPayment($joePays);
144
        $em->persist($joe);
145
        $jillPays = new Payment();
146
        $jillPays->setTransactionId('jillpays');
147
        $jillPays->setMethod('cash');
148
        $em->persist($jillPays);
149
        $jill = new Registration();
150
        $jill->setName('Jill');
151
        $jill->setUuid('Jill');
152
        $jill->setEvent($event);
153
        $jill->setEmail('[email protected]');
154
        $jill->setSaturday(true);
155
        $jill->setPayment($jillPays);
156
        $em->persist($jill);
157
        $em->flush();
158
        $this->createTicketsCommand($container);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 125 can be null; however, BCRM\WebBundle\Tests\Fun...:createTicketsCommand() does not accept null, maybe add an additional type check?

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:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
159
        $this->assertEquals(5, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array(
160
            'event' => $event,
161
            'day'   => Ticket::DAY_SATURDAY,
162
        ))));
163
    }
164
165
    /**
166
     * @test
167
     * @group   functional
168
     * @group   regression
169
     * @depends vipTicketsShouldNotCountForEventCapacity
170
     */
171
    public function vipTicketsShouldBeCreatedIfEventIsOverCapacity()
172
    {
173
        /* @var $em \Doctrine\Common\Persistence\ObjectManager */
174
        $client    = static::createClient();
175
        $container = $client->getContainer();
176
        $em        = $container
177
            ->get('doctrine')
178
            ->getManager();
179
180
        $event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0];
181
        $event->setCapacity(1);
182
        $em->persist($event);
183
        $em->flush();
184
185
        // Create Sponsor registration
186
        $sponsor2 = new Registration();
187
        $sponsor2->setName('Sponsor 2');
188
        $sponsor2->setUuid('Sponsor 2');
189
        $sponsor2->setEvent($event);
190
        $sponsor2->setEmail('[email protected]');
191
        $sponsor2->setSaturday(true);
192
        $sponsor2->setType(Registration::TYPE_SPONSOR);
193
        $em->persist($sponsor2);
194
195
        $em->flush();
196
197
        $this->createTicketsCommand($container);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 175 can be null; however, BCRM\WebBundle\Tests\Fun...:createTicketsCommand() does not accept null, maybe add an additional type check?

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:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
198
199
        $this->assertEquals(6, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array(
200
            'event' => $event,
201
            'day'   => Ticket::DAY_SATURDAY,
202
        ))));
203
    }
204
}
205