Completed
Push — master ( 1ff499...32025a )
by Loz
06:06 queued 04:18
created

MailerTest::testSetGetMailgunClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Kinglozzer\SilverStripeMailgunner\Tests;
4
5
use Kinglozzer\SilverStripeMailgunner\Mailer;
6
use Config;
7
use Email;
8
use Injector;
9
10
class MailerTest extends \SapphireTest
11
{
12
    /**
13
     * @param object &$object
14
     * @param string $methodName
15
     * @param array $parameters
16
     * @return mixed
17
     */
18
    protected function invokeMethod(&$object, $methodName, array $parameters = [])
19
    {
20
        $reflection = new \ReflectionClass(get_class($object));
21
        $method = $reflection->getMethod($methodName);
22
        $method->setAccessible(true);
23
24
        return $method->invokeArgs($object, $parameters);
25
    }
26
27
    /**
28
     * Simple test to check that registering the mailer as an Injector service
29
     * will make it the default mailer used by Email
30
     */
31
    public function testMailerRegistrationWithEmail()
32
    {
33
        Injector::nest();
34
        Injector::inst()->registerService(new Mailer, 'Mailer');
0 ignored issues
show
Documentation introduced by
new \Kinglozzer\SilverStripeMailgunner\Mailer() is of type object<Kinglozzer\SilverStripeMailgunner\Mailer>, but the function expects a object<stdClass>.

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...
35
        $this->assertInstanceOf('Kinglozzer\SilverStripeMailgunner\Mailer', Email::mailer());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
36
37
        Injector::unnest();
38
        $this->assertNotInstanceOf('Kinglozzer\SilverStripeMailgunner\Mailer', Email::mailer());
0 ignored issues
show
Bug introduced by
The method assertNotInstanceOf() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
39
    }
40
41
    public function testSetGetMailgunClient()
42
    {
43
        $mailer = new Mailer;
44
        $mockClient = $this->getMock('Mailgun\Mailgun');
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
45
46
        $this->assertInstanceOf('Mailgun\Mailgun', $mailer->getMailgunClient());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
47
48
        $mailer->setMailgunClient($mockClient);
49
        $this->assertSame($mockClient, $mailer->getMailgunClient());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    protected function getMockEmail()
56
    {
57
        return [
58
            '[email protected]', // to
59
            '[email protected]', // from
60
            'Important question', // subject
61
            '<p>How much foo could a foo bar baz if a baz bam could bar foo?</p>', // html content
62
            'How much foo could a foo bar baz if a baz bam could bar foo?', // plain text content
63
            ['filename.jpg'], // attachments
64
            [
65
                'X-Custom-Header' => 'foo',
66
                'Cc' => '[email protected]',
67
                'Bcc' => '[email protected]'
68
            ] // headers
69
        ];
70
    }
71
72 View Code Duplication
    public function testSendPlain()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
       list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
0 ignored issues
show
Unused Code introduced by
The assignment to $content is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
75
76
        $mailer = $this->getMock('Kinglozzer\SilverStripeMailgunner\Mailer', ['sendMessage']);
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
77
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
78
            ->method('sendMessage')
79
            ->with(
80
                $this->equalTo($to),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
81
                $this->equalTo($from),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
82
                $this->equalTo($subject),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
83
                $this->equalTo(''),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
84
                $this->equalTo($plainContent),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
85
                $this->equalTo($attachments),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
86
                $this->equalTo($headers)
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
87
            );
88
89
        $mailer->sendPlain($to, $from, $subject, $plainContent, $attachments, $headers);
90
    }
91
92 View Code Duplication
    public function testSendHTML()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
95
96
        $mailer = $this->getMock('Kinglozzer\SilverStripeMailgunner\Mailer', ['sendMessage']);
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
97
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
98
            ->method('sendMessage')
99
            ->with(
100
                $this->equalTo($to),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
101
                $this->equalTo($from),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
102
                $this->equalTo($subject),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
103
                $this->equalTo($content),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
104
                $this->equalTo($plainContent),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
105
                $this->equalTo($attachments),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
106
                $this->equalTo($headers)
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
107
            );
108
109
        $mailer->sendHTML($to, $from, $subject, $content, $attachments, $headers, $plainContent);
110
    }
