1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Mremi\Flowdock library. |
5
|
|
|
* |
6
|
|
|
* (c) Rémi Marseille <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mremi\Flowdock\Tests\Api\Push; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\Psr7\Response; |
15
|
|
|
|
16
|
|
|
use Mremi\Flowdock\Api\Push\TeamInboxMessage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Tests the TeamInboxMessage class |
20
|
|
|
* |
21
|
|
|
* @author Rémi Marseille <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class TeamInboxMessageTest extends BaseMessageTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->message = new TeamInboxMessage; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function testGetData() |
37
|
|
|
{ |
38
|
|
|
$this->message |
|
|
|
|
39
|
|
|
->setSource('source') |
40
|
|
|
->setFromAddress('[email protected]') |
41
|
|
|
->setSubject('subject') |
42
|
|
|
->setContent('Hello world!') |
43
|
|
|
->setFromName('mremi') |
44
|
|
|
->setReplyTo('[email protected]') |
45
|
|
|
->setProject('project') |
46
|
|
|
->setFormat('html') |
47
|
|
|
->addTag('tag1') |
48
|
|
|
->addTag('tag2') |
49
|
|
|
->setLink('http://www.flowdock.com/') |
50
|
|
|
->setResponse(new Response(200)); |
51
|
|
|
|
52
|
|
|
$expected = array( |
53
|
|
|
'source' => $this->message->getSource(), |
|
|
|
|
54
|
|
|
'from_address' => $this->message->getFromAddress(), |
|
|
|
|
55
|
|
|
'subject' => $this->message->getSubject(), |
|
|
|
|
56
|
|
|
'content' => $this->message->getContent(), |
57
|
|
|
'from_name' => $this->message->getFromName(), |
|
|
|
|
58
|
|
|
'reply_to' => $this->message->getReplyTo(), |
|
|
|
|
59
|
|
|
'project' => $this->message->getProject(), |
|
|
|
|
60
|
|
|
'format' => $this->message->getFormat(), |
|
|
|
|
61
|
|
|
'tags' => $this->message->getTags(), |
62
|
|
|
'link' => $this->message->getLink(), |
|
|
|
|
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->assertEquals($expected, $this->message->getData()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function testToArray() |
72
|
|
|
{ |
73
|
|
|
$this->message |
|
|
|
|
74
|
|
|
->setSource('source') |
75
|
|
|
->setFromAddress('[email protected]') |
76
|
|
|
->setSubject('subject') |
77
|
|
|
->setContent('Hello world!') |
78
|
|
|
->setFromName('mremi') |
79
|
|
|
->setReplyTo('[email protected]') |
80
|
|
|
->setProject('project') |
81
|
|
|
->setFormat('html') |
82
|
|
|
->addTag('tag1') |
83
|
|
|
->addTag('tag2') |
84
|
|
|
->setLink('http://www.flowdock.com/') |
85
|
|
|
->setResponse(new Response(200)); |
86
|
|
|
|
87
|
|
|
$expected = array( |
88
|
|
|
'source' => $this->message->getSource(), |
|
|
|
|
89
|
|
|
'from_address' => $this->message->getFromAddress(), |
|
|
|
|
90
|
|
|
'subject' => $this->message->getSubject(), |
|
|
|
|
91
|
|
|
'content' => $this->message->getContent(), |
92
|
|
|
'from_name' => $this->message->getFromName(), |
|
|
|
|
93
|
|
|
'reply_to' => $this->message->getReplyTo(), |
|
|
|
|
94
|
|
|
'project' => $this->message->getProject(), |
|
|
|
|
95
|
|
|
'format' => $this->message->getFormat(), |
|
|
|
|
96
|
|
|
'tags' => $this->message->getTags(), |
97
|
|
|
'link' => $this->message->getLink(), |
|
|
|
|
98
|
|
|
'response' => $this->message->getResponse(), |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->assertEquals($expected, $this->message->toArray()); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: