diff --git a/.gitignore b/.gitignore index 717e15a..bc73527 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /.env esb.yml .idea + +.phpunit.result.cache diff --git a/Dockerfile b/Dockerfile index dfba75c..949a993 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_VERSION=7.2 +ARG PHP_VERSION=7.4 FROM php:${PHP_VERSION}-cli-alpine @@ -10,9 +10,6 @@ RUN set -eux; \ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer ENV COMPOSER_ALLOW_SUPERUSER=1 -RUN set -eux; \ - composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \ - composer clear-cache ENV PATH="${PATH}:/root/.composer/vendor/bin" COPY .docker/php/php.ini /usr/local/etc/php/php.ini diff --git a/composer.json b/composer.json index 19995a8..26aa1fc 100644 --- a/composer.json +++ b/composer.json @@ -10,22 +10,23 @@ } ], "require": { - "php": "^7.1", + "php": "^7.1 || ^8.0", "ext-pcntl": "*", - "symfony/dependency-injection": "^3.3", - "symfony/config": "^3.3", - "symfony/yaml": "^3.3", - "amphp/beanstalk": "^0.2.4", + "ext-json": "*", + "symfony/dependency-injection": "^5.4", + "symfony/config": "^5.4", + "symfony/yaml": "^5.4", + "amphp/beanstalk": "^0.3.2", "monolog/monolog": "^1.23", "dragonmantank/cron-expression": "^2.0", "twig/twig": "^2.5", "nikic/fast-route": "^1.3", - "amphp/http-server": "^0.8.2", + "amphp/http-server": "^2.1", "amphp/amp": "^2.1", "psr/log": "^1.1", - "amphp/socket": "^0.10", - "amphp/http": "^1.1", - "amphp/file": "^0.3" + "amphp/socket": "^1.2", + "amphp/http": "^1.7", + "amphp/file": "^2.0" }, "autoload": { "psr-4": { @@ -41,18 +42,19 @@ "bin/esb" ], "require-dev": { - "phpunit/phpunit": "^6.5", - "amphp/phpunit-util": "^1.0", + "phpunit/phpunit": "^9.6", + "amphp/phpunit-util": "^2.0", "pda/pheanstalk": "^3.1", "mikey179/vfsstream": "^1.6", - "amphp/artax": "^3.0", + "amphp/http-client": "^4.6", "phpstan/phpstan": "^0.12", "squizlabs/php_codesniffer": "^3.2" }, "scripts": { "phpcs": "phpcs", - "phpstan": "phpstan analyse --no-progress -l 6 -c phpstan.neon src tests", - "phpunit": "phpunit", + "ecs": "vendor/bin/ecs", + "phpstan": "vendor/bin/phpstan analyse --no-progress -l max -c phpstan.neon src/", + "phpunit": "vendor/bin/phpunit", "tests": ["@phpcs", "@phpstan", "@phpunit"] } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4f73fec..6d06c4e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,13 @@ - + + + + src + + tests/ - - - - src - - - - - - diff --git a/services.yml b/services.yml index 407a084..9476dc0 100644 --- a/services.yml +++ b/services.yml @@ -18,17 +18,17 @@ services: Monolog\Handler\StreamHandler: class: \Monolog\Handler\StreamHandler - arguments: [ 'php://stdout', !php/const:Monolog\Logger::DEBUG ] + arguments: [ 'php://stdout', !php/const Monolog\Logger::DEBUG ] Monolog\Handler\ErrorLogHandler: class: \Monolog\Handler\ErrorLogHandler - arguments: [ !php/const:Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, !php/const:Monolog\Logger::ERROR ] + arguments: [ !php/const Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, !php/const Monolog\Logger::ERROR ] Monolog\Formatter\HtmlFormatter: {} Monolog\Handler\NativeMailerHandler: class: \Monolog\Handler\NativeMailerHandler - arguments: [ '%logger_mail_to%', 'Significant event from ESB', '%logger_mail_from%', !php/const:Monolog\Logger::WARNING ] + arguments: [ '%logger_mail_to%', 'Significant event from ESB', '%logger_mail_from%', !php/const Monolog\Logger::WARNING ] calls: - method: setFormatter arguments: diff --git a/src/FlowConfiguration.php b/src/FlowConfiguration.php index 4ac783c..ae72e2e 100644 --- a/src/FlowConfiguration.php +++ b/src/FlowConfiguration.php @@ -16,8 +16,8 @@ final class FlowConfiguration implements ConfigurationInterface */ public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('flows'); + $treeBuilder = new TreeBuilder('flows'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->useAttributeAsKey('name') ->arrayPrototype() diff --git a/tests/BeanstalkTestCase.php b/tests/BeanstalkTestCase.php index 869b4db..788ba69 100644 --- a/tests/BeanstalkTestCase.php +++ b/tests/BeanstalkTestCase.php @@ -2,17 +2,17 @@ namespace Webgriffe\Esb; -use PHPUnit\Framework\TestCase; +use Amp\PHPUnit\AsyncTestCase; use Pheanstalk\Pheanstalk; -class BeanstalkTestCase extends TestCase +class BeanstalkTestCase extends AsyncTestCase { /** * @var Pheanstalk */ protected $pheanstalk; - public function setUp() + protected function setUp(): void { parent::setUp(); $this->pheanstalk = $this->getPheanstalk(); diff --git a/tests/Integration/CrontabProducerAndWorkerTest.php b/tests/Integration/CrontabProducerAndWorkerTest.php index 625fe15..391e2f0 100644 --- a/tests/Integration/CrontabProducerAndWorkerTest.php +++ b/tests/Integration/CrontabProducerAndWorkerTest.php @@ -47,7 +47,7 @@ public function testCrontabProducerAndWorkerDoesNotProduceIfIsNotTheRightTime() self::$kernel->boot(); - $this->assertFileNotExists($workerFile); + $this->assertFileDoesNotExist($workerFile); } public function testCrontabProducerAndWorkerProducesIfItsTheRightTime() @@ -77,8 +77,8 @@ public function testCrontabProducerAndWorkerProducesIfItsTheRightTime() self::$kernel->boot(); $workerFileLines = $this->getFileLines($workerFile); - $this->assertContains('job1', $workerFileLines[0]); - $this->assertContains('job2', $workerFileLines[1]); + $this->assertStringContainsString('job1', $workerFileLines[0]); + $this->assertStringContainsString('job2', $workerFileLines[1]); $this->assertReadyJobsCountInTube(0, self::TUBE); } } diff --git a/tests/Integration/FlowsDependencyTest.php b/tests/Integration/FlowsDependencyTest.php index a2a92a8..4524ae5 100644 --- a/tests/Integration/FlowsDependencyTest.php +++ b/tests/Integration/FlowsDependencyTest.php @@ -111,7 +111,7 @@ function ($log) { $timestamp2 = $this->getLogLineTimestamp($worker2Line); $this->assertReadyJobsCountInTube(0, self::FLOW3_CODE); - $this->assertFileNotExists($workerFile3); + $this->assertFileDoesNotExist($workerFile3); //This is hard to read, but it checks that $timestamp1 >= $timestamp2 $this->assertGreaterThanOrEqual( @@ -208,21 +208,21 @@ function ($log) { $workerFileLines = $this->getFileLines($workerFile1); $this->assertCount(1, $workerFileLines); $worker1Line = $workerFileLines[0]; - $this->assertContains('job1', $worker1Line); + $this->assertStringContainsString('job1', $worker1Line); $timestamp1 = $this->getLogLineTimestamp($worker1Line); $this->assertReadyJobsCountInTube(0, self::FLOW2_CODE); $workerFileLines = $this->getFileLines($workerFile2); $this->assertCount(1, $workerFileLines); $worker2Line = $workerFileLines[0]; - $this->assertContains('job2', $worker2Line); + $this->assertStringContainsString('job2', $worker2Line); $timestamp2 = $this->getLogLineTimestamp($worker2Line); $this->assertReadyJobsCountInTube(0, self::FLOW3_CODE); $workerFileLines = $this->getFileLines($workerFile3); $this->assertCount(1, $workerFileLines); $worker3Line = $workerFileLines[0]; - $this->assertContains('job3', $worker3Line); + $this->assertStringContainsString('job3', $worker3Line); $timestamp3 = $this->getLogLineTimestamp($worker3Line); //Checks that $timestamp1 >= $timestamp2 diff --git a/tests/Integration/HttpRequestProducerAndWorkerTest.php b/tests/Integration/HttpRequestProducerAndWorkerTest.php index 59d284d..f5e69ca 100644 --- a/tests/Integration/HttpRequestProducerAndWorkerTest.php +++ b/tests/Integration/HttpRequestProducerAndWorkerTest.php @@ -2,13 +2,14 @@ namespace Webgriffe\Esb\Integration; -use Amp\Artax\DefaultClient; -use Amp\Artax\Request; -use Amp\Artax\Response; +use Amp\Http\Client\HttpClientBuilder; +use Amp\Http\Client\Request; +use Amp\Http\Client\Response; use Amp\Loop; use Amp\Promise; use Amp\Socket\ClientSocket; use Amp\Socket\ConnectException; +use Amp\Socket\Socket; use Monolog\Logger; use org\bovigo\vfs\vfsStream; use Webgriffe\Esb\DummyFilesystemWorker; @@ -28,7 +29,7 @@ class HttpRequestProducerAndWorkerTest extends KernelTestCase const TUBE = 'sample_tube'; - public function setUp() + public function setUp(): void { parent::setUp(); $this->workerFile = vfsStream::url('root/worker.data'); @@ -55,11 +56,15 @@ public function testHttpRequestProducerAndWorker() Loop::delay(100, function () { yield $this->waitForConnectionAvailable("tcp://127.0.0.1:{$this->httpPort}"); $payload = json_encode(['jobs' => ['job1', 'job2', 'job3']]); - $client = new DefaultClient(); - $request = (new Request("http://127.0.0.1:{$this->httpPort}/dummy", 'POST'))->withBody($payload); + $client = HttpClientBuilder::buildDefault(); + $request = new Request("http://127.0.0.1:{$this->httpPort}/dummy", 'POST'); + $request->setBody($payload); /** @var Response $response */ $response = yield $client->request($request); - $this->assertContains('"Successfully scheduled 3 job(s) to be queued."', yield $response->getBody()); + $this->assertContains( + '"Successfully scheduled 3 job(s) to be queued."', + yield $response->getBody()->read() + ); }); $this->stopWhen(function () { return (yield exists($this->workerFile)) && count($this->getFileLines($this->workerFile)) === 3; @@ -92,8 +97,9 @@ public function testHttpRequestProducerWithWrongUriShouldReturn404() Loop::delay(100, function () { yield $this->waitForConnectionAvailable("tcp://127.0.0.1:{$this->httpPort}"); $payload = json_encode(['jobs' => ['job1', 'job2', 'job3']]); - $client = new DefaultClient(); - $request = (new Request("http://127.0.0.1:{$this->httpPort}/wrong-uri", 'POST'))->withBody($payload); + $client = HttpClientBuilder::buildDefault(); + $request = new Request("http://127.0.0.1:{$this->httpPort}/wrong-uri", 'POST'); + $request->setBody($payload); /** @var Response $response */ $response = yield $client->request($request); $this->assertEquals(404, $response->getStatus()); @@ -104,7 +110,7 @@ public function testHttpRequestProducerWithWrongUriShouldReturn404() self::$kernel->boot(); - $this->assertFileNotExists($this->workerFile); + $this->assertFileDoesNotExist($this->workerFile); $this->assertReadyJobsCountInTube(0, self::TUBE); } @@ -113,8 +119,8 @@ private function waitForConnectionAvailable(string $uri): Promise return call(function () use ($uri) { do { try { - /** @var ClientSocket $connection */ - $connection = yield connect($uri); + /** @var Socket $connection */ + $connection = yield from connect($uri); } catch (ConnectException $e) { $connection = null; } diff --git a/tests/Integration/JobUnserializationErrorHandlingTest.php b/tests/Integration/JobUnserializationErrorHandlingTest.php index b8c11b5..51a3b00 100644 --- a/tests/Integration/JobUnserializationErrorHandlingTest.php +++ b/tests/Integration/JobUnserializationErrorHandlingTest.php @@ -54,7 +54,7 @@ function () { self::$kernel->boot(); - $this->assertContains('Cannot unserialize job payload so it has been buried.', $this->dumpLog()); + $this->assertStringContainsString('Cannot unserialize job payload so it has been buried.', $this->dumpLog()); $this->assertReadyJobsCountInTube(0, self::TUBE); $this->assertBuriedJobsCountInTube(1, self::TUBE); } diff --git a/tests/Integration/NonUtf8DataHandlingTest.php b/tests/Integration/NonUtf8DataHandlingTest.php index 5521b1d..af99b3d 100644 --- a/tests/Integration/NonUtf8DataHandlingTest.php +++ b/tests/Integration/NonUtf8DataHandlingTest.php @@ -50,7 +50,7 @@ function () { self::$kernel->boot(); - $this->assertNotContains('Successfully produced a new Job []', $this->dumpLog()); - $this->assertNotContains('Successfully worked a Job []', $this->dumpLog()); + $this->assertStringNotContainsString('Successfully produced a new Job []', $this->dumpLog()); + $this->assertStringNotContainsString('Successfully worked a Job []', $this->dumpLog()); } } diff --git a/tests/Integration/RepeatProducerAndWorkerTest.php b/tests/Integration/RepeatProducerAndWorkerTest.php index 15ce9dd..fe3b0f9 100644 --- a/tests/Integration/RepeatProducerAndWorkerTest.php +++ b/tests/Integration/RepeatProducerAndWorkerTest.php @@ -53,8 +53,8 @@ function () use ($producerDir) { self::$kernel->boot(); $workerFileLines = $this->getFileLines($workerFile); - $this->assertContains('job1', $workerFileLines[0]); - $this->assertContains('job2', $workerFileLines[1]); + $this->assertStringContainsString('job1', $workerFileLines[0]); + $this->assertStringContainsString('job2', $workerFileLines[1]); $this->assertReadyJobsCountInTube(0, self::TUBE); } diff --git a/tests/Integration/TwoFlowsTest.php b/tests/Integration/TwoFlowsTest.php index 46f3638..f827b43 100644 --- a/tests/Integration/TwoFlowsTest.php +++ b/tests/Integration/TwoFlowsTest.php @@ -69,12 +69,12 @@ function () use ($producerDir1, $producerDir2) { self::$kernel->boot(); $workerFileLines = $this->getFileLines($workerFile1); - $this->assertContains('job1', $workerFileLines[0]); - $this->assertContains('job2', $workerFileLines[1]); + $this->assertStringContainsString('job1', $workerFileLines[0]); + $this->assertStringContainsString('job2', $workerFileLines[1]); $this->assertReadyJobsCountInTube(0, self::TUBE1); $workerFileLines = $this->getFileLines($workerFile2); - $this->assertContains('job1', $workerFileLines[0]); - $this->assertContains('job2', $workerFileLines[1]); + $this->assertStringContainsString('job1', $workerFileLines[0]); + $this->assertStringContainsString('job2', $workerFileLines[1]); $this->assertReadyJobsCountInTube(0, self::TUBE1); } } diff --git a/tests/KernelTestCase.php b/tests/KernelTestCase.php index c773a2b..fb429c6 100644 --- a/tests/KernelTestCase.php +++ b/tests/KernelTestCase.php @@ -2,7 +2,7 @@ namespace Webgriffe\Esb; -use Amp\File\BlockingDriver; +use Amp\File\Driver\BlockingDriver; use Amp\Loop; use Monolog\Handler\TestHandler; use org\bovigo\vfs\vfsStream; @@ -21,13 +21,13 @@ class KernelTestCase extends BeanstalkTestCase /** * @throws \Error */ - public function setUp() + protected function setUp(): void { parent::setUp(); filesystem(new BlockingDriver()); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); self::$kernel = null;