|
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\ChatMessage; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Tests the ChatMessage class |
|
20
|
|
|
* |
|
21
|
|
|
* @author Rémi Marseille <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class ChatMessageTest extends BaseMessageTest |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->message = new ChatMessage; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testGetData() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->message |
|
|
|
|
|
|
39
|
|
|
->setContent('Hello world!') |
|
40
|
|
|
->setExternalUserName('mremi') |
|
41
|
|
|
->addTag('tag1') |
|
42
|
|
|
->addTag('tag2') |
|
43
|
|
|
->setMessageId(1) |
|
44
|
|
|
->setResponse(new Response(200)); |
|
45
|
|
|
|
|
46
|
|
|
$expected = array( |
|
47
|
|
|
'content' => $this->message->getContent(), |
|
48
|
|
|
'external_user_name' => $this->message->getExternalUserName(), |
|
|
|
|
|
|
49
|
|
|
'tags' => $this->message->getTags(), |
|
50
|
|
|
'message_id' => $this->message->getMessageId(), |
|
|
|
|
|
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals($expected, $this->message->getData()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testToArray() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->message |
|
|
|
|
|
|
62
|
|
|
->setContent('Hello world!') |
|
63
|
|
|
->setExternalUserName('mremi') |
|
64
|
|
|
->addTag('tag1') |
|
65
|
|
|
->addTag('tag2') |
|
66
|
|
|
->setMessageId(1) |
|
67
|
|
|
->setResponse(new Response(200)); |
|
68
|
|
|
|
|
69
|
|
|
$expected = array( |
|
70
|
|
|
'content' => $this->message->getContent(), |
|
71
|
|
|
'external_user_name' => $this->message->getExternalUserName(), |
|
|
|
|
|
|
72
|
|
|
'tags' => $this->message->getTags(), |
|
73
|
|
|
'message_id' => $this->message->getMessageId(), |
|
|
|
|
|
|
74
|
|
|
'response' => $this->message->getResponse(), |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals($expected, $this->message->toArray()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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: