-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathCommandResultTest.php
69 lines (50 loc) · 1.98 KB
/
CommandResultTest.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
<?php
namespace Enqueue\AsyncCommand\Tests;
use Enqueue\AsyncCommand\CommandResult;
use PHPUnit\Framework\TestCase;
class CommandResultTest extends TestCase
{
public function testShouldImplementJsonSerializableInterface()
{
$rc = new \ReflectionClass(CommandResult::class);
$this->assertTrue($rc->implementsInterface(\JsonSerializable::class));
}
public function testShouldBeFinal()
{
$rc = new \ReflectionClass(CommandResult::class);
$this->assertTrue($rc->isFinal());
}
public function testShouldAllowGetExitCodeSetInConstructor()
{
$result = new CommandResult(123, '', '');
$this->assertSame(123, $result->getExitCode());
}
public function testShouldAllowGetOutputSetInConstructor()
{
$result = new CommandResult(0, 'theOutput', '');
$this->assertSame('theOutput', $result->getOutput());
}
public function testShouldAllowGetErrorOutputSetInConstructor()
{
$result = new CommandResult(0, '', 'theErrorOutput');
$this->assertSame('theErrorOutput', $result->getErrorOutput());
}
public function testShouldSerializeAndUnserialzeCommand()
{
$result = new CommandResult(123, 'theOutput', 'theErrorOutput');
$jsonCommand = json_encode($result);
// guard
$this->assertNotEmpty($jsonCommand);
$unserializedResult = CommandResult::jsonUnserialize($jsonCommand);
$this->assertInstanceOf(CommandResult::class, $unserializedResult);
$this->assertSame(123, $unserializedResult->getExitCode());
$this->assertSame('theOutput', $unserializedResult->getOutput());
$this->assertSame('theErrorOutput', $unserializedResult->getErrorOutput());
}
public function testThrowExceptionIfInvalidJsonGiven()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The malformed json given.');
CommandResult::jsonUnserialize('{]');
}
}