Skip to content

Commit 8799d06

Browse files
author
Eugene Leonovich
committed
Add Queue::getName()
1 parent 489239a commit 8799d06

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

src/Queue.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
class Queue
1717
{
1818
private $client;
19-
private $tubeName;
19+
private $name;
2020

2121
/**
2222
* @param \Tarantool|\Tarantool\Client\Client $client
23-
* @param string $tubeName
23+
* @param string $name
2424
*
2525
* @throws \InvalidArgumentException
2626
*/
27-
public function __construct($client, $tubeName)
27+
public function __construct($client, $name)
2828
{
2929
if ($client instanceof Client) {
3030
$client = new ClientAdapter($client);
@@ -36,7 +36,15 @@ public function __construct($client, $tubeName)
3636
}
3737

3838
$this->client = $client;
39-
$this->tubeName = $tubeName;
39+
$this->name = $name;
40+
}
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getName()
46+
{
47+
return $this->name;
4048
}
4149

4250
/**
@@ -48,7 +56,7 @@ public function __construct($client, $tubeName)
4856
public function put($data, array $options = [])
4957
{
5058
$args = $options ? [$data, $options] : [$data];
51-
$result = $this->client->call("queue.tube.$this->tubeName:put", $args);
59+
$result = $this->client->call("queue.tube.$this->name:put", $args);
5260

5361
return Task::createFromTuple($result[0]);
5462
}
@@ -61,7 +69,7 @@ public function put($data, array $options = [])
6169
public function take($timeout = null)
6270
{
6371
$args = null === $timeout ? [] : [$timeout];
64-
$result = $this->client->call("queue.tube.$this->tubeName:take", $args);
72+
$result = $this->client->call("queue.tube.$this->name:take", $args);
6573

6674
return empty($result[0]) ? null : Task::createFromTuple($result[0]);
6775
}
@@ -73,7 +81,7 @@ public function take($timeout = null)
7381
*/
7482
public function ack($taskId)
7583
{
76-
$result = $this->client->call("queue.tube.$this->tubeName:ack", [$taskId]);
84+
$result = $this->client->call("queue.tube.$this->name:ack", [$taskId]);
7785

7886
return Task::createFromTuple($result[0]);
7987
}
@@ -87,7 +95,7 @@ public function ack($taskId)
8795
public function release($taskId, array $options = [])
8896
{
8997
$args = $options ? [$taskId, $options] : [$taskId];
90-
$result = $this->client->call("queue.tube.$this->tubeName:release", $args);
98+
$result = $this->client->call("queue.tube.$this->name:release", $args);
9199

92100
return Task::createFromTuple($result[0]);
93101
}
@@ -99,7 +107,7 @@ public function release($taskId, array $options = [])
99107
*/
100108
public function peek($taskId)
101109
{
102-
$result = $this->client->call("queue.tube.$this->tubeName:peek", [$taskId]);
110+
$result = $this->client->call("queue.tube.$this->name:peek", [$taskId]);
103111

104112
return Task::createFromTuple($result[0]);
105113
}
@@ -111,7 +119,7 @@ public function peek($taskId)
111119
*/
112120
public function bury($taskId)
113121
{
114-
$result = $this->client->call("queue.tube.$this->tubeName:bury", [$taskId]);
122+
$result = $this->client->call("queue.tube.$this->name:bury", [$taskId]);
115123

116124
return Task::createFromTuple($result[0]);
117125
}
@@ -123,7 +131,7 @@ public function bury($taskId)
123131
*/
124132
public function kick($count)
125133
{
126-
$result = $this->client->call("queue.tube.$this->tubeName:kick", [$count]);
134+
$result = $this->client->call("queue.tube.$this->name:kick", [$count]);
127135

128136
return $result[0][0];
129137
}
@@ -135,14 +143,14 @@ public function kick($count)
135143
*/
136144
public function delete($taskId)
137145
{
138-
$result = $this->client->call("queue.tube.$this->tubeName:delete", [$taskId]);
146+
$result = $this->client->call("queue.tube.$this->name:delete", [$taskId]);
139147

140148
return Task::createFromTuple($result[0]);
141149
}
142150

143151
public function truncate()
144152
{
145-
$this->client->call("queue.tube.$this->tubeName:truncate");
153+
$this->client->call("queue.tube.$this->name:truncate");
146154
}
147155

148156
/**
@@ -154,7 +162,7 @@ public function truncate()
154162
*/
155163
public function stats($path = null)
156164
{
157-
$result = $this->client->call('queue.stats', [$this->tubeName]);
165+
$result = $this->client->call('queue.stats', [$this->name]);
158166

159167
if (null === $path) {
160168
return $result[0][0];

tests/Integration/QueueTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ public static function tearDownAfterClass()
5353

5454
protected function setUp()
5555
{
56-
$name = preg_replace('/^test([^\s]+).*$/', '\1', $this->getName());
57-
$name = strtolower($name);
56+
$testName = preg_replace('/^test([^\s]+).*$/', '\1', $this->getName());
57+
$testName = strtolower($testName);
5858

5959
$tubeType = $this->getTubeType();
60-
$tubeName = sprintf('t_%s_%s', $tubeType, $name);
60+
$queueName = sprintf('t_%s_%s', $tubeType, $testName);
6161

62-
self::$client->evaluate('create_tube(...)', [$tubeName, $tubeType]);
62+
self::$client->evaluate('create_tube(...)', [$queueName, $tubeType]);
6363

6464
$ann = $this->getAnnotations();
6565
if (!empty($ann['method']['eval'])) {
6666
foreach ($ann['method']['eval'] as $eval) {
67-
self::$client->evaluate(str_replace('%tube_name%', $tubeName, $eval));
67+
self::$client->evaluate(str_replace('%tube_name%', $queueName, $eval));
6868
}
6969
}
7070

71-
$this->queue = new Queue(self::$client, $tubeName);
71+
$this->queue = new Queue(self::$client, $queueName);
7272
}
7373

7474
protected function tearDown()

tests/Unit/QueueTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Tarantool\Queue\Tests\Unit;
1313

1414
use Tarantool\Queue\Queue;
15-
use Tarantool\Queue\Task;
1615

1716
class QueueTest extends \PHPUnit_Framework_TestCase
1817
{
@@ -43,4 +42,17 @@ public function provideConstructorInvalidArgumentData()
4342
[[], 'array'],
4443
];
4544
}
45+
46+
public function testGetName()
47+
{
48+
$clientClass = class_exists('Tarantool') ? 'Tarantool' : 'Tarantool\Client\Client';
49+
$client = $this->getMockBuilder($clientClass)
50+
->disableOriginalConstructor()
51+
->getMock();
52+
53+
$queueName = uniqid('queue_', true);
54+
$queue = new Queue($client, $queueName);
55+
56+
$this->assertSame($queueName, $queue->getName());
57+
}
4658
}

0 commit comments

Comments
 (0)