assigning incompatible types to properties.
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(): void |
||
24 | { |
||
25 | parent::setUp(); |
||
26 | |||
27 | $this->client = $this->getMockBuilder(Client::class) |
||
0 ignored issues
–
show
|
|||
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) |
||
0 ignored issues
–
show
It seems like
$this->getMockBuilder(Si...avisBuild'))->getMock() of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type SilverStripe\ModuleRatings\Check\CIPassingCheck of property $check .
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..
Loading history...
|
|||
35 | ->setMethods(['checkTravisBuild']) |
||
36 | ->getMock(); |
||
37 | |||
38 | $this->check->expects($this->once())->method('checkTravisBuild')->willReturn(false); |
||
39 | $this->check->setRequestClient($this->client); |
||
40 | |||
41 | $suite = (new CheckSuite())->setRepositorySlug('foo/bar'); |
||
42 | $this->check->setSuite($suite); |
||
43 | } |
||
44 | |||
45 | public function testCircleFetchFailure() |
||
46 | { |
||
47 | $this->client->method('getBody')->willReturn(false); |
||
48 | $this->check->run(); |
||
49 | $this->assertFalse($this->check->getSuccessful()); |
||
50 | } |
||
51 | |||
52 | public function testCircleNotFoundFailure() |
||
53 | { |
||
54 | $this->client->method('getBody')->willReturn('{ |
||
55 | "message": "Project not found" |
||
56 | }'); |
||
57 | $this->check->run(); |
||
58 | $this->assertFalse($this->check->getSuccessful()); |
||
59 | } |
||
60 | |||
61 | public function testCircleSuccessful() |
||
62 | { |
||
63 | $this->client->method('getBody')->willReturn('[ |
||
64 | {"failed": false}, |
||
65 | {"failed": false}, |
||
66 | {"failed": true} |
||
67 | ]'); |
||
68 | $this->check->run(); |
||
69 | $this->assertTrue($this->check->getSuccessful()); |
||
70 | } |
||
71 | |||
72 | public function testCircleUnsuccessful() |
||
73 | { |
||
74 | $this->client->method('getBody')->willReturn('{ |
||
75 | {"failed": true}, |
||
76 | {"failed": false}, |
||
77 | {"failed": true} |
||
78 | }'); |
||
79 | $this->check->run(); |
||
80 | $this->assertFalse($this->check->getSuccessful()); |
||
81 | } |
||
82 | |||
83 | public function testCircleDefaultReturn() |
||
84 | { |
||
85 | $this->client->method('getBody')->willReturn('{ |
||
86 | "unrelated": "information" |
||
87 | }'); |
||
88 | $this->check->run(); |
||
89 | $this->assertFalse($this->check->getSuccessful()); |
||
90 | } |
||
91 | |||
92 | public function testGuzzleThrowsException() |
||
93 | { |
||
94 | $this->client->method('getBody')->will($this->throwException(new Exception())); |
||
95 | $this->check->run(); |
||
96 | $this->assertFalse($this->check->getSuccessful()); |
||
97 | } |
||
98 | } |
||
99 |
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..