77use App \Test \Fixture \ReportsFixture ;
88use Cake \Command \Command ;
99use Cake \Console \TestSuite \ConsoleIntegrationTestTrait ;
10+ use Cake \Http \TestSuite \HttpClientTrait ;
1011use Cake \TestSuite \TestCase ;
1112use 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