Issues (25)

tests/Check/CIPassingCheck/TravisTest.php (6 issues)

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(): void
24
    {
25
        parent::setUp();
26
27
        $this->client = $this->getMockBuilder(Client::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

27
        $this->client = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(Client::class)

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...
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...
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
Documentation Bug introduced by
It seems like $this->getMockBuilder(Si...leCiBuild'))->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...
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

34
        $this->check = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(CIPassingCheck::class)

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...
35
            ->setMethods(['checkCircleCiBuild'])
36
            ->getMock();
37
        $this->check->setRequestClient($this->client);
38
39
        $suite = (new CheckSuite())->setRepositorySlug('foo/bar');
40
        $this->check->setSuite($suite);
41
    }
42
43
    public function testTravisFetchFailure()
44
    {
45
        $this->client->method('getBody')->willReturn(false);
0 ignored issues
show
The method willReturn() does not exist on GuzzleHttp\Promise\PromiseInterface. ( Ignorable by Annotation )

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

45
        $this->client->method('getBody')->/** @scrutinizer ignore-call */ willReturn(false);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        $this->check->run();
47
        $this->assertFalse($this->check->getSuccessful());
48
    }
49
50
    public function testTravisNotFoundFailure()
51
    {
52
        $this->client->method('getBody')->willReturn('{
53
            "file": "not found"
54
        }');
55
        $this->check->run();
56
        $this->assertFalse($this->check->getSuccessful());
57
    }
58
59
    public function testTravisSuccessful()
60
    {
61
        $this->client->method('getBody')->willReturn('{
62
            "last_build_result": 0
63
        }');
64
        $this->check->run();
65
        $this->assertTrue($this->check->getSuccessful());
66
    }
67
68
    public function testTravisUnsuccessful()
69
    {
70
        $this->client->method('getBody')->willReturn('{
71
            "last_build_result": 255
72
        }');
73
        $this->check->run();
74
        $this->assertFalse($this->check->getSuccessful());
75
    }
76
77
    public function testTravisDefaultReturn()
78
    {
79
        $this->client->method('getBody')->willReturn('{
80
            "unrelated": "information"
81
        }');
82
        $this->check->run();
83
        $this->assertFalse($this->check->getSuccessful());
84
    }
85
86
    public function testGuzzleThrowsException()
87
    {
88
        $this->client->method('getBody')->will($this->throwException(new Exception()));
0 ignored issues
show
The method will() does not exist on GuzzleHttp\Promise\PromiseInterface. ( Ignorable by Annotation )

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

88
        $this->client->method('getBody')->/** @scrutinizer ignore-call */ will($this->throwException(new Exception()));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
        $this->check->run();
90
        $this->assertFalse($this->check->getSuccessful());
91
    }
92
}
93