Passed
Pull Request — master (#9)
by Robbie
07:42 queued 06:17
created

TravisTest::testTravisFetchFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(Gu... 'getBody'))->getMock() of type PHPUnit_Framework_MockObject_MockObject is incompatible with the declared type GuzzleHttp\Client of property $client.

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...
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']);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMock(SilverStr...('checkCircleCiBuild')) 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...
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::getMock() has been deprecated: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
        $this->check = /** @scrutinizer ignore-deprecated */ $this->getMock(CIPassingCheck::class, ['checkCircleCiBuild']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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