Skip to content

Commit fcaf5a0

Browse files
authored
Merge pull request #9 from asiries335/mvp-7
feat(stream): create tests
2 parents c0d461b + e5635df commit fcaf5a0

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

tests/Unit/ClientTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
4+
namespace Asiries335\redisSteamPhp\Tests;
5+
6+
use Asiries335\redisSteamPhp\Client;
7+
use Asiries335\redisSteamPhp\ClientRedisStreamPhpInterface;
8+
use Asiries335\redisSteamPhp\Stream;
9+
use Asiries335\redisSteamPhp\StreamGroupConsumer;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ClientTest extends TestCase
13+
{
14+
private $client;
15+
16+
/**
17+
* setUp
18+
*
19+
* @return void
20+
*/
21+
public function setUp() : void
22+
{
23+
$connector = \Mockery::mock(ClientRedisStreamPhpInterface::class);
24+
$this->client = new Client($connector);
25+
}
26+
27+
/**
28+
* test Stream
29+
*
30+
* @return void
31+
*/
32+
public function testStream() : void
33+
{
34+
$result = $this->client->stream('stream-name');
35+
36+
$this->assertInstanceOf(Stream::class, $result);
37+
}
38+
39+
/**
40+
* test Group
41+
*
42+
* @return void
43+
*/
44+
public function testGroup() : void
45+
{
46+
$result = $this->client->streamGroupConsumer('stream-name');
47+
48+
$this->assertInstanceOf(StreamGroupConsumer::class, $result);
49+
}
50+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
4+
namespace Asiries335\redisSteamPhp\Tests;
5+
6+
7+
use Asiries335\redisSteamPhp\ClientRedisStreamPhpInterface;
8+
use Asiries335\redisSteamPhp\StreamGroupConsumer;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class StreamGroupConsumerTest extends TestCase
12+
{
13+
private $client;
14+
15+
private const TEST_NAME_STREAM = 'test_stream';
16+
17+
private const TEST_NAME_GROUP = 'test_group';
18+
19+
/**
20+
* setUp
21+
*
22+
* @return void
23+
*/
24+
public function setUp() : void
25+
{
26+
$this->client = \Mockery::mock(ClientRedisStreamPhpInterface::class);
27+
}
28+
29+
/**
30+
* Create a group
31+
*
32+
* @return void
33+
*
34+
* @throws \Exception
35+
*/
36+
public function testCreateGroup() : void
37+
{
38+
$this->client->shouldReceive('call')->andReturn(true);
39+
40+
$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);
41+
42+
$result = $streamGroup->create(self::TEST_NAME_GROUP, true);
43+
44+
$this->assertEquals(true, $result);
45+
}
46+
47+
/**
48+
* Destroy a group
49+
*
50+
* @return void
51+
*
52+
* @throws \Exception
53+
*/
54+
public function testDestroyGroup() : void
55+
{
56+
$this->client->shouldReceive('call')->andReturn(true);
57+
58+
$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);
59+
60+
$result = $streamGroup->destroy(self::TEST_NAME_GROUP);
61+
62+
$this->assertEquals(true, $result);
63+
}
64+
65+
/**
66+
* Test delete a consumer from group
67+
*
68+
* @return void
69+
*
70+
* @throws \Exception
71+
*/
72+
public function testDeleteConsumerGroup() : void
73+
{
74+
$this->client->shouldReceive('call')->andReturn(true);
75+
76+
$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);
77+
78+
$result = $streamGroup->deleteConsumer(self::TEST_NAME_GROUP, 'consumerName');
79+
80+
$this->assertEquals(true, $result);
81+
}
82+
}

0 commit comments

Comments
 (0)