Skip to content

Commit e24b5e0

Browse files
author
Eugene Leonovich
committed
Update a unit test
1 parent 4bad99e commit e24b5e0

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/Queue.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ public function __construct(\Tarantool $client, $tubeName)
2121
*/
2222
public function put($data, array $options = null)
2323
{
24-
$result = $this->client->call($this->prefix.'put', [$data, (array) $options]);
24+
$args = $options ? [$data, $options] : [$data];
25+
$result = $this->client->call($this->prefix.'put', $args);
2526

2627
return Task::createFromTuple($result[0]);
2728
}
2829

2930
/**
30-
* @param int|null $timeout
31+
* @param float|null $timeout
3132
*
3233
* @return Task|null
3334
*/
3435
public function take($timeout = null)
3536
{
36-
$options = null === $timeout ? [] : [(float) $timeout];
37-
$result = $this->client->call($this->prefix.'take', $options);
37+
$args = null === $timeout ? [] : [$timeout];
38+
$result = $this->client->call($this->prefix.'take', $args);
3839

3940
return empty($result[0]) ? null : Task::createFromTuple($result[0]);
4041
}
@@ -59,7 +60,8 @@ public function ack($taskId)
5960
*/
6061
public function release($taskId, array $options = null)
6162
{
62-
$result = $this->client->call($this->prefix.'release', [$taskId, (array) $options]);
63+
$args = $options ? [$taskId, $options] : [$taskId];
64+
$result = $this->client->call($this->prefix.'release', $args);
6365

6466
return Task::createFromTuple($result[0]);
6567
}

tests/Unit/QueueTest.php

+28-24
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,52 @@
33
namespace Tarantool\Queue\Tests\Unit;
44

55
use Tarantool\Queue\Queue;
6+
use Tarantool\Queue\Task;
67

78
class QueueTest extends \PHPUnit_Framework_TestCase
89
{
9-
private $tarantool;
10+
private $client;
1011
private $queue;
1112

1213
protected function setUp()
1314
{
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');
1617
}
1718

1819
/**
1920
* @dataProvider provideCallData
2021
*/
21-
public function testClientCall($functionName, array $args, $returnValue, $hasEmptyOptions = false)
22+
public function testMethod($functionName, array $args, array $tuple, $result)
2223
{
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);
3333
}
3434

3535
public function provideCallData()
3636
{
37+
$tuple = [1, 'x', 42];
38+
$task = Task::createFromTuple($tuple);
39+
3740
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],
4852
];
4953
}
5054
}

0 commit comments

Comments
 (0)