Completed
Push — master ( 494e95...e935f8 )
by Arnaud
01:56
created

testCompleteScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 48
rs 9.125
cc 1
eloc 27
nc 1
nop 0
1
<?php
2
/*
3
 * Copyright 2014-2017 Arnaud Bienvenu
4
 *
5
 * This file is part of Kyela.
6
7
 * Kyela is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
12
 * Kyela is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with Kyela.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace Abienvenu\KyelaBundle\Tests\Controller;
23
24
class ParticipationControllerTest extends PollWebTestCase
25
{
26
    /**
27
     * Creates, edits and deletes a participation
28
     */
29
    public function testCompleteScenario()
30
    {
31
        // Create a poll to work with
32
        $crawler = self::createPollEntry(uniqid('Test Poll '));
33
34
        // Create a participant
35
        $participant = uniqid('Test Participant ');
36
        $crawler = self::submitForm($crawler, 'add.a.participant', 'participant', ['name' => $participant]);
37
38
        // Create an event
39
        $event = uniqid('Test Event ');
40
        $crawler = self::clickLink($crawler, 'add.a.date');
41
        $crawler = self::submitForm($crawler, 'create', 'event',
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::submitForm($crawle...)), 'time' => '20:30')) on line 41 can be null; however, Abienvenu\KyelaBundle\Te...bTestCase::submitForm() 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...
42
            ['name' => $event, 'place' => 'Nowhere', 'date' => date('d-m-Y', strtotime("tomorrow")), 'time' => '20:30']);
43
44
        // Check "yes" is not selected
45
        $filter = 'button:contains("' . self::$translator->trans('yes') . '")';
46
        self::checkElement($crawler, $filter, 1);
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::submitForm($crawle...)), 'time' => '20:30')) on line 41 can be null; however, Abienvenu\KyelaBundle\Te...estCase::checkElement() 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...
47
48
        // Choose "yes"
49
        $button = $crawler->selectButton(self::$translator->trans('yes'));
50
        $url = $button->extract(['data-url'])[0];
51
        self::$client->request('GET', $url);
52
        self::$client->back();
53
        $crawler = self::$client->reload();
54
55
        // Check "yes is selected
56
        $filter = 'button:contains("' . self::$translator->trans('yes') . '")';
57
        self::checkElement($crawler, $filter, 2);
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::$client->reload() on line 53 can be null; however, Abienvenu\KyelaBundle\Te...estCase::checkElement() 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...
58
59
        // Choose "no"
60
        $button = $crawler->selectButton(self::$translator->trans('no'));
61
        $url = $button->extract(['data-url'])[0];
62
        self::$client->request('GET', $url);
63
        self::$client->back();
64
        $crawler = self::$client->reload();
65
66
        // Check "yes" is not selected anymore
67
        $filter = 'button:contains("' . self::$translator->trans('yes') . '")';
68
        self::checkElement($crawler, $filter, 1);
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::$client->reload() on line 64 can be null; however, Abienvenu\KyelaBundle\Te...estCase::checkElement() 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...
69
70
        // Check "no" is selected
71
        $filter = 'button:contains("' . self::$translator->trans('no') . '")';
72
        self::checkElement($crawler, $filter, 2);
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::$client->reload() on line 64 can be null; however, Abienvenu\KyelaBundle\Te...estCase::checkElement() 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...
73
74
        // Delete the poll
75
        self::deletePollEntry($crawler);
0 ignored issues
show
Bug introduced by
It seems like $crawler defined by self::$client->reload() on line 64 can be null; however, Abienvenu\KyelaBundle\Te...Case::deletePollEntry() 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
}
78