111
112
    public function testSendMessage()
113
    {
114
        $domain = 'http://testdomain.com';
115
        Config::inst()->update('Kinglozzer\SilverStripeMailgunner\Mailer', 'api_domain', $domain);
116
117
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
118
119
        $messageBuilder = $this->getMock('Mailgun\Messages\MessageBuilder', ['getMessage']);
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
120
        // We expect that sendMessage() will fetch the full message text from the builder
121
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
122
            ->method('getMessage')
123
            ->will($this->returnValue('test message'));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
124
125
        $client = $this->getMock('Mailgun\Mailgun', ['MessageBuilder', 'sendMessage']);
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
126
        // We expect that sendMessage() will fetch the message builder from the Mailgun client, and
127
        // we use this point to inject our mock message builder
128
        $client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
129
            ->method('MessageBuilder')
130
            ->will($this->returnValue($messageBuilder));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
131
        // We expect that Mailer::sendMessage() will trigger Mailgun::sendMessage() with the
132
        // domain set in config, and the prepared message and attachments
133
         $client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
134
            ->method('sendMessage')
135
            ->with(
136
                $this->equalTo($domain),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
137
                $this->equalTo('test message'),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
138
                $this->equalTo(['preparedattachments'])
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
139
            );
140
141
        $mailer = $this->getMock(
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
142
            'Kinglozzer\SilverStripeMailgunner\Mailer',
143
            ['getMailgunClient', 'buildMessage', 'prepareAttachments', 'closeTempFileHandles']
144
        );
145
        // We inject our mock Mailgun client while asserting that sendMessage() does request it
146
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
147
            ->method('getMailgunClient')
148
            ->will($this->returnValue($client));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
149
        // We expect that sendMessage() will pass everything off to the buildMessage() method
150
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
151
            ->method('buildMessage')
152
            ->with(
153
                $this->equalTo($messageBuilder),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
154
                $this->equalTo($to),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
155
                $this->equalTo($from),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
156
                $this->equalTo($subject),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
157
                $this->equalTo($content),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
158
                $this->equalTo($plainContent),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
159
                $this->equalTo($headers)
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
160
            );
161
        // We've got attachments, so we assert that sendMessage() passes them off to
162
        // prepareAttachments() and specify a mock "prepared" return value
163
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
164
            ->method('prepareAttachments')
165
            ->with( $this->equalTo($attachments))
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
166
            ->will($this->returnValue(['preparedattachments']));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
167
        // Assert that the mailer attempts to close any remaining open file handles
168
        $mailer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
169
            ->method('closeTempFileHandles');
170
171
        // Let's go!
172
        $this->invokeMethod(
173
            $mailer,
174
            'sendMessage',
175
            [$to, $from, $subject, $content, $plainContent, $attachments, $headers]
176
        );
177
    }
178
179
    public function testBuildMessage()
180
    {
181
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
0 ignored issues
show
Unused Code introduced by
The assignment to $attachments is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
182
183
        $messageBuilder = $this->getMock('Mailgun\Messages\MessageBuilder');
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
184
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
185
            ->method('addToRecipient')
186
            ->with($this->equalTo($to));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
187
188
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
189
            ->method('setFromAddress')
190
            ->with($this->equalTo($from));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
191
192
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
193
            ->method('setSubject')
194
            ->with($this->equalTo($subject));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
195
196
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
197
            ->method('setHtmlBody')
198
            ->with($this->equalTo($content));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
199
200
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
201
            ->method('setTextBody')
202
            ->with($this->equalTo($plainContent));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
203
204
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
205
            ->method('addCcRecipient')
206
            ->with($this->equalTo($headers['Cc']));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
207
208
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
209
            ->method('addBccRecipient')
210
            ->with($this->equalTo($headers['Bcc']));
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
211
212
        $messageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
213
            ->method('addCustomHeader')
214
            ->with(
215
                $this->equalTo('X-Custom-Header'),
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
216
                $this->equalTo('foo')
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
217
            );
218
219
        $this->invokeMethod(
220
            new Mailer,
221
            'buildMessage',
222
            [$messageBuilder, $to, $from, $subject, $content, $plainContent, $headers]
223
        );
224
    }
