Skip to content

Commit

Permalink
WIP updates dependencies to make the ESB work with PHP 8 too
Browse files Browse the repository at this point in the history
  • Loading branch information
azambon committed Dec 10, 2024
1 parent d757538 commit 3cdc792
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/.env
esb.yml
.idea

.phpunit.result.cache
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=7.2
ARG PHP_VERSION=7.4

FROM php:${PHP_VERSION}-cli-alpine

Expand All @@ -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
Expand Down
30 changes: 16 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"]
}
}
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
processIsolation="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" processIsolation="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="webgriffe/esb Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<listeners>
<listener class="Amp\PHPUnit\LoopReset" />
</listeners>
</phpunit>
6 changes: 3 additions & 3 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/FlowConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/BeanstalkTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/CrontabProducerAndWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testCrontabProducerAndWorkerDoesNotProduceIfIsNotTheRightTime()

self::$kernel->boot();

$this->assertFileNotExists($workerFile);
$this->assertFileDoesNotExist($workerFile);
}

public function testCrontabProducerAndWorkerProducesIfItsTheRightTime()
Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/Integration/FlowsDependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions tests/Integration/HttpRequestProducerAndWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -104,7 +110,7 @@ public function testHttpRequestProducerWithWrongUriShouldReturn404()

self::$kernel->boot();

$this->assertFileNotExists($this->workerFile);
$this->assertFileDoesNotExist($this->workerFile);
$this->assertReadyJobsCountInTube(0, self::TUBE);
}

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/JobUnserializationErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/NonUtf8DataHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions tests/Integration/RepeatProducerAndWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/TwoFlowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions tests/KernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 3cdc792

Please sign in to comment.