1
|
|
|
<?php |
2
|
|
|
namespace Checkdomain\Comodo\Tests; |
3
|
|
|
|
4
|
|
|
use Checkdomain\Comodo\CommunicationAdapter; |
5
|
|
|
use Checkdomain\Comodo\ImapExtension; |
6
|
|
|
use Checkdomain\Comodo\ImapHelper; |
7
|
|
|
use Checkdomain\Comodo\ImapAdapter; |
8
|
|
|
use Checkdomain\Comodo\Model\Account; |
9
|
|
|
use Checkdomain\Comodo\Util; |
10
|
|
|
use GuzzleHttp\Client; |
11
|
|
|
use Psr\Http\Message\ResponseInterface; |
12
|
|
|
use Psr\Http\Message\StreamInterface; |
13
|
|
|
use Zend\Mail\Storage\Folder; |
14
|
|
|
|
15
|
|
|
abstract class AbstractTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapAdapter |
19
|
|
|
*/ |
20
|
|
|
protected function createImapAdapter() |
21
|
|
|
{ |
22
|
|
|
$imapAdapter = new ImapAdapter(); |
23
|
|
|
$imapAdapter->setInstance($this->createImapExtension()); |
|
|
|
|
24
|
|
|
|
25
|
|
|
return $imapAdapter; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapExtension |
30
|
|
|
*/ |
31
|
|
|
protected function createImapExtension() |
32
|
|
|
{ |
33
|
|
|
$imapExtension = $this |
34
|
|
|
->getMockBuilder(ImapExtension::class) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->disableOriginalClone() |
37
|
|
|
->getMock(); |
38
|
|
|
|
39
|
|
|
$imapExtension |
40
|
|
|
->expects($this->any()) |
41
|
|
|
->method('getFolders') |
42
|
|
|
->will($this->returnValue([$this->createZendImapStorageFolder()])); |
43
|
|
|
|
44
|
|
|
$imapExtension |
45
|
|
|
->expects($this->any()) |
46
|
|
|
->method('selectFolder') |
47
|
|
|
->will($this->returnValue(true)); |
48
|
|
|
|
49
|
|
|
return $imapExtension; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Zend\Mail\Storage\Folder |
54
|
|
|
*/ |
55
|
|
|
protected function createZendImapStorageFolder() |
56
|
|
|
{ |
57
|
|
|
return $this |
58
|
|
|
->getMockBuilder(Folder::class) |
59
|
|
|
->setConstructorArgs(['INBOX']) |
60
|
|
|
->disableOriginalConstructor() |
61
|
|
|
->disableOriginalClone() |
62
|
|
|
->getMock(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* little helper to create the util class |
67
|
|
|
* |
68
|
|
|
* @param Client $client |
69
|
|
|
* |
70
|
|
|
* @return Util |
71
|
|
|
*/ |
72
|
|
|
protected function createUtil(Client $client = null) |
73
|
|
|
{ |
74
|
|
|
$imapHelper = $this->createImapHelper(); |
75
|
|
|
$imapAdapter = $this->createImapAdapter(); |
76
|
|
|
$communicationAdapter = new CommunicationAdapter(new Account('test_user', 'test_password')); |
77
|
|
|
|
78
|
|
|
if ($client != null) { |
79
|
|
|
$communicationAdapter->setClient($client); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return new Util($communicationAdapter, $imapAdapter, $imapHelper); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapHelper |
87
|
|
|
*/ |
88
|
|
|
public function createImapHelper() |
89
|
|
|
{ |
90
|
|
|
return $this |
91
|
|
|
->getMockBuilder(ImapHelper::class) |
92
|
|
|
->disableOriginalConstructor() |
93
|
|
|
->disableOriginalClone() |
94
|
|
|
->disableAutoload() |
95
|
|
|
->getMock(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Creates a class to simulate Requests, and return response String for testing purposes |
100
|
|
|
* |
101
|
|
|
* @param $responseString |
102
|
|
|
* |
103
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\GuzzleHttp\Client |
104
|
|
|
*/ |
105
|
|
|
protected function createGuzzleClient($responseString) |
106
|
|
|
{ |
107
|
|
|
$client = $this->createMock(Client::class); |
108
|
|
|
$response = $this->createMock(ResponseInterface::class); |
109
|
|
|
$body = $this->createMock(StreamInterface::class); |
110
|
|
|
|
111
|
|
|
$body |
112
|
|
|
->expects($this->any()) |
113
|
|
|
->method('getContents') |
114
|
|
|
->will($this->returnValue($responseString)); |
115
|
|
|
|
116
|
|
|
$response |
117
|
|
|
->expects($this->any()) |
118
|
|
|
->method('getBody') |
119
|
|
|
->will($this->returnValue($body)); |
120
|
|
|
|
121
|
|
|
$client |
122
|
|
|
->expects($this->any()) |
123
|
|
|
->method('request') |
124
|
|
|
->will($this->returnValue($response)); |
125
|
|
|
|
126
|
|
|
return $client; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.