This commit is contained in:
2021-03-10 23:24:13 +03:00
parent 92d8304a6a
commit 1b5e1ffb95
4 changed files with 50 additions and 0 deletions

View File

@ -59,6 +59,9 @@ jobs:
run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest
if: ${{ matrix.dependencies == 'lowest' }} if: ${{ matrix.dependencies == 'lowest' }}
- name: Install nsq bin
run: curl -L https://github.com/nsqio/nsq/releases/download/v1.2.0/nsq-1.2.0.linux-amd64.go1.12.9.tar.gz | tar xz --strip 1
- name: Run tests - name: Run tests
run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml
@ -197,6 +200,9 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist run: composer update --no-progress --no-interaction --prefer-dist
- name: Install nsq bin
run: curl -L https://github.com/nsqio/nsq/releases/download/v1.2.0/nsq-1.2.0.linux-amd64.go1.12.9.tar.gz | tar xz --strip 1
- name: Run script - name: Run script
env: env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

11
.gitignore vendored
View File

@ -4,3 +4,14 @@
/.php_cs.cache /.php_cs.cache
/.phpunit.result.cache /.phpunit.result.cache
/infection.log /infection.log
# Nsq
bin/nsq_stat
bin/nsq_tail
bin/nsq_to_file
bin/nsq_to_http
bin/nsq_to_nsq
bin/nsqadmin
bin/nsqd
bin/nsqlookupd
bin/to_nsq

0
bin/.gitkeep Normal file
View File

View File

@ -3,12 +3,45 @@
declare(strict_types=1); declare(strict_types=1);
use Amp\Loop; use Amp\Loop;
use Amp\Process\Process;
use Nsq\Exception\ServerException; use Nsq\Exception\ServerException;
use Nsq\Producer; use Nsq\Producer;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function Amp\ByteStream\buffer;
use function Amp\Promise\wait;
final class ProducerTest extends TestCase final class ProducerTest extends TestCase
{ {
/**
* @param array<int, string>|string $body
*
* @dataProvider data
*/
public function testPublish(array | string $body, string $expected): void
{
$process = new Process(
sprintf('bin/nsq_tail -topic %s -channel default -nsqd-tcp-address localhost:4150 -n 1', __FUNCTION__),
);
wait($process->start());
$producer = Producer::create('tcp://localhost:4150');
wait($producer->connect());
wait($producer->publish(__FUNCTION__, $body));
wait($process->join());
self::assertSame($expected, wait(buffer($process->getStdout())));
}
/**
* @return Generator<int, array{0: string|array, 1: string}>
*/
public function data(): Generator
{
yield ['Yo!', 'Yo!'.PHP_EOL];
yield ['Yo!', 'Yo!'.PHP_EOL];
}
/** /**
* @dataProvider pubFails * @dataProvider pubFails
*/ */