|
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 = array( |
|
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, $issueResponse, $issueResponseWithClosed |
|
78
|
|
|
); |
|
79
|
|
|
$curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
|
80
|
|
|
200, 200, 200 |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
// Fetch all linked reports |
|
84
|
|
|
$reports = $this->Reports->find( |
|
85
|
|
|
'all', |
|
86
|
|
|
array( |
|
87
|
|
|
'conditions' => array( |
|
88
|
|
|
'sourceforge_bug_id IS NOT NULL', |
|
89
|
|
|
'NOT' => array( |
|
90
|
|
|
'status' => 'resolved' |
|
91
|
|
|
) |
|
92
|
|
|
) |
|
93
|
|
|
) |
|
94
|
|
|
); |
|
95
|
|
|
$this->assertEquals(3, $reports->count()); |
|
96
|
|
|
|
|
97
|
|
|
$this->SyncGithubIssueStates->main(); |
|
98
|
|
|
|
|
99
|
|
|
// Fetch all linked reports |
|
100
|
|
|
$reports = $this->Reports->find( |
|
101
|
|
|
'all', |
|
102
|
|
|
array( |
|
103
|
|
|
'conditions' => array( |
|
104
|
|
|
'sourceforge_bug_id IS NOT NULL', |
|
105
|
|
|
'NOT' => array( |
|
106
|
|
|
'status' => 'resolved' |
|
107
|
|
|
) |
|
108
|
|
|
) |
|
109
|
|
|
) |
|
110
|
|
|
); |
|
111
|
|
|
$this->assertEquals(2, $reports->count()); |
|
112
|
|
|
|
|
113
|
|
|
// Fetch all closed reports |
|
114
|
|
|
$reports = $this->Reports->find( |
|
115
|
|
|
'all', |
|
116
|
|
|
array( |
|
117
|
|
|
'conditions' => array( |
|
118
|
|
|
'sourceforge_bug_id IS NOT NULL', |
|
119
|
|
|
'status' => 'resolved' |
|
120
|
|
|
) |
|
121
|
|
|
) |
|
122
|
|
|
); |
|
123
|
|
|
$this->assertEquals(1, $reports->count()); |
|
124
|
|
|
$report5 = $this->Reports->get(4); |
|
125
|
|
|
$this->assertEquals('resolved', $report5->status); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: