3 Commits

Author SHA1 Message Date
f5ab37c579 rename test data 2021-03-10 23:33:15 +03:00
809f967fb1 remove NsqTest.php 2021-03-10 23:33:09 +03:00
1b5e1ffb95 tests 2021-03-10 23:24:13 +03:00
5 changed files with 49 additions and 39 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

@@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
use Nsq\Config\ClientConfig;
use PHPUnit\Framework\TestCase;
final class NsqTest extends TestCase
{
/**
* @dataProvider configs
*/
public function test(ClientConfig $clientConfig): void
{
self::markTestSkipped('');
}
/**
* @return Generator<string, array<int, ClientConfig>>
*/
public function configs(): Generator
{
yield 'default' => [
new ClientConfig(
heartbeatInterval: 3000,
snappy: false,
readTimeout: 1,
),
];
yield 'snappy' => [
new ClientConfig(
heartbeatInterval: 3000,
snappy: true,
readTimeout: 1,
),
];
}
}

View File

@@ -3,12 +3,44 @@
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 ['Test Message One!', 'Test Message One!'.PHP_EOL];
}
/** /**
* @dataProvider pubFails * @dataProvider pubFails
*/ */