Completed
Push — master ( 214aa8...a8ef68 )
by Loz
04:54
created

testSendMessageExceptionClosesHandles()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 18
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
            [
64
                [
65
                    'filename' => 'filename.jpg',
66
                    'contents' => 'abcdefg'
67
                ]
68
            ], // attachments
69
            [
70
                'X-Custom-Header' => 'foo',
71
                'Cc' => '[email protected]',
72
                'Bcc' => '[email protected]'
73
            ] // headers
74
        ];
75
    }
76
77 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...
78
    {
79
        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...
80
81
        $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...
82
        $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...
83
            ->method('sendMessage')
84
            ->with(
85
                $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...
86
                $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...
87
                $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...
88
                $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...
89
                $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...
90
                $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...
91
                $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...
92
            );
93
94
        $mailer->sendPlain($to, $from, $subject, $plainContent, $attachments, $headers);
95
    }
96
97 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...
98
    {
99
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
100
101
        $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...
102
        $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...
103
            ->method('sendMessage')
104
            ->with(
105
                $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...
106
                $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...
107
                $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...
108
                $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...
109
                $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...
110
                $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...
111
                $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...
112
            );
113
114
        $mailer->sendHTML($to, $from, $subject, $content, $attachments, $headers, $plainContent);
115
    }
116
117
    public function testSendMessage()
118
    {
119
        $domain = 'http://testdomain.com';
120
        Config::inst()->update('Kinglozzer\SilverStripeMailgunner\Mailer', 'api_domain', $domain);
121
122
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
123
124
        $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...
125
        // We expect that sendMessage() will fetch the full message text from the builder
126
        $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...
127
            ->method('getMessage')
128
            ->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...
129
130
        $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...
131
        // We expect that sendMessage() will fetch the message builder from the Mailgun client, and
132
        // we use this point to inject our mock message builder
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('MessageBuilder')
135
            ->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...
136
        // We expect that Mailer::sendMessage() will trigger Mailgun::sendMessage() with the
137
        // domain set in config, and the prepared message and attachments
138
         $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...
139
            ->method('sendMessage')
140
            ->with(
141
                $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...
142
                $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...
143
                $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...
144
            );
145
146
        $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...
147
            'Kinglozzer\SilverStripeMailgunner\Mailer',
148
            ['getMailgunClient', 'buildMessage', 'prepareAttachments', 'closeTempFileHandles']
149
        );
150
        // We inject our mock Mailgun client while asserting that sendMessage() does request it
151
        $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...
152
            ->method('getMailgunClient')
153
            ->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...
154
        // We expect that sendMessage() will pass everything off to the buildMessage() method
155
        $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...
156
            ->method('buildMessage')
157
            ->with(
158
                $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...
159
                $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...
160
                $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...
161
                $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...
162
                $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...
163
                $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...
164
                $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...
165
            );
166
        // We've got attachments, so we assert that sendMessage() passes them off to
167
        // prepareAttachments() and specify a mock "prepared" return value
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('prepareAttachments')
170
            ->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...
171
            ->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...
172
        // Assert that the mailer attempts to close any remaining open file handles
173
        $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...
174
            ->method('closeTempFileHandles');
175
176
        // Let's go!
177
        $this->invokeMethod(
178
            $mailer,
179
            'sendMessage',
180
            [$to, $from, $subject, $content, $plainContent, $attachments, $headers]
181
        );
182
    }
183
184
    /**
185
     * @expectedException Exception
186
     */
187
    public function testSendMessageExceptionClosesHandles()
