|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\ModuleRatings\Tests\Check\CIPassingCheck; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use SilverStripe\ModuleRatings\Check\CIPassingCheck; |
|
8
|
|
|
use SilverStripe\ModuleRatings\CheckSuite; |
|
9
|
|
|
|
|
10
|
|
|
class CircleCITest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Client |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $client; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var CIPassingCheck |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $check; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$this->client = $this->getMockBuilder(Client::class) |
|
|
|
|
|
|
27
|
|
|
->setMethods(['get', 'getBody']) |
|
28
|
|
|
->getMock(); |
|
29
|
|
|
|
|
30
|
|
|
// Mock get to return client, we can then mock the last call easily |
|
31
|
|
|
$this->client->method('get')->willReturn($this->client); |
|
32
|
|
|
|
|
33
|
|
|
$this->check = $this->getMock(CIPassingCheck::class, ['checkTravisBuild']); |
|
|
|
|
|
|
34
|
|
|
$this->check->expects($this->once())->method('checkTravisBuild')->willReturn(false); |
|
35
|
|
|
$this->check->setRequestClient($this->client); |
|
36
|
|
|
|
|
37
|
|
|
$suite = (new CheckSuite)->setRepositorySlug('foo/bar'); |
|
38
|
|
|
$this->check->setSuite($suite); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testCircleFetchFailure() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->client->method('getBody')->willReturn(false); |
|
44
|
|
|
$this->check->run(); |
|
45
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testCircleNotFoundFailure() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->client->method('getBody')->willReturn('{ |
|
51
|
|
|
"message": "Project not found" |
|
52
|
|
|
}'); |
|
53
|
|
|
$this->check->run(); |
|
54
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testCircleSuccessful() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->client->method('getBody')->willReturn('[ |
|
60
|
|
|
{"failed": false}, |
|
61
|
|
|
{"failed": false}, |
|
62
|
|
|
{"failed": true} |
|
63
|
|
|
]'); |
|
64
|
|
|
$this->check->run(); |
|
65
|
|
|
$this->assertTrue($this->check->getSuccessful()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testCircleUnsuccessful() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->client->method('getBody')->willReturn('{ |
|
71
|
|
|
{"failed": true}, |
|
72
|
|
|
{"failed": false}, |
|
73
|
|
|
{"failed": true} |
|
74
|
|
|
}'); |
|
75
|
|
|
$this->check->run(); |
|
76
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testCircleDefaultReturn() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->client->method('getBody')->willReturn('{ |
|
82
|
|
|
"unrelated": "information" |
|
83
|
|
|
}'); |
|
84
|
|
|
$this->check->run(); |
|
85
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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..