Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate PHPUnit 9 => 10 (Waiting for PHPUnit-Bridge) #296

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"laminas/laminas-diagnostics": "^1.25",
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.6.16",
"phpunit/phpunit": "^10.5.10",
"symfony/http-client": "^6.4|^7.0",
"symfony/mailer": "^6.4|^7.0",
"symfony/messenger": "^6.4|^7.0",
Expand Down
47 changes: 25 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="Liip\Monitor\Tests\Fixture\TestKernel" />
<server name="SHELL_VERBOSITY" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
<env name="OH_DEAR_MONITOR_SECRET" value="secret"/>
</php>
cacheDirectory=".phpunit.cache">

<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="Liip\Monitor\Tests\Fixture\TestKernel"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
<env name="OH_DEAR_MONITOR_SECRET" value="secret"/>
</php>

<testsuites>
<testsuite name="liip/monitor-bundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="liip/monitor-bundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<!-- TODO activate after phpunit-bridge does support phpunit 10
<extensions>
<bootstrap class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</extensions>
-->

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
21 changes: 6 additions & 15 deletions tests/Check/CheckContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Liip\Monitor\Check\CheckContext;
use Liip\Monitor\Result;
use Liip\Monitor\Tests\CheckTests;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -32,36 +33,28 @@ public static function checkResultProvider(): iterable
];
}

/**
* @test
*/
#[Test]
public function id_can_be_overridden(): void
{
$this->assertSame('7e4c0e91', (new CheckContext(new CallbackCheck('name', fn() => null)))->id());
$this->assertSame('override', (new CheckContext(new CallbackCheck('name', fn() => null), id: 'override'))->id());
}

/**
* @test
*/
#[Test]
public function wrapped_label_is_used_to_calculate_id(): void
{
$this->assertSame('7e4c0e91', (new CheckContext(new CallbackCheck('name', fn() => null)))->id());
$this->assertSame('b22f5367', (new CheckContext(new CallbackCheck('name', fn() => null), label: 'override'))->id());
}

/**
* @test
*/
#[Test]
public function label_can_be_overridden(): void
{
$this->assertSame('name', (new CheckContext(new CallbackCheck('name', fn() => null)))->label());
$this->assertSame('override', (new CheckContext(new CallbackCheck('name', fn() => null), label: 'override'))->label());
}

/**
* @test
*/
#[Test]
public function can_set_suites_and_ttl(): void
{
$context = new CheckContext(new CallbackCheck('name', fn() => null));
Expand All @@ -77,9 +70,7 @@ public function can_set_suites_and_ttl(): void
$this->assertSame(['foo', 'bar'], (new CheckContext(new CallbackCheck('name', fn() => null), suite: ['foo', 'bar']))->suites());
}

