|
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 Doctrine\DBAL\Configuration; |
|
13
|
|
|
use Doctrine\DBAL\DriverManager; |
|
14
|
|
|
use T3Bot\Commands\BeerCommand; |
|
15
|
|
|
use T3Bot\Tests\Unit\BaseCommandTestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class BeerCommandTest. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** @noinspection LongInheritanceChainInspection */ |
|
22
|
|
|
class BeerCommandTest extends BaseCommandTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
View Code Duplication |
public function tearDown() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
DriverManager::getConnection($GLOBALS['config']['db'], new Configuration()) |
|
30
|
|
|
->delete('beers', [ |
|
31
|
|
|
'to_user' => 'U23456', |
|
32
|
|
|
'from_user' => 'U12345', |
|
33
|
|
|
]); |
|
34
|
|
|
parent::tearDown(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @test |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function processForReturnsCorrectResponseForWrongUsername() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
43
|
|
|
'user' => 'U54321', |
|
44
|
|
|
'text' => 'beer:for max', |
|
45
|
|
|
]); |
|
46
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
47
|
|
|
static::assertEquals('*Sorry, a username must start with a @-sign:*', $result); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function processForReturnsCorrectResponseForCorrectUsername() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
56
|
|
|
'user' => 'U12345', |
|
57
|
|
|
'text' => 'beer:for <@U23456>', |
|
58
|
|
|
]); |
|
59
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
60
|
|
|
static::assertStringStartsWith('Yeah, one more :t3beer: for <@U23456>', $result); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
*/ |
|
66
|
|
View Code Duplication |
public function processForReturnsCorrectResponseForCorrectUsernameWithin24Hours() |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
69
|
|
|
'user' => 'U12345', |
|
70
|
|
|
'text' => 'beer:for <@U23456>', |
|
71
|
|
|
]); |
|
72
|
|
|
$this->command->process(); |
|
|
|
|
|
|
73
|
|
|
$result = $this->command->process(); |
|
74
|
|
|
static::assertStringStartsWith('You spend one :t3beer: to <@U23456> within in last 24 hours. Too much beer is unhealthy ;)', $result); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @test |
|
79
|
|
|
*/ |
|
80
|
|
|
public function processAllReturnsCorrectResponse() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
83
|
|
|
'user' => 'U12345', |
|
84
|
|
|
'text' => 'beer:all', |
|
85
|
|
|
]); |
|
86
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
87
|
|
|
static::assertRegExp('/Yeah, ([0-9]*) :t3beer: spend to all people/', $result); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @test |
|
92
|
|
|
*/ |
|
93
|
|
|
public function processTop10ReturnsCorrectResponse() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
96
|
|
|
'user' => 'U12345', |
|
97
|
|
|
'text' => 'beer:top10', |
|
98
|
|
|
]); |
|
99
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
100
|
|
|
static::assertStringStartsWith('*Yeah, here are the TOP 10*', $result); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @test |
|
105
|
|
|
*/ |
|
106
|
|
|
public function processStatsReturnsCorrectResponseForCorrectUsername() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
109
|
|
|
'user' => 'U12345', |
|
110
|
|
|
'text' => 'beer:stats <@U23456>', |
|
111
|
|
|
]); |
|
112
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
113
|
|
|
static::assertRegExp('/<@U23456> has received ([0-9]*) :t3beer: so far/', $result); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @test |
|
118
|
|
|
*/ |
|
119
|
|
View Code Duplication |
public function processStatsReturnsCorrectResponseForinvalidUsername() |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
$this->initCommandWithPayload(BeerCommand::class, [ |
|
122
|
|
|
'user' => 'U12345', |
|
123
|
|
|
'text' => 'beer:stats foo', |
|
124
|
|
|
]); |
|
125
|
|
|
$result = $this->command->process(); |
|
|
|
|
|
|
126
|
|
|
static::assertEquals('*Sorry, a username must start with a @-sign:*', $result); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
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.