1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Dispatcher\Tests\Commands; |
4
|
|
|
|
5
|
|
|
use Nip\Dispatcher\Commands\Command; |
6
|
|
|
use Nip\Dispatcher\Tests\AbstractTest; |
7
|
|
|
use Nip\Http\Response\Response; |
8
|
|
|
use Nip\Request; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CommandTest |
12
|
|
|
* @package Nip\Dispatcher\Tests\Commands |
13
|
|
|
*/ |
14
|
|
|
class CommandTest extends AbstractTest |
15
|
|
|
{ |
16
|
|
|
public function testGetSetRequest() |
17
|
|
|
{ |
18
|
|
|
$command = new Command(); |
19
|
|
|
self::assertEquals(null, $command->getRequest()); |
20
|
|
|
self::assertFalse($command->hasRequest()); |
21
|
|
|
|
22
|
|
|
$request = new Request(); |
|
|
|
|
23
|
|
|
$command->setRequest($request); |
24
|
|
|
|
25
|
|
|
self::assertTrue($command->hasRequest()); |
26
|
|
|
self::assertEquals($request, $command->getRequest()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetSetResponse() |
30
|
|
|
{ |
31
|
|
|
$command = new Command(); |
32
|
|
|
self::assertEquals(null, $command->getReturn()); |
|
|
|
|
33
|
|
|
self::assertFalse($command->hasReturn()); |
34
|
|
|
|
35
|
|
|
$response = new Response(); |
36
|
|
|
$command->setReturn($response); |
37
|
|
|
self::assertTrue($command->hasReturn()); |
38
|
|
|
self::assertEquals($response, $command->getReturn()); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws \Exception |
43
|
|
|
*/ |
44
|
|
|
public function testActionGetParamWithActionStringSet() |
45
|
|
|
{ |
46
|
|
|
$command = new Command(); |
47
|
|
|
$command->setAction('Module@Controller::action'); |
48
|
|
|
self::assertEquals('Module@Controller::action', $command->getAction()); |
49
|
|
|
|
50
|
|
|
self::expectException(\Exception::class); |
|
|
|
|
51
|
|
|
$command->getActionParam('name'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
|
|
public function testActionGetParamWithActionEmpty() |
58
|
|
|
{ |
59
|
|
|
$command = new Command(); |
60
|
|
|
|
61
|
|
|
self::assertNull($command->getActionParam('name')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @throws \Exception |
66
|
|
|
*/ |
67
|
|
|
public function testActionSetParamWithActionStringSet() |
68
|
|
|
{ |
69
|
|
|
$command = new Command(); |
70
|
|
|
$command->setAction('Module@Controller::action'); |
71
|
|
|
|
72
|
|
|
self::expectException(\Exception::class); |
|
|
|
|
73
|
|
|
$command->setActionParam('name', 'value'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @throws \Exception |
78
|
|
|
*/ |
79
|
|
|
public function testActionSetParamWithActionEmpty() |
80
|
|
|
{ |
81
|
|
|
$command = new Command(); |
82
|
|
|
|
83
|
|
|
self::assertNull($command->getActionParam('name')); |
84
|
|
|
|
85
|
|
|
$command->setActionParam('name', 'value'); |
86
|
|
|
self::assertEquals('value', $command->getActionParam('name')); |
87
|
|
|
self::assertEquals(['name' => 'value'], $command->getAction()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|