Skip to content

Commit

Permalink
Merge pull request #9 from asiries335/mvp-7
Browse files Browse the repository at this point in the history
feat(stream): create tests
  • Loading branch information
asiries335 authored Oct 2, 2020
2 parents c0d461b + e5635df commit fcaf5a0
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php


namespace Asiries335\redisSteamPhp\Tests;

use Asiries335\redisSteamPhp\Client;
use Asiries335\redisSteamPhp\ClientRedisStreamPhpInterface;
use Asiries335\redisSteamPhp\Stream;
use Asiries335\redisSteamPhp\StreamGroupConsumer;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{
private $client;

/**
* setUp
*
* @return void
*/
public function setUp() : void
{
$connector = \Mockery::mock(ClientRedisStreamPhpInterface::class);
$this->client = new Client($connector);
}

/**
* test Stream
*
* @return void
*/
public function testStream() : void
{
$result = $this->client->stream('stream-name');

$this->assertInstanceOf(Stream::class, $result);
}

/**
* test Group
*
* @return void
*/
public function testGroup() : void
{
$result = $this->client->streamGroupConsumer('stream-name');

$this->assertInstanceOf(StreamGroupConsumer::class, $result);
}
}
82 changes: 82 additions & 0 deletions tests/Unit/StreamGroupConsumerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php


namespace Asiries335\redisSteamPhp\Tests;


use Asiries335\redisSteamPhp\ClientRedisStreamPhpInterface;
use Asiries335\redisSteamPhp\StreamGroupConsumer;
use PHPUnit\Framework\TestCase;

class StreamGroupConsumerTest extends TestCase
{
private $client;

private const TEST_NAME_STREAM = 'test_stream';

private const TEST_NAME_GROUP = 'test_group';

/**
* setUp
*
* @return void
*/
public function setUp() : void
{
$this->client = \Mockery::mock(ClientRedisStreamPhpInterface::class);
}

/**
* Create a group
*
* @return void
*
* @throws \Exception
*/
public function testCreateGroup() : void
{
$this->client->shouldReceive('call')->andReturn(true);

$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);

$result = $streamGroup->create(self::TEST_NAME_GROUP, true);

$this->assertEquals(true, $result);
}

/**
* Destroy a group
*
* @return void
*
* @throws \Exception
*/
public function testDestroyGroup() : void
{
$this->client->shouldReceive('call')->andReturn(true);

$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);

$result = $streamGroup->destroy(self::TEST_NAME_GROUP);

$this->assertEquals(true, $result);
}

/**
* Test delete a consumer from group
*
* @return void
*
* @throws \Exception
*/
public function testDeleteConsumerGroup() : void
{
$this->client->shouldReceive('call')->andReturn(true);

$streamGroup = new StreamGroupConsumer($this->client, self::TEST_NAME_STREAM);

$result = $streamGroup->deleteConsumer(self::TEST_NAME_GROUP, 'consumerName');

$this->assertEquals(true, $result);
}
}

0 comments on commit fcaf5a0

Please sign in to comment.