/**
* @test
*/
#[Test]
public function cannot_create_for_self(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
9 changes: 3 additions & 6 deletions tests/Check/CheckRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Liip\Monitor\Check\CallbackCheck;
use Liip\Monitor\Check\CheckRunner;
use Liip\Monitor\Result\Status;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Cache\CacheInterface;
Expand All @@ -23,9 +24,7 @@
*/
final class CheckRunnerTest extends TestCase
{
/**
* @test
*/
#[Test]
public function exception_thrown(): void
{
$runner = new CheckRunner(
Expand All @@ -45,9 +44,7 @@ public function exception_thrown(): void
$this->assertStringContainsString('Liip\Monitor\Tests\Check\CheckRunnerTest->Liip\Monitor\Tests\Check\{closure}()', $result->context()['stack_trace']);
}

/**
* @test
*/
#[Test]
public function exception_thrown_with_previous(): void
{
$runner = new CheckRunner(
Expand Down
9 changes: 3 additions & 6 deletions tests/Check/Doctrine/DbalConnectionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
use Liip\Monitor\Check\Doctrine\DbalConnectionCheck;
use Liip\Monitor\Result;
use Liip\Monitor\Result\Status;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @author Kevin Bond <[email protected]>
*/
final class DbalConnectionCheckTest extends KernelTestCase
{
/**
* @test
*/
#[Test]
public function can_run(): void
{
$check = new DbalConnectionCheck(self::getContainer()->get('doctrine'), 'default');
Expand All @@ -34,9 +33,7 @@ public function can_run(): void
$this->assertSame(Status::SUCCESS, $check->run()->status());
}

/**
* @test
*/
#[Test]
public function invalid_connection(): void
{
$connectionRegistry = $this->createMock(ConnectionRegistry::class);
Expand Down
5 changes: 2 additions & 3 deletions tests/Check/LaminasDiagnosticsBridgeCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Liip\Monitor\Check\LaminasDiagnosticsBridgeCheck;
use Liip\Monitor\Result;
use Liip\Monitor\Tests\CheckTests;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -64,9 +65,7 @@ public static function checkResultProvider(): iterable
];
}

/**
* @test
*/
#[Test]
public function invalid(): void
{
$check = self::create(fn() => 'invalid');
Expand Down
13 changes: 5 additions & 8 deletions tests/Check/Php/ComposerAuditCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
use Liip\Monitor\Check\Php\ComposerAuditCheck;
use Liip\Monitor\Result;
use Liip\Monitor\Result\Status;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
* @author Kevin Bond <[email protected]>
*
* @group slow
*/
#[Group('slow')]
final class ComposerAuditCheckTest extends TestCase
{
/**
* @test
*/
#[Test]
public function successful_check(): void
{
$check = new ComposerAuditCheck(__DIR__.'/../../Fixture/project1');
Expand All @@ -37,9 +36,7 @@ public function successful_check(): void
$this->assertEquals(Result::success('No advisories'), $result);
}

/**
* @test
*/
#[Test]
public function failed_check(): void
{
$check = new ComposerAuditCheck(__DIR__.'/../../Fixture/project2');
Expand Down
4 changes: 2 additions & 2 deletions tests/Check/Php/PhpVersionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
use Liip\Monitor\Info\Php\PhpVersionInfo;
use Liip\Monitor\Result;
use Liip\Monitor\Tests\CheckTests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\HttpClient;

/**
* @author Kevin Bond <[email protected]>
*
* @group slow
*/
#[Group('slow')]
final class PhpVersionCheckTest extends TestCase
{
use CheckTests;
Expand Down
4 changes: 2 additions & 2 deletions tests/Check/Symfony/SymfonyVersionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
use Liip\Monitor\Info\Symfony\SymfonyVersionInfo;
use Liip\Monitor\Result;
use Liip\Monitor\Tests\CheckTests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\HttpClient;

/**
* @author Kevin Bond <[email protected]>
*
* @group slow
*/
#[Group('slow')]
final class SymfonyVersionCheckTest extends TestCase
{
use CheckTests;
Expand Down
8 changes: 4 additions & 4 deletions tests/CheckTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
use Liip\Monitor\Check\CheckContext;
use Liip\Monitor\Result;
use Liip\Monitor\Result\Status;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

/**
* @author Kevin Bond <[email protected]>
*/
trait CheckTests
{
/**
* @test
* @dataProvider checkResultProvider
*/
#[Test]
#[DataProvider('checkResultProvider')]
public function run_check(Check|callable $check, Result|Status|callable $expectedResult, ?string $expectedLabel = null): void
{
if ($check instanceof \Closure) {
Expand Down
16 changes: 6 additions & 10 deletions tests/Controller/OhDearControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Liip\Monitor\Tests\Controller;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Browser\Test\HasBrowser;

Expand All @@ -21,10 +23,8 @@ final class OhDearControllerTest extends KernelTestCase
{
use HasBrowser;

/**
* @test
* @group slow
*/
#[Test]
#[Group('slow')]
public function run_checks(): void
{
$content = $this->browser()
Expand All @@ -43,9 +43,7 @@ public function run_checks(): void
$this->assertSame('ok', $content['checkResults'][0]['status']);
}

/**
* @test
*/
#[Test]
public function not_found_if_secret_missing(): void
{
$this->browser()
Expand All @@ -54,9 +52,7 @@ public function not_found_if_secret_missing(): void
;
}

/**
* @test
*/
#[Test]
public function not_found_if_secret_mismatch(): void
{
$this->browser()
Expand Down
5 changes: 2 additions & 3 deletions tests/DependencyInjection/LiipMonitorCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
use Liip\Monitor\Check\Doctrine\DbalConnectionCheck;
use Liip\Monitor\DependencyInjection\LiipMonitorExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Kevin Bond <[email protected]>
*/
final class LiipMonitorCompilerPassTest extends AbstractCompilerPassTestCase
{
/**
* @test
*/
#[Test]
public function adds_default_doctrine_connection_checks(): void
{
$this->setParameter('liip_monitor.check.doctrine_dbal_connection.all', []);
Expand Down
Loading
Loading