ChimpifyCampaignTest::getNewMailChimpMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
use \Mockery as Mockery;
4
use \DrewM\MailChimp\MailChimp;
5
6
class ChimpifyCampaignTest 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 testGetMailChimpTemplates()
15
    {
16
        $chimpifyCampaign = new ChimpifyCampaign();
17
18
        $mailChimp = $this->getNewMailChimpMock();
19
        $mailChimp
20
            ->shouldReceive('get')
21
            ->with('templates')
22
            ->once();
23
        $mailChimp
24
            ->shouldReceive('success')
25
            ->withNoArgs()
26
            ->once();
27
28
        try {
29
            $chimpifyCampaign->getMailChimpTemplates($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<ChimpifyCampaignTest>.

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('get')
37
            ->with('templates')
38
            ->once()
39
            ->andReturn([
40
                'templates' => [
41
                    [
42
                        'type' => 'user',
43
                        'name' => 'Template One',
44
                    ],
45
                    [
46
                        'type' => 'preset',
47
                        'name' => 'Template Two',
48
                    ],
49
                ],
50
            ]);
51
        $mailChimp
52
            ->shouldReceive('success')
53
            ->withNoArgs()
54
            ->once()
55
            ->andReturn(true);
56
57
        $result = $chimpifyCampaign->getMailChimpTemplates($mailChimp);
58
59
        $this->assertInstanceOf('ArrayList', $result);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<ChimpifyCampaignTest>.

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

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...
61
    }
62
63
    protected function getNewMailChimpMock()
64
    {
65
        return Mockery::mock(
66
            '\DrewM\MailChimp\MailChimp',
67
            ['abc123abc123abc123abc123abc123-us1']
68
        );
69
    }
70
}
71