1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ModuleRatings\Tests\Check\CIPassingCheck; |
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 CircleCITest 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() |
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->getMock(CIPassingCheck::class, ['checkTravisBuild']); |
|
|
|
|
35
|
|
|
$this->check->expects($this->once())->method('checkTravisBuild')->willReturn(false); |
36
|
|
|
$this->check->setRequestClient($this->client); |
37
|
|
|
|
38
|
|
|
$suite = (new CheckSuite)->setRepositorySlug('foo/bar'); |
39
|
|
|
$this->check->setSuite($suite); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCircleFetchFailure() |
43
|
|
|
{ |
44
|
|
|
$this->client->method('getBody')->willReturn(false); |
45
|
|
|
$this->check->run(); |
46
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testCircleNotFoundFailure() |
50
|
|
|
{ |
51
|
|
|
$this->client->method('getBody')->willReturn('{ |
52
|
|
|
"message": "Project not found" |
53
|
|
|
}'); |
54
|
|
|
$this->check->run(); |
55
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCircleSuccessful() |
59
|
|
|
{ |
60
|
|
|
$this->client->method('getBody')->willReturn('[ |
61
|
|
|
{"failed": false}, |
62
|
|
|
{"failed": false}, |
63
|
|
|
{"failed": true} |
64
|
|
|
]'); |
65
|
|
|
$this->check->run(); |
66
|
|
|
$this->assertTrue($this->check->getSuccessful()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testCircleUnsuccessful() |
70
|
|
|
{ |
71
|
|
|
$this->client->method('getBody')->willReturn('{ |
72
|
|
|
{"failed": true}, |
73
|
|
|
{"failed": false}, |
74
|
|
|
{"failed": true} |
75
|
|
|
}'); |
76
|
|
|
$this->check->run(); |
77
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testCircleDefaultReturn() |
81
|
|
|
{ |
82
|
|
|
$this->client->method('getBody')->willReturn('{ |
83
|
|
|
"unrelated": "information" |
84
|
|
|
}'); |
85
|
|
|
$this->check->run(); |
86
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGuzzleThrowsException() |
90
|
|
|
{ |
91
|
|
|
$this->client->method('getBody')->will($this->throwException(new Exception)); |
92
|
|
|
$this->check->run(); |
93
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..