Passed
Push — master ( fcb909...cb681d )
by Robbie
02:26
created

testValueOfDoRequestIsReturned()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BringYourOwnIdeas\Maintenance\Tests\Util;
4
5
use BringYourOwnIdeas\Maintenance\Util\SupportedAddonsLoader;
6
use SilverStripe\Dev\SapphireTest;
7
8
class SupportedAddonsLoaderTest extends SapphireTest
9
{
10
    /**
11
     * @var SupportedAddonsLoader
12
     */
13
    protected $loader;
14
15
    protected function setUp()
16
    {
17
        parent::setUp();
18
19
        $this->loader = $this->getMockBuilder(SupportedAddonsLoader::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(Br...doRequest'))->getMock() of type PHPUnit_Framework_MockObject_MockObject is incompatible with the declared type BringYourOwnIdeas\Mainte...l\SupportedAddonsLoader of property $loader.

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...
20
            ->setMethods(['doRequest'])
21
            ->getMock();
22
    }
23
24
    public function testCallsSupportedAddonsEndpoint()
25
    {
26
        $this->loader->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on BringYourOwnIdeas\Mainte...l\SupportedAddonsLoader. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

26
        $this->loader->/** @scrutinizer ignore-call */ 
27
                       expects($this->once())
Loading history...
27
            ->method('doRequest')
28
            ->with('addons.silverstripe.org/api/supported-addons', function () {
29
                // no-op
30
            });
31
32
        $this->loader->getAddonNames();
33
    }
34
35
    public function testCallbackReturnsAddonsFromBody()
36
    {
37
        $this->loader->expects($this->once())
38
            ->method('doRequest')
39
            ->with($this->isType('string'), $this->isType('callable'))
40
            ->will($this->returnArgument(1));
41
42
        $result = $this->loader->getAddonNames();
43
        $mockResponse = [
44
            'foo' => 'bar',
45
            'addons' => 'baz',
46
        ];
47
48
        $this->assertSame('baz', $result($mockResponse));
49
    }
50
51
    public function testValueOfDoRequestIsReturned()
52
    {
53
        $this->loader->expects($this->once())
54
            ->method('doRequest')
55
            ->willReturn('hello world');
56
57
        $this->assertSame('hello world', $this->loader->getAddonNames());
58
    }
59
}
60