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
|
|
|
/** |
16
|
|
|
* Class AbstractTest |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapHelper |
22
|
|
|
*/ |
23
|
|
|
public function createImapHelper() |
24
|
|
|
{ |
25
|
|
|
return $this |
26
|
|
|
->getMockBuilder(ImapHelper::class) |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->disableOriginalClone() |
29
|
|
|
->disableAutoload() |
30
|
|
|
->getMock(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapAdapter |
35
|
|
|
*/ |
36
|
|
|
protected function createImapAdapter() |
37
|
|
|
{ |
38
|
|
|
$imapAdapter = new ImapAdapter(); |
39
|
|
|
$imapAdapter->setInstance($this->createImapExtension()); |
|
|
|
|
40
|
|
|
|
41
|
|
|
return $imapAdapter; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapExtension |
46
|
|
|
*/ |
47
|
|
|
protected function createImapExtension() |
48
|
|
|
{ |
49
|
|
|
$imapExtension = $this |
50
|
|
|
->getMockBuilder(ImapExtension::class) |
51
|
|
|
->disableOriginalConstructor() |
52
|
|
|
->disableOriginalClone() |
53
|
|
|
->getMock(); |
54
|
|
|
|
55
|
|
|
$imapExtension |
56
|
|
|
->expects($this->any()) |
57
|
|
|
->method('selectFolder') |
58
|
|
|
->will($this->returnValue(true)); |
59
|
|
|
|
60
|
|
|
return $imapExtension; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* little helper to create the util class |
65
|
|
|
* |
66
|
|
|
* @param Client $client |
67
|
|
|
* |
68
|
|
|
* @return Util |
69
|
|
|
*/ |
70
|
|
|
protected function createUtil(Client $client = null) |
71
|
|
|
{ |
72
|
|
|
$imapHelper = $this->createImapHelper(); |
73
|
|
|
$imapAdapter = $this->createImapAdapter(); |
74
|
|
|
$communicationAdapter = new CommunicationAdapter(new Account('test_user', 'test_password')); |
75
|
|
|
|
76
|
|
|
if ($client != null) { |
77
|
|
|
$communicationAdapter->setClient($client); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return new Util($communicationAdapter, $imapAdapter, $imapHelper); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Creates a class to simulate Requests, and return response String for testing purposes |
86
|
|
|
* |
87
|
|
|
* @param $responseString |
88
|
|
|
* |
89
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\GuzzleHttp\Client |
90
|
|
|
*/ |
91
|
|
|
protected function createGuzzleClient($responseString) |
92
|
|
|
{ |
93
|
|
|
$client = $this->getMockBuilder(Client::class)->getMock(); |
94
|
|
|
$response = $this->getMockBuilder(ResponseInterface::class)->getMock(); |
95
|
|
|
$body = $this->getMockBuilder(StreamInterface::class)->getMock(); |
96
|
|
|
|
97
|
|
|
$body |
98
|
|
|
->expects($this->any()) |
99
|
|
|
->method('getContents') |
100
|
|
|
->will($this->returnValue($responseString)); |
101
|
|
|
|
102
|
|
|
$response |
103
|
|
|
->expects($this->any()) |
104
|
|
|
->method('getBody') |
105
|
|
|
->will($this->returnValue($body)); |
106
|
|
|
|
107
|
|
|
$client |
108
|
|
|
->expects($this->any()) |
109
|
|
|
->method('request') |
110
|
|
|
->will($this->returnValue($response)); |
111
|
|
|
|
112
|
|
|
return $client; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
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.