1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ModuleRatings\Tests\Check; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SilverStripe\ModuleRatings\Check\CIPassingCheck; |
8
|
|
|
use SilverStripe\ModuleRatings\CheckSuite; |
9
|
|
|
|
10
|
|
|
class TravisTest 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')->will($this->returnSelf()); |
32
|
|
|
|
33
|
|
|
$this->check = $this->getMock(CIPassingCheck::class, ['checkCircleCiBuild']); |
|
|
|
|
34
|
|
|
$this->check->setRequestClient($this->client); |
35
|
|
|
|
36
|
|
|
$suite = (new CheckSuite)->setRepositorySlug('foo/bar'); |
37
|
|
|
$this->check->setSuite($suite); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testTravisFetchFailure() |
41
|
|
|
{ |
42
|
|
|
$this->client->method('getBody')->willReturn(false); |
43
|
|
|
$this->check->run(); |
44
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testTravisNotFoundFailure() |
48
|
|
|
{ |
49
|
|
|
$this->client->method('getBody')->willReturn('{ |
50
|
|
|
"file": "not found" |
51
|
|
|
}'); |
52
|
|
|
$this->check->run(); |
53
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testTravisSuccessful() |
57
|
|
|
{ |
58
|
|
|
$this->client->method('getBody')->willReturn('{ |
59
|
|
|
"last_build_result": 0 |
60
|
|
|
}'); |
61
|
|
|
$this->check->run(); |
62
|
|
|
$this->assertTrue($this->check->getSuccessful()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testTravisUnsuccessful() |
66
|
|
|
{ |
67
|
|
|
$this->client->method('getBody')->willReturn('{ |
68
|
|
|
"last_build_result": 255 |
69
|
|
|
}'); |
70
|
|
|
$this->check->run(); |
71
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testTravisDefaultReturn() |
75
|
|
|
{ |
76
|
|
|
$this->client->method('getBody')->willReturn('{ |
77
|
|
|
"unrelated": "information" |
78
|
|
|
}'); |
79
|
|
|
$this->check->run(); |
80
|
|
|
$this->assertFalse($this->check->getSuccessful()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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..