188
    {
189
        list($to, $from, $subject, $content, $plainContent, $attachments, $headers) = $this->getMockEmail();
190
191
        $client = $this->getMock('Mailgun\Mailgun', ['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...
192
        // Make our mock client trigger an exception
193
        $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...
194
            ->method('sendMessage')
195
            ->will($this->throwException(new \Exception));
0 ignored issues
show
Bug introduced by
The method throwException() 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...
196
197
        $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...
198
            'Kinglozzer\SilverStripeMailgunner\Mailer',
199
            ['getMailgunClient', 'closeTempFileHandles']
200
        );
201
        // Inject our mock Mailgun client
202
        $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...
203
            ->method('getMailgunClient')
204
            ->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...
205
        // Assert that the exception that the client throws triggers closing open file handles
206
        $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...
207
            ->method('closeTempFileHandles');
208
209
        $this->invokeMethod(
210
            $mailer,
211
            'sendMessage',
212
            [$to, $from, $subject, $content, $plainContent, $attachments, $headers]
213
        );
214
    }
215
216
    public function testBuildMessage()
217
    {
218
        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...
219
220
        $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...
221
        $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...
222
            ->method('addToRecipient')
223
            ->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...
224
225
        $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...
226
            ->method('setFromAddress')
227
            ->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...
228
229
        $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...
230
            ->method('setSubject')
231
            ->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...
232
233
        $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...
234
            ->method('setHtmlBody')
235
            ->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...
236
237
        $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...
238
            ->method('setTextBody')
239
            ->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...
240
241
        $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...
242
            ->method('addCcRecipient')
243
            ->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...
244
245
        $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...
246
            ->method('addBccRecipient')
247
            ->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...
248
249
        $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...
250
            ->method('addCustomHeader')
251
            ->with(
252
                $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...
253
                $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...
254
            );
255
256
        $this->invokeMethod(
257
            new Mailer,
258
            'buildMessage',
259
            [$messageBuilder, $to, $from, $subject, $content, $plainContent, $headers]
260
        );
261
    }
262
263
    public function testPrepareAttachments()
264
    {
265
        $attachments = [
266
            ['filename' => 'test1.jpg', 'contents' => 'abcdefg'],
267
            ['filename' => 'test2.jpg', 'contents' => 'hijklmn']
268
        ];
269
270
        $expected = [
271
            'attachment' => [
272
                ['filePath' => 'tmp/test1.jpg', 'remoteName' => 'test1.jpg'],
273
                ['filePath' => 'tmp/test2.jpg', 'remoteName' => 'test2.jpg']
274
            ]
275
        ];
276
277
        $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...
278
        $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...
279
            ->method('writeToTempFile')
280
            ->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...
281
            ->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...
282
        $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...
283
            ->method('writeToTempFile')
284
            ->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...
285
            ->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...
286
287
        $prepared =  $this->invokeMethod($mailer, 'prepareAttachments', [$attachments]);
288
        $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...
289
    }
290
291
    public function testWriteToTempFile()
292
    {
293
        $contents = 'test file contents';
294
        $mailer = new Mailer;
295
        $tempFile = $this->invokeMethod($mailer, 'writeToTempFile', [$contents]);
296
297
        $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...
298
299
        // Assert that the stream and temp file path are stored
300
        $reflection = new \ReflectionClass(get_class($mailer));
301
        $property = $reflection->getProperty('tempFileHandles');
302
        $property->setAccessible(true);
303
        $fileHandles = $property->getValue($mailer);
304
305
        $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...
306
307
        // Test the contents of the stream
308
        $handle = $fileHandles[0]['handle'];
309
        rewind($handle);
310
        $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...
311
        $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...
312
    }
313
314
    public function testCloseTempFileHandles()
315
    {
316
        $mailer = new Mailer;
317
        $tempFile = tempnam(sys_get_temp_dir(), 'SS_MG_TESTS_TMP');
318
        $fileHandle = fopen($tempFile, 'w');
319
        fwrite($fileHandle, 'test data');
320
        $handleData = ['handle' => $fileHandle, 'path' => $tempFile];
321
322
        $reflection = new \ReflectionClass(get_class($mailer));
323
        $property = $reflection->getProperty('tempFileHandles');
324
        $property->setAccessible(true);
325
        $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...
326
327
        $this->invokeMethod($mailer, 'closeTempFileHandles');
328
329
        $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...
330
        $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...
331
        $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...
332
    }
333
}
334