|
3 | 3 | namespace Tarantool\Queue\Tests\Unit;
|
4 | 4 |
|
5 | 5 | use Tarantool\Queue\Queue;
|
| 6 | +use Tarantool\Queue\Task; |
6 | 7 |
|
7 | 8 | class QueueTest extends \PHPUnit_Framework_TestCase
|
8 | 9 | {
|
9 |
| - private $tarantool; |
| 10 | + private $client; |
10 | 11 | private $queue;
|
11 | 12 |
|
12 | 13 | protected function setUp()
|
13 | 14 | {
|
14 |
| - $this->tarantool = $this->getMock('Tarantool'); |
15 |
| - $this->queue = new Queue($this->tarantool, 'foo'); |
| 15 | + $this->client = $this->getMock('Tarantool'); |
| 16 | + $this->queue = new Queue($this->client, 'foo'); |
16 | 17 | }
|
17 | 18 |
|
18 | 19 | /**
|
19 | 20 | * @dataProvider provideCallData
|
20 | 21 | */
|
21 |
| - public function testClientCall($functionName, array $args, $returnValue, $hasEmptyOptions = false) |
| 22 | + public function testMethod($functionName, array $args, array $tuple, $result) |
22 | 23 | {
|
23 |
| - $this->tarantool->expects($this->once())->method('call') |
24 |
| - ->with("queue.tube.foo:$functionName", |
25 |
| - $hasEmptyOptions ? $this->logicalOr( |
26 |
| - $this->equalTo($args + [1 => []]), |
27 |
| - $this->equalTo($args) |
28 |
| - ) : $args |
29 |
| - ) |
30 |
| - ->will($this->returnValue([$returnValue])); |
31 |
| - |
32 |
| - call_user_func_array([$this->queue, $functionName], $args); |
| 24 | + $this->client->expects($this->once())->method('call') |
| 25 | + ->with("queue.tube.foo:$functionName", $args) |
| 26 | + ->will($this->returnValue([$tuple])); |
| 27 | + |
| 28 | + $actualResult = call_user_func_array([$this->queue, $functionName], $args); |
| 29 | + |
| 30 | + is_object($result) |
| 31 | + ? $this->assertEquals($result, $actualResult) |
| 32 | + : $this->assertSame($result, $actualResult); |
33 | 33 | }
|
34 | 34 |
|
35 | 35 | public function provideCallData()
|
36 | 36 | {
|
| 37 | + $tuple = [1, 'x', 42]; |
| 38 | + $task = Task::createFromTuple($tuple); |
| 39 | + |
37 | 40 | return [
|
38 |
| - ['put', [42], [1, 0], true], |
39 |
| - ['put', [42, ['delay' => 2]], [1, 0]], |
40 |
| - ['take', [1], [1, 0]], |
41 |
| - ['ack', [1], [1, 0]], |
42 |
| - ['release', [1], [1, 0], true], |
43 |
| - ['release', [1, ['delay' => 2]], [1, 0]], |
44 |
| - ['peek', [1], [1, 0]], |
45 |
| - ['bury', [1], [1, 0]], |
46 |
| - ['kick', [5], 5], |
47 |
| - ['delete', [1], [1, 0]], |
| 41 | + ['put', [42], $tuple, $task], |
| 42 | + ['put', [42, ['delay' => 2]], $tuple, $task], |
| 43 | + ['take', [], $tuple, $task], |
| 44 | + ['take', [.1], $tuple, $task], |
| 45 | + ['ack', [1], $tuple, $task], |
| 46 | + ['release', [1], $tuple, $task], |
| 47 | + ['release', [1, ['delay' => 2]], $tuple, $task], |
| 48 | + ['peek', [1], $tuple, $task], |
| 49 | + ['bury', [1], $tuple, $task], |
| 50 | + ['kick', [5], [5], 5], |
| 51 | + ['delete', [1], $tuple, $task], |
48 | 52 | ];
|
49 | 53 | }
|
50 | 54 | }
|
0 commit comments