/
QPeekTest.php
108 lines (94 loc) · 3.8 KB
/
QPeekTest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Disque\Test\Command;
use PHPUnit_Framework_TestCase;
use Disque\Command\Argument\InvalidCommandArgumentException;
use Disque\Command\CommandInterface;
use Disque\Command\QPeek;
use Disque\Command\Response\InvalidResponseException;
class QPeekTest extends PHPUnit_Framework_TestCase
{
public function testInstance()
{
$c = new QPeek();
$this->assertInstanceOf(CommandInterface::class, $c);
}
public function testGetCommand()
{
$c = new QPeek();
$result = $c->getCommand();
$this->assertSame('QPEEK', $result);
}
public function testIsBlocking()
{
$c = new QPeek();
$result = $c->isBlocking();
$this->assertFalse($result);
}
public function testBuildInvalidArgumentsEmpty()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: []');
$c = new QPeek();
$c->setArguments([]);
}
public function testBuildInvalidArgumentsEmptyTooMany()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: ["test","stuff","arg"]');
$c = new QPeek();
$c->setArguments(['test', 'stuff', 'arg']);
}
public function testBuildInvalidArgumentsEmptyNonNumeric()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: {"test":"stuff","arg":"val"}');
$c = new QPeek();
$c->setArguments(['test' => 'stuff', 'arg' => 'val']);
}
public function testBuildInvalidArgumentsNumericNon0()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: {"1":"stuff","2":"test"}');
$c = new QPeek();
$c->setArguments([1 => 'stuff', 2 => 'test']);
}
public function testBuildInvalidArgumentsNumericNon1()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: {"0":"stuff","2":"test"}');
$c = new QPeek();
$c->setArguments([0 => 'stuff', 2 => 'test']);
}
public function testBuildInvalidArgumentsNonString()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: [false,"test"]');
$c = new QPeek();
$c->setArguments([false, 'test']);
}
public function testBuildInvalidArgumentsNonNumeric()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: ["test","stuff"]');
$c = new QPeek();
$c->setArguments(['test', 'stuff']);
}
public function testBuildInvalidArgumentsNonInt()
{
$this->setExpectedExceptionRegExp(InvalidCommandArgumentException::class, '/^Invalid command arguments. Arguments for command Disque\\\\Command\\\\QPeek: \["test",3.14\d*\]$/');
$c = new QPeek();
$c->setArguments(['test', 3.14]);
}
public function testBuild()
{
$c = new QPeek();
$c->setArguments(['test', 78]);
$result = $c->getArguments();
$this->assertSame(['test', 78], $result);
}
public function testParse()
{
$c = new QPeek();
$result = $c->parse([['queue', 'D-0f0c644fd3ccb51c2cedbd47fcb6f312646c993c05a0SQ', 'stuff']]);
$this->assertSame([
[
'queue' => 'queue',
'id' => 'D-0f0c644fd3ccb51c2cedbd47fcb6f312646c993c05a0SQ',
'body' => 'stuff'
]
], $result);
}
}