From 34b6b75665caf369e22c66b29e144c8dec8d78c7 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Tue, 7 Jun 2022 15:04:33 +0100 Subject: [PATCH] [feature] add PHP 8.1 and Symfony 6.1 support (#271) --- .github/workflows/ci.yml | 8 ++++-- .php_cs.dist => .php-cs-fixer.dist.php | 2 +- Check/SymfonyVersion.php | 4 +-- .../Compiler/AddGroupsCompilerPass.php | 2 +- Helper/ArrayReporter.php | 4 +-- Tests/Check/RedisCollectionTest.php | 2 +- Tests/Helper/SwiftMailerReporterTest.php | 22 +++++++++------- Tests/Helper/SymfonyMailerReporterTest.php | 26 ++++++++++--------- Tests/LiipMonitorBundleTest.php | 2 ++ Tests/app/config_symfony5.yml | 2 +- Tests/app/config_symfony6.yml | 12 +++++++++ composer.json | 4 +-- 12 files changed, 57 insertions(+), 33 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (91%) create mode 100644 Tests/app/config_symfony6.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8aad81c1..75759baf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,11 +15,15 @@ jobs: strategy: fail-fast: true matrix: - php: [7.4, 8.0] + php: [7.4, 8.0, 8.1] symfony: [4.4.*, 5.3.*, 5.4.*] include: - php: 8.0 symfony: 6.0.* + - php: 8.1 + symfony: 6.0.* + - php: 8.1 + symfony: 6.1.* steps: - name: Checkout code @@ -128,4 +132,4 @@ jobs: composer-options: --prefer-dist - name: Check CS - run: vendor/bin/php-cs-fixer fix -v --dry-run --diff-format=udiff + run: vendor/bin/php-cs-fixer fix --diff --dry-run --verbose diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 91% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index dacb96e1..8848a364 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -6,7 +6,7 @@ ->in(__DIR__) ; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, 'no_superfluous_phpdoc_tags' => [ diff --git a/Check/SymfonyVersion.php b/Check/SymfonyVersion.php index ac7778d6..b1ecb528 100644 --- a/Check/SymfonyVersion.php +++ b/Check/SymfonyVersion.php @@ -18,8 +18,8 @@ */ class SymfonyVersion implements CheckInterface { - const PACKAGIST_URL = 'https://packagist.org/packages/symfony/symfony.json'; - const VERSION_CHECK_URL = 'https://symfony.com/releases/%s.json'; + public const PACKAGIST_URL = 'https://packagist.org/packages/symfony/symfony.json'; + public const VERSION_CHECK_URL = 'https://symfony.com/releases/%s.json'; /** * @return ResultInterface diff --git a/DependencyInjection/Compiler/AddGroupsCompilerPass.php b/DependencyInjection/Compiler/AddGroupsCompilerPass.php index ffbceb72..3769a7d3 100644 --- a/DependencyInjection/Compiler/AddGroupsCompilerPass.php +++ b/DependencyInjection/Compiler/AddGroupsCompilerPass.php @@ -7,7 +7,7 @@ class AddGroupsCompilerPass implements CompilerPassInterface { - const SERVICE_ID_PREFIX = 'liip_monitor.check.'; + public const SERVICE_ID_PREFIX = 'liip_monitor.check.'; public function process(ContainerBuilder $container): void { diff --git a/Helper/ArrayReporter.php b/Helper/ArrayReporter.php index f9074c9b..bc3e21f1 100644 --- a/Helper/ArrayReporter.php +++ b/Helper/ArrayReporter.php @@ -15,8 +15,8 @@ */ class ArrayReporter implements ReporterInterface { - const STATUS_OK = 'OK'; - const STATUS_KO = 'KO'; + public const STATUS_OK = 'OK'; + public const STATUS_KO = 'KO'; private $globalStatus = self::STATUS_OK; private $results = []; diff --git a/Tests/Check/RedisCollectionTest.php b/Tests/Check/RedisCollectionTest.php index 4c1a6ee0..1045b146 100644 --- a/Tests/Check/RedisCollectionTest.php +++ b/Tests/Check/RedisCollectionTest.php @@ -10,7 +10,7 @@ final class RedisCollectionTest extends TestCase { - const AUTH = 'my-super-secret-password'; + public const AUTH = 'my-super-secret-password'; /** * @test diff --git a/Tests/Helper/SwiftMailerReporterTest.php b/Tests/Helper/SwiftMailerReporterTest.php index d229d099..4bf0132d 100644 --- a/Tests/Helper/SwiftMailerReporterTest.php +++ b/Tests/Helper/SwiftMailerReporterTest.php @@ -11,7 +11,6 @@ use Laminas\Diagnostics\Result\Success; use Laminas\Diagnostics\Result\Warning; use Liip\MonitorBundle\Helper\SwiftMailerReporter; -use Prophecy\Argument; /** * @author Kevin Bond @@ -23,13 +22,15 @@ class SwiftMailerReporterTest extends \PHPUnit\Framework\TestCase */ public function testSendNoEmail(ResultInterface $result, $sendOnWarning): void { - $mailer = $this->prophesize('Swift_Mailer'); - $mailer->send()->shouldNotBeCalled(); + $mailer = $this->createMock('Swift_Mailer'); + $mailer + ->expects(self::never()) + ->method('send'); $results = new Collection(); - $results[$this->prophesize(CheckInterface::class)->reveal()] = $result; + $results[$this->createMock(CheckInterface::class)] = $result; - $reporter = new SwiftMailerReporter($mailer->reveal(), 'foo@bar.com', 'bar@foo.com', 'foo bar', $sendOnWarning); + $reporter = new SwiftMailerReporter($mailer, 'foo@bar.com', 'bar@foo.com', 'foo bar', $sendOnWarning); $reporter->onFinish($results); } @@ -38,13 +39,16 @@ public function testSendNoEmail(ResultInterface $result, $sendOnWarning): void */ public function testSendEmail(ResultInterface $result, $sendOnWarning): void { - $mailer = $this->prophesize('Swift_Mailer'); - $mailer->send(Argument::type('Swift_Message'))->shouldBeCalled(); + $mailer = $this->createMock('Swift_Mailer'); + $mailer + ->expects(self::once()) + ->method('send') + ->with(self::isInstanceOf('Swift_Message')); $results = new Collection(); - $results[$this->prophesize(CheckInterface::class)->reveal()] = $result; + $results[$this->createMock(CheckInterface::class)] = $result; - $reporter = new SwiftMailerReporter($mailer->reveal(), 'foo@bar.com', 'bar@foo.com', 'foo bar', $sendOnWarning); + $reporter = new SwiftMailerReporter($mailer, 'foo@bar.com', 'bar@foo.com', 'foo bar', $sendOnWarning); $reporter->onFinish($results); } diff --git a/Tests/Helper/SymfonyMailerReporterTest.php b/Tests/Helper/SymfonyMailerReporterTest.php index cbc39e3a..d8ecf5cc 100644 --- a/Tests/Helper/SymfonyMailerReporterTest.php +++ b/Tests/Helper/SymfonyMailerReporterTest.php @@ -6,8 +6,8 @@ use Laminas\Diagnostics\Result\Collection; use Laminas\Diagnostics\Result\Failure; use Liip\MonitorBundle\Helper\SymfonyMailerReporter; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; @@ -15,7 +15,7 @@ class SymfonyMailerReporterTest extends TestCase { /** - * @var \Prophecy\Prophecy\ObjectProphecy|MailerInterface + * @var MockObject|MailerInterface */ private $mailer; @@ -25,7 +25,7 @@ protected function setUp(): void $this->markTestSkipped('Symfony Mailer not available.'); } - $this->mailer = $this->prophesize(MailerInterface::class); + $this->mailer = $this->createMock(MailerInterface::class); } /** @@ -33,7 +33,7 @@ protected function setUp(): void */ public function testSendMail(array $recipients, string $sender, string $subject): void { - $reporter = new SymfonyMailerReporter($this->mailer->reveal(), $recipients, $sender, $subject); + $reporter = new SymfonyMailerReporter($this->mailer, $recipients, $sender, $subject); $check = $this->prophesize(CheckInterface::class); $check->getLabel()->willReturn('Some Label'); @@ -41,15 +41,17 @@ public function testSendMail(array $recipients, string $sender, string $subject) $checks = new Collection(); $checks[$check->reveal()] = new Failure('Something goes wrong'); - $this->mailer->send(Argument::that(function (Email $message) use ($recipients, $sender, $subject): bool { - $this->assertEquals(Address::createArray($recipients), $message->getTo(), 'Check if Recipient is sent correctly.'); - $this->assertEquals([Address::create($sender)], $message->getFrom(), 'Check that the from header is set correctly.'); - $this->assertSame($subject, $message->getSubject(), 'Check that the subject has been set.'); + $this->mailer + ->expects(self::once()) + ->method('send') + ->with(self::callback(function (?Email $message) use ($recipients, $sender, $subject): bool { + self::assertEquals(Address::createArray($recipients), $message->getTo(), 'Check if Recipient is sent correctly.'); + self::assertEquals([Address::create($sender)], $message->getFrom(), 'Check that the from header is set correctly.'); + self::assertSame($subject, $message->getSubject(), 'Check that the subject has been set.'); + self::assertSame('[Some Label] Something goes wrong', $message->getTextBody(), 'Check if the text body has been set.'); - $this->assertSame('[Some Label] Something goes wrong', $message->getTextBody(), 'Check if the text body has been set.'); - - return true; - }))->shouldBeCalled(); + return true; + })); $reporter->onFinish($checks); } diff --git a/Tests/LiipMonitorBundleTest.php b/Tests/LiipMonitorBundleTest.php index 08c9b09a..cef70400 100644 --- a/Tests/LiipMonitorBundleTest.php +++ b/Tests/LiipMonitorBundleTest.php @@ -42,6 +42,8 @@ public function testBuildWithCompilerPasses(): void function ($compilerPass) use (&$compilerPasses) { $class = get_class($compilerPass); unset($compilerPasses[$class]); + + return $this->container; } ); diff --git a/Tests/app/config_symfony5.yml b/Tests/app/config_symfony5.yml index e42c427d..18767a7d 100644 --- a/Tests/app/config_symfony5.yml +++ b/Tests/app/config_symfony5.yml @@ -1,4 +1,4 @@ -# symfony 4 config (requires assets defined) +# symfony 5 config (requires assets defined) framework: router: resource: "%kernel.project_dir%/routing.yml" diff --git a/Tests/app/config_symfony6.yml b/Tests/app/config_symfony6.yml new file mode 100644 index 00000000..b0929e5e --- /dev/null +++ b/Tests/app/config_symfony6.yml @@ -0,0 +1,12 @@ +# symfony 6 config (requires assets defined) +framework: + router: + resource: "%kernel.project_dir%/routing.yml" + secret: test + test: ~ + assets: ~ + profiler: + collect: false + +liip_monitor: + enable_controller: true diff --git a/composer.json b/composer.json index dd60d7ed..74c6189c 100644 --- a/composer.json +++ b/composer.json @@ -39,9 +39,9 @@ "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0", "symfony/asset": "^4.4 || ^5.0 || ^6.0", "symfony/templating": "^4.4 || ^5.0 || ^6.0", - "phpunit/phpunit": "^7.0 || ^8.0", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", "symfony/finder": "^4.4 || ^5.0 || ^6.0", - "friendsofphp/php-cs-fixer": "^2.16", + "friendsofphp/php-cs-fixer": "^3.4", "doctrine/persistence": "^1.3.3 || ^2.0" }, "suggest": {