Skip to content

Commit

Permalink
[feature] add PHP 8.1 and Symfony 6.1 support (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendavies authored Jun 7, 2022
1 parent 67fdfd8 commit 34b6b75
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 33 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
->in(__DIR__)
;

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'no_superfluous_phpdoc_tags' => [
Expand Down
4 changes: 2 additions & 2 deletions Check/SymfonyVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/AddGroupsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions Helper/ArrayReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion Tests/Check/RedisCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class RedisCollectionTest extends TestCase
{
const AUTH = 'my-super-secret-password';
public const AUTH = 'my-super-secret-password';

/**
* @test
Expand Down
22 changes: 13 additions & 9 deletions Tests/Helper/SwiftMailerReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kevinbond@gmail.com>
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
26 changes: 14 additions & 12 deletions Tests/Helper/SymfonyMailerReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
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;

class SymfonyMailerReporterTest extends TestCase
{
/**
* @var \Prophecy\Prophecy\ObjectProphecy|MailerInterface
* @var MockObject|MailerInterface
*/
private $mailer;

Expand All @@ -25,31 +25,33 @@ protected function setUp(): void
$this->markTestSkipped('Symfony Mailer not available.');
}

$this->mailer = $this->prophesize(MailerInterface::class);
$this->mailer = $this->createMock(MailerInterface::class);
}

/**
* @dataProvider getTestData
*/
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');

$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);
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/LiipMonitorBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function testBuildWithCompilerPasses(): void
function ($compilerPass) use (&$compilerPasses) {
$class = get_class($compilerPass);
unset($compilerPasses[$class]);

return $this->container;
}
);

Expand Down
2 changes: 1 addition & 1 deletion Tests/app/config_symfony5.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# symfony 4 config (requires assets defined)
# symfony 5 config (requires assets defined)
framework:
router:
resource: "%kernel.project_dir%/routing.yml"
Expand Down
12 changes: 12 additions & 0 deletions Tests/app/config_symfony6.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 34b6b75

Please sign in to comment.