-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathRunCommandTest.php
87 lines (64 loc) · 2.51 KB
/
RunCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Enqueue\AsyncCommand\Tests;
use Enqueue\AsyncCommand\RunCommand;
use PHPUnit\Framework\TestCase;
class RunCommandTest extends TestCase
{
public function testShouldImplementJsonSerializableInterface()
{
$rc = new \ReflectionClass(RunCommand::class);
$this->assertTrue($rc->implementsInterface(\JsonSerializable::class));
}
public function testShouldBeFinal()
{
$rc = new \ReflectionClass(RunCommand::class);
$this->assertTrue($rc->isFinal());
}
public function testShouldAllowGetCommandSetInConstructor()
{
$command = new RunCommand('theCommand');
$this->assertSame('theCommand', $command->getCommand());
}
public function testShouldReturnEmptyArrayByDefaultOnGetArguments()
{
$command = new RunCommand('aCommand');
$this->assertSame([], $command->getArguments());
}
public function testShouldReturnEmptyArrayByDefaultOnGetOptions()
{
$command = new RunCommand('aCommand');
$this->assertSame([], $command->getOptions());
}
public function testShouldReturnArgumentsSetInConstructor()
{
$command = new RunCommand('aCommand', ['theArgument' => 'theValue']);
$this->assertSame(['theArgument' => 'theValue'], $command->getArguments());
}
public function testShouldReturnOptionsSetInConstructor()
{
$command = new RunCommand('aCommand', [], ['theOption' => 'theValue']);
$this->assertSame(['theOption' => 'theValue'], $command->getOptions());
}
public function testShouldSerializeAndUnserialzeCommand()
{
$command = new RunCommand(
'theCommand',
['theArgument' => 'theValue'],
['theOption' => 'theValue']
);
$jsonCommand = json_encode($command);
// guard
$this->assertNotEmpty($jsonCommand);
$unserializedCommand = RunCommand::jsonUnserialize($jsonCommand);
$this->assertInstanceOf(RunCommand::class, $unserializedCommand);
$this->assertSame('theCommand', $unserializedCommand->getCommand());
$this->assertSame(['theArgument' => 'theValue'], $unserializedCommand->getArguments());
$this->assertSame(['theOption' => 'theValue'], $unserializedCommand->getOptions());
}
public function testThrowExceptionIfInvalidJsonGiven()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The malformed json given.');
RunCommand::jsonUnserialize('{]');
}
}