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() |
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, ['checkCircleCiBuild']); |
|
|
|
|
35
|
|
|
$this->check->setRequestClient($this->client); |
36
|
|
|
|
37
|
|
|
$suite = (new CheckSuite)->setRepositorySlug('foo/bar'); |
38
|
|
|
$this->check->setSuite($suite); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testTravisFetchFailure() |
42
|
|
|
{ |
43
|
|
|
$this->client->method('getBody')->willReturn(false); |
44
|
|
|
$this->check->run(); |
45
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testTravisNotFoundFailure() |
49
|
|
|
{ |
50
|
|
|
$this->client->method('getBody')->willReturn('{ |
51
|
|
|
"file": "not found" |
52
|
|
|
}'); |
53
|
|
|
$this->check->run(); |
54
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testTravisSuccessful() |
58
|
|
|
{ |
59
|
|
|
$this->client->method('getBody')->willReturn('{ |
60
|
|
|
"last_build_result": 0 |
61
|
|
|
}'); |
62
|
|
|
$this->check->run(); |
63
|
|
|
$this->assertTrue($this->check->getSuccessful()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testTravisUnsuccessful() |
67
|
|
|
{ |
68
|
|
|
$this->client->method('getBody')->willReturn('{ |
69
|
|
|
"last_build_result": 255 |
70
|
|
|
}'); |
71
|
|
|
$this->check->run(); |
72
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testTravisDefaultReturn() |
76
|
|
|
{ |
77
|
|
|
$this->client->method('getBody')->willReturn('{ |
78
|
|
|
"unrelated": "information" |
79
|
|
|
}'); |
80
|
|
|
$this->check->run(); |
81
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGuzzleThrowsException() |
85
|
|
|
{ |
86
|
|
|
$this->client->method('getBody')->will($this->throwException(new Exception)); |
87
|
|
|
$this->check->run(); |
88
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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..