ChimpifyRequestHandlerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 5 1
B testHandleMailChimpResponse() 0 40 2
A getNewMailChimpMock() 0 7 1
1
<?php
2
3
use \Mockery as Mockery;
4
use \DrewM\MailChimp\MailChimp;
5
6
class ChimpifyRequestHandlerTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    public function tearDown()
9
    {
10
        Mockery::close();
11
        parent::tearDown();
12
    }
13
14
    public function testHandleMailChimpResponse()
15
    {
16
        $chimpifyRequestHandler = new ChimpifyRequestHandler(null, null, null, null, null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<GridField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
null is of type null, but the function expects a object<GridField_URLHandler>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
null is of type null, but the function expects a object<DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
null is of type null, but the function expects a object<RequestHandler>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
18
        $mailChimp = $this->getNewMailChimpMock();
19
        $mailChimp
20
            ->shouldReceive('getLastResponse')
21
            ->withNoArgs()
22
            ->once();
23
        $mailChimp
24
            ->shouldReceive('success')
25
            ->withNoArgs()
26
            ->once();
27
28
        try {
29
            $chimpifyRequestHandler->handleMailChimpResponse($mailChimp);
30
        } catch (Exception $e) {
31
            $this->assertEquals('Error connecting to MailChimp API', $e->getMessage());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ChimpifyRequestHandlerTest>.

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...
32
        }
33
34
        $mailChimp = $this->getNewMailChimpMock();
35
        $mailChimp
36
            ->shouldReceive('getLastResponse')
37
            ->withNoArgs()
38
            ->once()
39
            ->andReturn([
40
                'body' => json_encode(['items' => [['id' => 1]]]),
41
            ]);
42
        $mailChimp
43
            ->shouldReceive('success')
44
            ->withNoArgs()
45
            ->once()
46
            ->andReturn(true);
47
48
        $result = $chimpifyRequestHandler->handleMailChimpResponse($mailChimp);
49
50
        $this->assertEquals(true, is_array($result));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ChimpifyRequestHandlerTest>.

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...
51
        $this->assertEquals(1, count($result['items']));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ChimpifyRequestHandlerTest>.

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...
52
        $this->assertEquals(1, $result['items'][0]['id']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ChimpifyRequestHandlerTest>.

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...
53
    }
54
55
    protected function getNewMailChimpMock()
56
    {
57
        return Mockery::mock(
58
            '\DrewM\MailChimp\MailChimp',
59
            ['abc123abc123abc123abc123abc123-us1']
60
        );
61
    }
62
}
63