testDeleteWhenBadgeHasBeenUnlocked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Badger\Bundle\GameBundle\Tests\Controller;
4
5
use Badger\BadgerTestCase;
6
use Symfony\Bundle\FrameworkBundle\Client;
7
8
/**
9
 * @author    Marie Bochu <[email protected]>
10
 * @license   http://opensource.org/licenses/MIT The MIT License (MIT)
11
 */
12
class BadgeControllerTest extends BadgerTestCase
13
{
14
    public function testNewBadgeAction()
15
    {
16
        $client = $this->createUser();
17
18
        $count = count($this->get('badger.game.repository.badge')->findAll());
19
20
        $this->createBadge($client);
21
22
        $this->assertCount($count++, $this->get('badger.game.repository.badge')->findAll());
23
    }
24
25
    public function testDeleteAction()
26
    {
27
        $client = $this->createUser();
28
29
        $count = count($this->get('badger.game.repository.badge')->findAll());
30
31
        $badge = $this->get('badger.game.repository.badge')->findOneBy(['title' => 'Master Contributor']);
32
        $this->deleteBadge($client, $badge->getId());
33
34
        $this->assertCount($count -= 1, $this->get('badger.game.repository.badge')->findAll());
35
    }
36
37 View Code Duplication
    public function testDeleteWhenBadgeHasBeenClaimed()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
38
    {
39
        $client = $this->createUser();
40
41
        $countBadge = count($this->get('badger.game.repository.badge')->findAll());
42
        $countClaimedBadge = count($this->get('badger.game.repository.badge_completion')->findAll());
43
44
        $badge = $this->get('badger.game.repository.badge')->findOneBy(['title' => 'Bug Hunter']);
45
        $this->deleteBadge($client, $badge->getId());
46
47
        $this->assertCount($countBadge -= 1, $this->get('badger.game.repository.badge')->findAll(), 'Badge is removed');
48
        $this->assertCount($countClaimedBadge -= 1, $this->get('badger.game.repository.badge_completion')->findAll(), 'Claimed badge completion is removed');
49
    }
50
51 View Code Duplication
    public function testDeleteWhenBadgeHasBeenUnlocked()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
52
    {
53
        $client = $this->createUser();
54
55
        $countBadge = count($this->get('badger.game.repository.badge')->findAll());
56
        $countUnlockedBadge = count($this->get('badger.game.repository.badge_completion')->findAll());
57
58
        $badge = $this->get('badger.game.repository.badge')->findOneBy(['title' => 'Bug Hunter']);
59
        $this->deleteBadge($client, $badge->getId());
60
61
        $this->assertCount($countBadge -= 1, $this->get('badger.game.repository.badge')->findAll(), 'Badge is removed');
62
        $this->assertCount($countUnlockedBadge -= 1, $this->get('badger.game.repository.badge_completion')->findAll(), 'Badge completion is removed');
63
    }
64
65
    /**
66
     * @param Client $client
67
     */
68
    private function createBadge(Client $client)
69
    {
70
        $tag = $this->get('badger.game.repository.tag')->findOneBy(['code' => 'company']);
71
72
        $client->request('POST', 'admin/badge/new', [
73
            'badge' => [
74
                'title' => 'Part of the team',
75
                'tags' => [$tag->getId()]
76
            ]
77
        ]);
78
    }
79
80
    /**
81
     * @param Client $client
82
     * @param string $id
83
     */
84
    private function deleteBadge(Client $client, $id)
85
    {
86
        $client->request('POST', sprintf('admin/badge/%s/delete', $id), [
87
            '_method' => 'DELETE',
88
            'form' => []
89
        ]);
90
    }
91
}
92