|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Test\Message\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use Jalle19\StatusManager\Exception\UnhandledMessageException; |
|
6
|
|
|
use Jalle19\StatusManager\Message\Handler\DelegatesMessagesTrait; |
|
7
|
|
|
use Jalle19\StatusManager\Message\Handler\HandlerInterface; |
|
8
|
|
|
use Jalle19\StatusManager\Message\Request\InstancesRequest; |
|
9
|
|
|
use Jalle19\StatusManager\Message\Request\UsersRequest; |
|
10
|
|
|
use Jalle19\StatusManager\Message\Response\UsersResponse; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Ratchet\ConnectionInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class HandlerTest |
|
16
|
|
|
* @package Jalle19\StatusManager\Test\Message\Handler |
|
17
|
|
|
* @copyright Copyright © Sam Stenvall 2016- |
|
18
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class HandlerTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
use DelegatesMessagesTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var HandlerInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $_handler; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ConnectionInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $_sender; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @inheritdoc |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function setUp(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->_handler = new DummyHandler(); |
|
42
|
|
|
$this->_sender = new DummySender(); |
|
43
|
|
|
|
|
44
|
|
|
$this->registerMessageHandler($this->_handler); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Check that the message is properly handled |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testDelegateMessage() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->assertInstanceOf(UsersResponse::class, |
|
54
|
|
|
$this->tryDelegateMessage(new UsersRequest('foo'), $this->_sender)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function testFailedDelegation() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->expectException(UnhandledMessageException::class); |
|
61
|
|
|
$this->tryDelegateMessage(new InstancesRequest(), $this->_sender); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|