225
226
    public function testPrepareAttachments()
227
    {
228
        $attachments = [
229
            ['filename' => 'test1.jpg', 'contents' => 'abcdefg'],
230
            ['filename' => 'test2.jpg', 'contents' => 'hijklmn']
231
        ];
232
233
        $expected = [
234
            'attachment' => [
235
                ['filePath' => 'tmp/test1.jpg', 'remoteName' => 'test1.jpg'],
236
                ['filePath' => 'tmp/test2.jpg', 'remoteName' => 'test2.jpg']
237
            ]
238
        ];
239
240
        $mailer = $this->getMock('Kinglozzer\SilverStripeMailgunner\Mailer', ['writeToTempFile']);
0 ignored issues
show
Bug introduced by
The method getMock() does not exist on Kinglozzer\SilverStripeMailgunner\Tests\MailerTest. Did you maybe mean getMockEmail()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
241
        $mailer->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method at() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
242
            ->method('writeToTempFile')
243
            ->with($this->equalTo('abcdefg'))
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
244
            ->will($this->returnValue('tmp/test1.jpg'));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
245
        $mailer->expects($this->at(1))
0 ignored issues
show
Bug introduced by
The method at() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
246
            ->method('writeToTempFile')
247
            ->with($this->equalTo('hijklmn'))
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
248
            ->will($this->returnValue('tmp/test2.jpg'));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
249
250
        $prepared =  $this->invokeMethod($mailer, 'prepareAttachments', [$attachments]);
251
        $this->assertEquals($expected, $prepared);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
252
    }
253
254
    public function testWriteToTempFile()
255
    {
256
        $contents = 'test file contents';
257
        $mailer = new Mailer;
258
        $tempFile = $this->invokeMethod($mailer, 'writeToTempFile', [$contents]);
259
260
        $this->assertEquals($contents, file_get_contents($tempFile));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
261
262
        // Assert that the stream and temp file path are stored
263
        $reflection = new \ReflectionClass(get_class($mailer));
264
        $property = $reflection->getProperty('tempFileHandles');
265
        $property->setAccessible(true);
266
        $fileHandles = $property->getValue($mailer);
267
268
        $this->assertNotEmpty($fileHandles);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
269
270
        // Test the contents of the stream
271
        $handle = $fileHandles[0]['handle'];
272
        rewind($handle);
273
        $this->assertEquals($contents, fread($handle, filesize($fileHandles[0]['path'])));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
274
        $this->assertEquals($tempFile, $fileHandles[0]['path']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
275
    }
276
277
    public function testCloseTempFileHandles()
278
    {
279
        $mailer = new Mailer;
280
        $tempFile = tempnam(sys_get_temp_dir(), 'SS_MG_TESTS_TMP');
281
        $fileHandle = fopen($tempFile, 'w');
282
        fwrite($fileHandle, 'test data');
283
        $handleData = ['handle' => $fileHandle, 'path' => $tempFile];
284
285
        $reflection = new \ReflectionClass(get_class($mailer));
286
        $property = $reflection->getProperty('tempFileHandles');
287
        $property->setAccessible(true);
288
        $fileHandles = $property->setValue($mailer, [$handleData]);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fileHandles is correct as $property->setValue($mailer, array($handleData)) (which targets ReflectionProperty::setValue()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$fileHandles is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
289
290
        $this->invokeMethod($mailer, 'closeTempFileHandles');
291
292
        $this->assertEmpty($property->getValue($mailer));
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
293
        $this->assertFalse(file_exists($tempFile));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
294
        $this->assertEquals('Unknown', get_resource_type($fileHandle));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Kinglozzer\Silver...unner\Tests\MailerTest>.

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...
295
    }
296
}
297