FOSSology  4.4.0
Open Source License Compliance by Open Source Software
RepositoryApiTest.php
1 <?php
2 # SPDX-FileCopyrightText: © Fossology contributors
3 
4 # SPDX-License-Identifier: GPL-2.0-only
5 
7 
8 function time()
9 {
10  return 1535371200;
11 }
12 
17 class RepositoryApiTest extends \PHPUnit\Framework\TestCase
18 {
22 
29  protected function setUp() : void
30  {
31  $this->mockCurlRequest = \Mockery::mock('CurlRequest');
32 
33  $this->mockCurlRequest->shouldReceive('setOptions')->once()->with(array(
34  CURLOPT_HEADER => true,
35  CURLOPT_RETURNTRANSFER => true,
36  CURLOPT_HTTPHEADER => array('User-Agent: fossology'),
37  CURLOPT_TIMEOUT => 2,
38  ));
39  $this->mockCurlRequest->shouldReceive('execute')->once()
40  ->andReturn('HEADER{"key": "value"}');
41  $this->mockCurlRequest->shouldReceive('getInfo')->once()
42  ->with(CURLINFO_HEADER_SIZE)->andReturn(6);
43  $this->mockCurlRequest->shouldReceive('close')->once();
44  }
45 
50  public function tearDown() : void
51  {
52  \Mockery::close();
53  }
54 
62  public function testGetLatestRelease()
63  {
64  $mockCurlRequestServer = \Mockery::mock('CurlRequestService');
65  $mockCurlRequestServer->shouldReceive('create')->once()
66  ->with('https://api.github.com/repos/fossology/fossology/releases/latest')
67  ->andReturn($this->mockCurlRequest);
68  $repositoryApi = new RepositoryApi($mockCurlRequestServer);
69 
70  $this->assertEquals(array('key' => 'value'), $repositoryApi->getLatestRelease());
71  }
72 
80  public function testGetCommitsOfLastDays()
81  {
82  $mockCurlRequestServer = \Mockery::mock('CurlRequestServer');
83  $mockCurlRequestServer->shouldReceive('create')->once()
84  ->with('https://api.github.com/repos/fossology/fossology/commits?since=2018-06-28T12:00:00Z')
85  ->andReturn($this->mockCurlRequest);
86  $repositoryApi = new RepositoryApi($mockCurlRequestServer);
87 
88  $this->assertEquals(array('key' => 'value'), $repositoryApi->getCommitsOfLastDays(60));
89  }
90 }
testGetCommitsOfLastDays()
Test for RepositoryApi::getCommitsOfLastDays()
testGetLatestRelease()
Test for RepositoryApi::getLatestRelease()
Helper class to get the latest release and commits from GitHub API.
Utility functions for specific applications.