1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: SpamTestHandlerTest.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Test\SpamTest; |
10
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Handler\SpamTest\SpamTestHandler; |
12
|
|
|
use MSlwk\FreshMail\Tests\BaseTest; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use MSlwk\FreshMail\Error\ErrorHandler; |
15
|
|
|
use MSlwk\FreshMail\Exception\SpamTest\FreshMailSpamTestException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SpamTestHandlerTest |
19
|
|
|
* |
20
|
|
|
* @package MSlwk\FreshMail\Test\SpamTest |
21
|
|
|
*/ |
22
|
|
|
class SpamTestHandlerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
use BaseTest; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $sendRequestReturnValue |
28
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function getSpamTestHandlerMock($sendRequestReturnValue) |
31
|
|
|
{ |
32
|
|
|
$spamTestHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\SpamTest\SpamTestHandler') |
|
|
|
|
33
|
|
|
->setConstructorArgs([new ErrorHandler(), '', '']) |
34
|
|
|
->setMethods(['sendRequest']) |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$spamTestHandler->expects($this->once()) |
38
|
|
|
->method('sendRequest') |
39
|
|
|
->will($this->returnValue($sendRequestReturnValue)); |
40
|
|
|
|
41
|
|
|
return $spamTestHandler; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSpamTestSuccessful() |
45
|
|
|
{ |
46
|
|
|
$expectedTestsFailed = ['test1']; |
47
|
|
|
$expectedScore = 3.2; |
48
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock('{"status":"OK","tests":' |
49
|
|
|
. json_encode($expectedTestsFailed) . ',"score":' . $expectedScore . '}'); |
50
|
|
|
$returnData = $spamTestHandler->spamCheck('Test', 'Test'); |
51
|
|
|
self::assertEquals($expectedTestsFailed, $returnData->tests); |
52
|
|
|
self::assertEquals($expectedScore, $returnData->score); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testApiEndpoint() |
56
|
|
|
{ |
57
|
|
|
$accountCreateHandler = new SpamTestHandler(new ErrorHandler(), '', ''); |
58
|
|
|
$expectedApiEndpoint = '/rest/spam_test/check'; |
59
|
|
|
$returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler); |
60
|
|
|
self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testEmptySubject() |
64
|
|
|
{ |
65
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock( |
66
|
|
|
'{"errors":[{ "message":"Empty subject", "code":"1901" }], "status":"errors"}' |
67
|
|
|
); |
68
|
|
|
$this->expectException(FreshMailSpamTestException::class); |
69
|
|
|
$spamTestHandler->spamCheck('Test', 'Test'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testIncorrectFromAddress() |
73
|
|
|
{ |
74
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock( |
75
|
|
|
'{"errors":[{ "message":"Incorrect from_address", "code":"1902" }], "status":"errors"}' |
76
|
|
|
); |
77
|
|
|
$this->expectException(FreshMailSpamTestException::class); |
78
|
|
|
$spamTestHandler->spamCheck('Test', 'Test'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testEmptyContent() |
82
|
|
|
{ |
83
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock( |
84
|
|
|
'{"errors":[{ "message":"Empty contect", "code":"1904" }], "status":"errors"}' |
85
|
|
|
); |
86
|
|
|
$this->expectException(FreshMailSpamTestException::class); |
87
|
|
|
$spamTestHandler->spamCheck('Test', 'Test'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testSystemError() |
91
|
|
|
{ |
92
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock( |
93
|
|
|
'{"errors":[{ "message":"Spam-test system error", "code":"1906" }], "status":"errors"}' |
94
|
|
|
); |
95
|
|
|
$this->expectException(FreshMailSpamTestException::class); |
96
|
|
|
$spamTestHandler->spamCheck('Test', 'Test'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testDailyLimitExceeded() |
100
|
|
|
{ |
101
|
|
|
$spamTestHandler = $this->getSpamTestHandlerMock( |
102
|
|
|
'{"errors":[{ "message":"Daily limit exceeded", "code":"1907" }], "status":"errors"}' |
103
|
|
|
); |
104
|
|
|
$this->expectException(FreshMailSpamTestException::class); |
105
|
|
|
$spamTestHandler->spamCheck('Test', 'Test'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths