Completed
Branch master (51b807)
by Frank
04:17 queued 02:02
created

ForgeCommandTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 36.49 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 27
loc 74
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Tests\Unit\Commands;
11
12
use T3Bot\Commands\ForgeCommand;
13
use T3Bot\Tests\Unit\BaseCommandTestCase;
14
15
/**
16
 * Class ForgeCommandTest.
17
 */
18
class ForgeCommandTest extends BaseCommandTestCase
19
{
20
    /**
21
     * Data provider for show command.
22
     *
23
     * @return array
24
     */
25
    public function showTestDataProvider() : array
26
    {
27
        return [
28
            'forge:show 23456' => ['23456'],
29
            'forge:show http://forge.typo3.org/issues/23456/' => ['http://forge.typo3.org/issues/23456/'],
30
            'forge:show https://forge.typo3.org/issues/23456/' => ['https://forge.typo3.org/issues/23456/'],
31
            'forge:show http://forge.typo3.org/issues/23456' => ['http://forge.typo3.org/issues/23456'],
32
            'forge:show https://forge.typo3.org/issues/23456' => ['https://forge.typo3.org/issues/23456'],
33
        ];
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function processShowReturnsCorrectResponseForNoOptions()
40
    {
41
        $this->initCommandWithPayload(ForgeCommand::class, [
42
            'user' => 'U54321',
43
            'text' => 'forge:show',
44
        ]);
45
        $result = $this->command->process();
46
        static::assertEquals('hey, I need an issue number!', $result);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function processShowReturnsCorrectResponseForInvalidIssueNumber()
53
    {
54
        $this->initCommandWithPayload(ForgeCommand::class, [
55
            'user' => 'U54321',
56
            'text' => 'forge:show asdasd',
57
        ]);
58
        $result = $this->command->process();
59
        static::assertEquals('hey, I need an issue number!', $result);
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function processShowReturnsCorrectResponseForUnknownIssueNumber()
66
    {
67
        $this->initCommandWithPayload(ForgeCommand::class, [
68
            'user' => 'U54321',
69
            'text' => 'forge:show 99999',
70
        ]);
71
        $result = $this->command->process();
72
        static::assertEquals('Sorry not found!', $result);
73
    }
74
75
    /**
76
     * @test
77
     * @dataProvider showTestDataProvider
78
     *
79
     * @param string $issueNumber
80
     */
81
    public function processShowReturnsCorrectResponseForValidIssueNumbers($issueNumber)
82
    {
83
        $this->initCommandWithPayload(ForgeCommand::class, [
84
            'user' => 'U54321',
85
            'text' => 'forge:show ' . $issueNumber,
86
        ]);
87
        $result = $this->command->process();
88
89
        static::assertStringStartsWith('*[Bug] Cannot edit media links with IE8* by _Michael Gotzen_', $result);
90
    }
91
}
92