1
|
|
|
<?php |
2
|
|
|
namespace App\Test\TestCase\Shell; |
3
|
|
|
|
4
|
|
|
use App\Shell\SyncGithubIssueStatesShell; |
5
|
|
|
use Cake\ORM\TableRegistry; |
6
|
|
|
use Cake\TestSuite\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* App\Shell\SyncGithubIssueStatesShell Test Case |
10
|
|
|
*/ |
11
|
|
|
class SyncGithubIssueStatesShellTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
use \phpmock\phpunit\PHPMock; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* ConsoleIo mock |
18
|
|
|
* |
19
|
|
|
* @var \Cake\Console\ConsoleIo|\PHPUnit_Framework_MockObject_MockObject |
20
|
|
|
*/ |
21
|
|
|
public $io; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Test subject |
25
|
|
|
* |
26
|
|
|
* @var \App\Shell\SyncGithubIssueStatesShell |
27
|
|
|
*/ |
28
|
|
|
public $SyncGithubIssueStates; |
29
|
|
|
|
30
|
|
|
public $fixtures = [ |
31
|
|
|
'app.Reports', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* setUp method |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function setUp() |
40
|
|
|
{ |
41
|
|
|
parent::setUp(); |
42
|
|
|
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); |
43
|
|
|
$this->SyncGithubIssueStates = new SyncGithubIssueStatesShell($this->io); |
|
|
|
|
44
|
|
|
$this->Reports = TableRegistry::get('Reports'); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* tearDown method |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function tearDown() |
53
|
|
|
{ |
54
|
|
|
unset($this->SyncGithubIssueStates); |
55
|
|
|
|
56
|
|
|
parent::tearDown(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test main method |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function testMain() |
65
|
|
|
{ |
66
|
|
|
// Mock functions `curl_exec` and `curl_getinfo` in GithubApiComponent |
67
|
|
|
// so that we don't actually hit the Github Api |
68
|
|
|
$curlExecMock = $this->getFunctionMock('\App\Controller\Component', 'curl_exec'); |
69
|
|
|
$curlGetInfoMock = $this->getFunctionMock('\App\Controller\Component', 'curl_getinfo'); |
70
|
|
|
|
71
|
|
|
$issueResponse = file_get_contents(TESTS . 'Fixture' . DS . 'issue_response.json'); |
72
|
|
|
$decodedResponse = json_decode($issueResponse, true); |
73
|
|
|
$decodedResponse['state'] = 'closed'; |
74
|
|
|
$issueResponseWithClosed = json_encode($decodedResponse); |
75
|
|
|
|
76
|
|
|
$curlExecMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
77
|
|
|
$issueResponse, |
78
|
|
|
$issueResponse, |
79
|
|
|
$issueResponseWithClosed |
80
|
|
|
); |
81
|
|
|
$curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
82
|
|
|
200, |
83
|
|
|
200, |
84
|
|
|
200 |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
// Fetch all linked reports |
88
|
|
|
$reports = $this->Reports->find( |
89
|
|
|
'all', |
90
|
|
|
[ |
91
|
|
|
'conditions' => [ |
92
|
|
|
'sourceforge_bug_id IS NOT NULL', |
93
|
|
|
'NOT' => [ |
94
|
|
|
'status' => 'resolved', |
95
|
|
|
] |
96
|
|
|
], |
97
|
|
|
] |
98
|
|
|
); |
99
|
|
|
$this->assertEquals(3, $reports->count()); |
100
|
|
|
|
101
|
|
|
$this->SyncGithubIssueStates->main(); |
102
|
|
|
|
103
|
|
|
// Fetch all linked reports |
104
|
|
|
$reports = $this->Reports->find( |
105
|
|
|
'all', |
106
|
|
|
[ |
107
|
|
|
'conditions' => [ |
108
|
|
|
'sourceforge_bug_id IS NOT NULL', |
109
|
|
|
'NOT' => [ |
110
|
|
|
'status' => 'resolved', |
111
|
|
|
] |
112
|
|
|
], |
113
|
|
|
] |
114
|
|
|
); |
115
|
|
|
$this->assertEquals(2, $reports->count()); |
116
|
|
|
|
117
|
|
|
// Fetch all closed reports |
118
|
|
|
$reports = $this->Reports->find( |
119
|
|
|
'all', |
120
|
|
|
[ |
121
|
|
|
'conditions' => [ |
122
|
|
|
'sourceforge_bug_id IS NOT NULL', |
123
|
|
|
'status' => 'resolved' |
124
|
|
|
], |
125
|
|
|
] |
126
|
|
|
); |
127
|
|
|
$this->assertEquals(1, $reports->count()); |
128
|
|
|
$report5 = $this->Reports->get(4); |
129
|
|
|
$this->assertEquals('resolved', $report5->status); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|