Refactoring: Extend Reader and Writer from Connection

This commit is contained in:
2021-01-20 16:02:06 +03:00
parent fdd65cb547
commit 0a926ce607
6 changed files with 124 additions and 162 deletions

View File

@ -2,10 +2,7 @@
declare(strict_types=1);
use Nsq\Config;
use Nsq\Connection;
use Nsq\Envelope;
use Nsq\Reader;
use Nsq\Subscriber;
use Nsq\Writer;
use PHPUnit\Framework\TestCase;
@ -14,12 +11,10 @@ final class NsqTest extends TestCase
{
public function test(): void
{
$config = new Config('tcp://localhost:4150');
$writer = new Writer(Connection::connect($config));
$writer = new Writer('tcp://localhost:4150');
$writer->pub(__FUNCTION__, __FUNCTION__);
$subscriber = new Subscriber(new Reader(Connection::connect($config)));
$subscriber = new Subscriber('tcp://localhost:4150');
$generator = $subscriber->subscribe(__FUNCTION__, __FUNCTION__, 1);
$envelope = $generator->current();
@ -27,7 +22,7 @@ final class NsqTest extends TestCase
static::assertInstanceOf(Envelope::class, $envelope);
/** @var Envelope $envelope */
static::assertSame(__FUNCTION__, $envelope->message->body);
$envelope->ack();
$envelope->finish();
$generator->next();
static::assertNull($generator->current());