From 1b5e1ffb95cb2cb1e5a82044a93b97c2f94179d1 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Wed, 10 Mar 2021 23:24:13 +0300 Subject: [PATCH] tests --- .github/workflows/ci.yaml | 6 ++++++ .gitignore | 11 +++++++++++ bin/.gitkeep | 0 tests/ProducerTest.php | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 bin/.gitkeep diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3194617..2fe9025 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,6 +59,9 @@ jobs: run: composer update --no-progress --no-interaction --prefer-dist --prefer-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 run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml @@ -197,6 +200,9 @@ jobs: - name: Install dependencies 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 env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.gitignore b/.gitignore index 6b59151..24d2a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,14 @@ /.php_cs.cache /.phpunit.result.cache /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 diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/ProducerTest.php b/tests/ProducerTest.php index 9c7d5d1..f10b24d 100644 --- a/tests/ProducerTest.php +++ b/tests/ProducerTest.php @@ -3,12 +3,45 @@ declare(strict_types=1); use Amp\Loop; +use Amp\Process\Process; use Nsq\Exception\ServerException; use Nsq\Producer; use PHPUnit\Framework\TestCase; +use function Amp\ByteStream\buffer; +use function Amp\Promise\wait; final class ProducerTest extends TestCase { + /** + * @param array|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 + */ + public function data(): Generator + { + yield ['Yo!', 'Yo!'.PHP_EOL]; + yield ['Yo!', 'Yo!'.PHP_EOL]; + } + /** * @dataProvider pubFails */