Skip to content

Commit 6ab0139

Browse files
committed
Un mock sync github tests for curl calls, now use the client
1 parent 284051e commit 6ab0139

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/Command/SyncGithubIssueStatesCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function execute(Arguments $args, ConsoleIo $io)
8989
['scope' => 'cron_jobs']
9090
);
9191

92-
return self::CODE_ERROR;
92+
return self::CODE_SUCCESS;
9393
}
9494

9595
Log::error(
@@ -101,6 +101,6 @@ public function execute(Arguments $args, ConsoleIo $io)
101101
['scope' => 'cron_jobs']
102102
);
103103

104-
return self::CODE_SUCCESS;
104+
return self::CODE_ERROR;
105105
}
106106
}

tests/TestCase/Shell/SyncGithubIssueStatesShellTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Test\Fixture\ReportsFixture;
88
use Cake\Command\Command;
99
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
10+
use Cake\Http\TestSuite\HttpClientTrait;
1011
use Cake\TestSuite\TestCase;
1112
use phpmock\phpunit\PHPMock;
1213

@@ -23,6 +24,7 @@ class SyncGithubIssueStatesShellTest extends TestCase
2324
{
2425
use ConsoleIntegrationTestTrait;
2526
use PHPMock;
27+
use HttpClientTrait;
2628

2729
public function getFixtures(): array
2830
{
@@ -38,26 +40,24 @@ public function getFixtures(): array
3840
*/
3941
public function testExecute(): void
4042
{
43+
$repoPath = 'phpmyadmin/phpmyadmin';
4144
$Reports = $this->getTableLocator()->get('Reports');
42-
// Mock functions `curl_exec` and `curl_getinfo` in GithubApiComponent
43-
// so that we don't actually hit the Github Api
44-
$curlExecMock = $this->getFunctionMock('\App\Controller\Component', 'curl_exec');
45-
$curlGetInfoMock = $this->getFunctionMock('\App\Controller\Component', 'curl_getinfo');
46-
4745
$issueResponse = file_get_contents(TESTS . 'Fixture' . DS . 'issue_response.json');
4846
$decodedResponse = json_decode($issueResponse, true);
4947
$decodedResponse['state'] = 'closed';
5048
$issueResponseWithClosed = json_encode($decodedResponse);
5149

52-
$curlExecMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls(
53-
$issueResponse,
54-
$issueResponse,
55-
$issueResponseWithClosed
50+
$this->mockClientGet(
51+
'https://api.github.com/repos/' . $repoPath . '/issues/1',
52+
$this->newClientResponse(200, [], $issueResponse),
53+
);
54+
$this->mockClientGet(
55+
'https://api.github.com/repos/' . $repoPath . '/issues/2',
56+
$this->newClientResponse(200, [], $issueResponse),
5657
);
57-
$curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls(
58-
200,
59-
200,
60-
200
58+
$this->mockClientGet(
59+
'https://api.github.com/repos/' . $repoPath . '/issues/4',
60+
$this->newClientResponse(200, [], $issueResponseWithClosed),
6161
);
6262

6363
// Fetch all linked reports

0 commit comments

Comments
 (0)