|
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\BaseMessageInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Tests the common methods |
|
20
|
|
|
* |
|
21
|
|
|
* @author Rémi Marseille <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class BaseMessageTest extends \PHPUnit_Framework_TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var BaseMessageInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $message; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Initializes message used by tests |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
throw new \RuntimeException('You must define a setUp method to initialize the message.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Cleanups message |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function tearDown() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->message = null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Tests a fresh message |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testFreshMessage() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertInstanceOf(get_class($this->message), call_user_func(array(get_class($this->message), 'create'))); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertTrue(is_array($this->message->getTags())); |
|
54
|
|
|
$this->assertCount(0, $this->message->getTags()); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertTrue(is_array($this->message->getResponseBody())); |
|
57
|
|
|
$this->assertCount(0, $this->message->getResponseBody()); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertNull($this->message->getResponseMessage()); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertTrue(is_array($this->message->getResponseErrors())); |
|
62
|
|
|
$this->assertCount(0, $this->message->getResponseErrors()); |
|
63
|
|
|
$this->assertFalse($this->message->hasResponseErrors()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Tests to add some tags to a message |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testAddTags() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->message->addTag('#hello'); |
|
72
|
|
|
$this->assertCount(1, $this->message->getTags()); |
|
73
|
|
|
$this->assertEquals(array('#hello'), $this->message->getTags()); |
|
74
|
|
|
|
|
75
|
|
|
$this->message->addTag('#world'); |
|
76
|
|
|
$this->assertCount(2, $this->message->getTags()); |
|
77
|
|
|
$this->assertEquals(array('#hello', '#world'), $this->message->getTags()); |
|
78
|
|
|
|
|
79
|
|
|
$this->message->clearTags(); |
|
80
|
|
|
$this->assertTrue(is_array($this->message->getTags())); |
|
81
|
|
|
$this->assertCount(0, $this->message->getTags()); |
|
82
|
|
|
|
|
83
|
|
|
$this->message->setTags(array('#foo', '#bar')); |
|
84
|
|
|
$this->assertCount(2, $this->message->getTags()); |
|
85
|
|
|
$this->assertEquals(array('#foo', '#bar'), $this->message->getTags()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Tests a valid response |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testValidResponse() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->message->setResponse(new Response(200, [], '{"dummy": "ok"}')); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals(array('dummy' => 'ok'), $this->message->getResponseBody()); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertNull($this->message->getResponseMessage()); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertTrue(is_array($this->message->getResponseErrors())); |
|
100
|
|
|
$this->assertCount(0, $this->message->getResponseErrors()); |
|
101
|
|
|
$this->assertFalse($this->message->hasResponseErrors()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Tests an invalid response |
|
106
|
|
|
*/ |
|
107
|
|
|
public function testInvalidResponse() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->message->setResponse(new Response(400, [], '{"message": "Validation error", "errors": {"content": ["can\'t be blank"]}}')); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertEquals(array('message' => 'Validation error', 'errors' => array('content' => array('can\'t be blank'))), $this->message->getResponseBody()); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertEquals('Validation error', $this->message->getResponseMessage()); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertTrue(is_array($this->message->getResponseErrors())); |
|
116
|
|
|
$this->assertEquals(array('content' => array('can\'t be blank')), $this->message->getResponseErrors()); |
|
117
|
|
|
$this->assertTrue($this->message->hasResponseErrors()); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Tests the getData method |
|
122
|
|
|
*/ |
|
123
|
|
|
abstract public function testGetData(); |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Tests the toArray method |
|
127
|
|
|
*/ |
|
128
|
|
|
abstract public function testToArray(); |
|
129
|
|
|
} |
|
130
|
|
|
|