1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ModuleRatings\Tests\Check; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use SilverStripe\ModuleRatings\Check\CIPassingCheck; |
9
|
|
|
use SilverStripe\ModuleRatings\CheckSuite; |
10
|
|
|
|
11
|
|
|
class TravisTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Client |
15
|
|
|
*/ |
16
|
|
|
protected $client; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var CIPassingCheck |
20
|
|
|
*/ |
21
|
|
|
protected $check; |
22
|
|
|
|
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
$this->client = $this->getMockBuilder(Client::class) |
|
|
|
|
28
|
|
|
->setMethods(['get', 'getBody']) |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
// Mock get to return client, we can then mock the last call easily |
32
|
|
|
$this->client->method('get')->will($this->returnSelf()); |
33
|
|
|
|
34
|
|
|
$this->check = $this->getMockBuilder(CIPassingCheck::class) |
|
|
|
|
35
|
|
|
->setMethods(['checkCircleCiBuild']) |
36
|
|
|
->getMock(); |
37
|
|
|
$this->check->setRequestClient($this->client); |
38
|
|
|
|
39
|
|
|
$suite = (new CheckSuite())->setRepositorySlug('foo/bar'); |
40
|
|
|
$this->check->setSuite($suite); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testTravisFetchFailure() |
44
|
|
|
{ |
45
|
|
|
$this->client->method('getBody')->willReturn(false); |
|
|
|
|
46
|
|
|
$this->check->run(); |
47
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testTravisNotFoundFailure() |
51
|
|
|
{ |
52
|
|
|
$this->client->method('getBody')->willReturn('{ |
53
|
|
|
"file": "not found" |
54
|
|
|
}'); |
55
|
|
|
$this->check->run(); |
56
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testTravisSuccessful() |
60
|
|
|
{ |
61
|
|
|
$this->client->method('getBody')->willReturn('{ |
62
|
|
|
"last_build_result": 0 |
63
|
|
|
}'); |
64
|
|
|
$this->check->run(); |
65
|
|
|
$this->assertTrue($this->check->getSuccessful()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testTravisUnsuccessful() |
69
|
|
|
{ |
70
|
|
|
$this->client->method('getBody')->willReturn('{ |
71
|
|
|
"last_build_result": 255 |
72
|
|
|
}'); |
73
|
|
|
$this->check->run(); |
74
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testTravisDefaultReturn() |
78
|
|
|
{ |
79
|
|
|
$this->client->method('getBody')->willReturn('{ |
80
|
|
|
"unrelated": "information" |
81
|
|
|
}'); |
82
|
|
|
$this->check->run(); |
83
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGuzzleThrowsException() |
87
|
|
|
{ |
88
|
|
|
$this->client->method('getBody')->will($this->throwException(new Exception())); |
|
|
|
|
89
|
|
|
$this->check->run(); |
90
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.