Issues (61)

tests/Message/SmsHandlerTest.php (3 issues)

1
<?php
2
/**
3
 * File: SmsHandlerTest.php
4
 *
5
 * @author      Maciej SÅ‚awik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Test\Message;
10
11
use MSlwk\FreshMail\Handler\Message\SmsHandler;
12
use MSlwk\FreshMail\Tests\BaseTest;
13
use PHPUnit\Framework\TestCase;
14
use MSlwk\FreshMail\Error\ErrorHandler;
15
use MSlwk\FreshMail\Exception\Message\FreshMailSmsException;
16
17
/**
18
 * Class SmsHandlerTest
19
 *
20
 * @package MSlwk\FreshMail\Test\Message
21
 */
22
class SmsHandlerTest extends TestCase
23
{
24
    use BaseTest;
25
26
    /**
27
     * @param $sendRequestReturnValue
28
     * @return \PHPUnit_Framework_MockObject_MockObject
0 ignored issues
show
The type PHPUnit_Framework_MockObject_MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
     */
30
    public function getSmsHandlerMock($sendRequestReturnValue)
31
    {
32
        $smsHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Message\SmsHandler')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

32
        $smsHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Message\SmsHandler')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
33
            ->setConstructorArgs([new ErrorHandler(), '', ''])
34
            ->setMethods(['sendRequest'])
35
            ->getMock();
36
37
        $smsHandler->expects($this->once())
38
            ->method('sendRequest')
39
            ->will($this->returnValue($sendRequestReturnValue));
40
41
        return $smsHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $smsHandler returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type PHPUnit_Framework_MockObject_MockObject.
Loading history...
42
    }
43
44
    public function testSmsSuccessfullySent()
45
    {
46
        $smsHandler = $this->getSmsHandlerMock('{"status":"OK"}');
47
        $returnValue = $smsHandler->sendSingleSms(
48
            '+48987654321',
49
            'Test',
50
            'Test',
51
            'Test',
52
            false
53
        );
54
        self::assertNull($returnValue);
55
    }
56
57
    public function testApiEndpoint()
58
    {
59
        $accountCreateHandler = new SmsHandler(new ErrorHandler(), '', '');
60
        $expectedApiEndpoint = '/rest/sms/send';
61
        $returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler);
62
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
63
    }
64
65
    public function testIncorrectNumber()
66
    {
67
        $smsHandler = $this->getSmsHandlerMock(
68
            '{"errors":[{ "message":"Incorrect GSM number", "code":"1101" }], "status":"errors"}'
69
        );
70
        $this->expectException(FreshMailSmsException::class);
71
        $smsHandler->sendSingleSms('+48987654321', 'Test');
72
    }
73
74
    public function testEmptyContent()
75
    {
76
        $smsHandler = $this->getSmsHandlerMock(
77
            '{"errors":[{ "message":"Empty SMS content", "code":"1102" }], "status":"errors"}'
78
        );
79
        $this->expectException(FreshMailSmsException::class);
80
        $smsHandler->sendSingleSms('+48987654321', 'Test');
81
    }
82
83
    public function testContentTooLong()
84
    {
85
        $smsHandler = $this->getSmsHandlerMock(
86
            '{"errors":[{ "message":"SMS content too long", "code":"1103" }], "status":"errors"}'
87
        );
88
        $this->expectException(FreshMailSmsException::class);
89
        $smsHandler->sendSingleSms('+48987654321', 'Test');
90
    }
91
92
    public function testContentTooLongWithSpecialChars()
93
    {
94
        $smsHandler = $this->getSmsHandlerMock(
95
            '{"errors":[{ "message":"SMS content too long", "code":"1104" }], "status":"errors"}'
96
        );
97
        $this->expectException(FreshMailSmsException::class);
98
        $smsHandler->sendSingleSms('+48987654321', 'Test');
99
    }
100
101
    public function testIncorrectSender()
102
    {
103
        $smsHandler = $this->getSmsHandlerMock(
104
            '{"errors":[{ "message":"Incorrect sender", "code":"1105" }], "status":"errors"}'
105
        );
106
        $this->expectException(FreshMailSmsException::class);
107
        $smsHandler->sendSingleSms('+48987654321', 'Test');
108
    }
109
110
    public function testSenderNotVerified()
111
    {
112
        $smsHandler = $this->getSmsHandlerMock(
113
            '{"errors":[{ "message":"SMS sender not verified", "code":"1106" }], "status":"errors"}'
114
        );
115
        $this->expectException(FreshMailSmsException::class);
116
        $smsHandler->sendSingleSms('+48987654321', 'Test');
117
    }
118
119
    public function testIncorrectEncoding()
120
    {
121
        $smsHandler = $this->getSmsHandlerMock(
122
            '{"errors":[{ "message":"Incorrect encoding", "code":"1107" }], "status":"errors"}'
123
        );
124
        $this->expectException(FreshMailSmsException::class);
125
        $smsHandler->sendSingleSms('+48987654321', 'Test');
126
    }
127
128
    public function testSingleSmsTooLong()
129
    {
130
        $smsHandler = $this->getSmsHandlerMock(
131
            '{"errors":[{ "message":"Content too long for forced single message", "code":"1108" }], "status":"errors"}'
132
        );
133
        $this->expectException(FreshMailSmsException::class);
134
        $smsHandler->sendSingleSms('+48987654321', 'Test');
135
    }
136
137
    public function testSingleSmsToLongWithSpecialChars()
138
    {
139
        $smsHandler = $this->getSmsHandlerMock(
140
            '{"errors":[{ "message":"Content too long for forced single message", "code":"1109" }], "status":"errors"}'
141
        );
142
        $this->expectException(FreshMailSmsException::class);
143
        $smsHandler->sendSingleSms('+48987654321', 'Test');
144
    }
145
146
    public function testContractNotSigned()
147
    {
148
        $smsHandler = $this->getSmsHandlerMock(
149
            '{"errors":[{ "message":"You must sign a contract to send SMS", "code":"1150" }], "status":"errors"}'
150
        );
151
        $this->expectException(FreshMailSmsException::class);
152
        $smsHandler->sendSingleSms('+48987654321', 'Test');
153
    }
154
155
}
156