Extract ProducerTest from NsqTest

This commit is contained in:
2021-01-23 03:43:00 +03:00
parent d0594c601c
commit cc26255f6f
2 changed files with 32 additions and 28 deletions

View File

@ -3,7 +3,6 @@
declare(strict_types=1);
use Nsq\Consumer;
use Nsq\Exception;
use Nsq\Message;
use Nsq\Producer;
use Nsq\Subscriber;
@ -17,12 +16,8 @@ final class NsqTest extends TestCase
$producer->pub(__FUNCTION__, __FUNCTION__);
$consumer = new Consumer(
'tcp://localhost:4150',
null,
null,
null,
null,
1000,
address: 'tcp://localhost:4150',
heartbeatInterval: 1000,
);
$subscriber = new Subscriber($consumer);
$generator = $subscriber->subscribe(__FUNCTION__, __FUNCTION__, 1);
@ -84,25 +79,4 @@ final class NsqTest extends TestCase
$generator->send(Subscriber::STOP);
self::assertTrue($consumer->isClosed());
}
/**
* @dataProvider pubFails
*/
public function testPubFail(string $topic, string $body, string $exceptionMessage): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage($exceptionMessage);
$producer = new Producer('tcp://localhost:4150');
$producer->pub($topic, $body);
}
/**
* @return Generator<string, array>
*/
public function pubFails(): Generator
{
yield 'Empty body' => ['test', '', 'E_BAD_MESSAGE PUB invalid message body size 0'];
yield 'Invalid topic' => ['test$%^&', '', 'E_BAD_TOPIC PUB topic name "test$%^&" is not valid'];
}
}

30
tests/ProducerTest.php Normal file
View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
use Nsq\Producer;
use PHPUnit\Framework\TestCase;
final class ProducerTest extends TestCase
{
/**
* @dataProvider pubFails
*/
public function testPubFail(string $topic, string $body, string $exceptionMessage): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage($exceptionMessage);
$producer = new Producer('tcp://localhost:4150');
$producer->pub($topic, $body);
}
/**
* @return Generator<string, array>
*/
public function pubFails(): Generator
{
yield 'Empty body' => ['test', '', 'E_BAD_MESSAGE PUB invalid message body size 0'];
yield 'Invalid topic' => ['test$%^&', '', 'E_BAD_TOPIC PUB topic name "test$%^&" is not valid'];
}
}