FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
RepositoryApiTest.php
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 version 2 as published by the Free Software Foundation.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11 
12 You should have received a copy of the GNU General Public License along
13 with this program; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16 
18 
19 function time()
20 {
21  return 1535371200;
22 }
23 
28 class RepositoryApiTest extends \PHPUnit\Framework\TestCase
29 {
33 
40  protected function setUp()
41  {
42  $this->mockCurlRequest = \Mockery::mock('CurlRequest');
43 
44  $this->mockCurlRequest->shouldReceive('setOptions')->once()->with(array(
45  CURLOPT_HEADER => true,
46  CURLOPT_RETURNTRANSFER => true,
47  CURLOPT_HTTPHEADER => array('User-Agent: fossology'),
48  CURLOPT_TIMEOUT => 2,
49  ));
50  $this->mockCurlRequest->shouldReceive('execute')->once()
51  ->andReturn('HEADER{"key": "value"}');
52  $this->mockCurlRequest->shouldReceive('getInfo')->once()
53  ->with(CURLINFO_HEADER_SIZE)->andReturn(6);
54  $this->mockCurlRequest->shouldReceive('close')->once();
55  }
56 
61  public function tearDown()
62  {
63  \Mockery::close();
64  }
65 
73  public function testGetLatestRelease()
74  {
75  $mockCurlRequestServer = \Mockery::mock('CurlRequestService');
76  $mockCurlRequestServer->shouldReceive('create')->once()
77  ->with('https://api.github.com/repos/fossology/fossology/releases/latest')
78  ->andReturn($this->mockCurlRequest);
79  $repositoryApi = new RepositoryApi($mockCurlRequestServer);
80 
81  $this->assertEquals(array('key' => 'value'), $repositoryApi->getLatestRelease());
82  }
83 
91  public function testGetCommitsOfLastDays()
92  {
93  $mockCurlRequestServer = \Mockery::mock('CurlRequestServer');
94  $mockCurlRequestServer->shouldReceive('create')->once()
95  ->with('https://api.github.com/repos/fossology/fossology/commits?since=2018-06-28T12:00:00Z')
96  ->andReturn($this->mockCurlRequest);
97  $repositoryApi = new RepositoryApi($mockCurlRequestServer);
98 
99  $this->assertEquals(array('key' => 'value'), $repositoryApi->getCommitsOfLastDays(60));
100  }
101 }
Helper class to get the latest release and commits from GitHub API.
Utility functions for specific applications.
testGetLatestRelease()
Test for RepositoryApi::getLatestRelease()
testGetCommitsOfLastDays()
Test for RepositoryApi::getCommitsOfLastDays()