Skip to content

Commit

Permalink
minor #493 Fix compatibility with PHPUnit 11 (derrabus)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x-dev branch.

Discussion
----------

Fix compatibility with PHPUnit 11

This PR fixes a couple of compatibility issues with PHPUnit 11:

* Data provider methods must be static.
* The mock builder does not have a `setMethods()` method anymore.
* Abstract test classes must not use the suffix `Test`.

Note: The tests are still run with PHPUnit 8.5 and 9.6 though. The PR merely enables us to use PHPUnit 11 in the future.

Commits
-------

7c93761 Fix compatibility with PHPUnit 11
  • Loading branch information
derrabus committed Nov 6, 2024
2 parents b394dfe + 7c93761 commit 33bf5ca
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class AddSwiftMailerTransportPassTest extends TestCase

private $definition;

/**
* @before
*/
protected function doSetUp()
protected function setUp(): void
{
$this->compilerPass = new AddSwiftMailerTransportPass();
$this->definition = new Definition(null, [new Reference('swiftmailer')]);
Expand Down
6 changes: 3 additions & 3 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testProcessSimpleCase()
$this->assertFalse($config['handlers']['foobar']['nested']);
}

public function provideProcessStringChannels()
public static function provideProcessStringChannels(): array
{
return [
['foo', 'foo', true],
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testProcessStringChannels($string, $expectedString, $isInclusive
$this->assertEquals($expectedString, $config['handlers']['foobar']['channels']['elements'][0]);
}

public function provideGelfPublisher()
public static function provideGelfPublisher(): array
{
return [
[
Expand Down Expand Up @@ -532,7 +532,7 @@ public function testWithProcessPsr3Messages(array $configuration, array $process
$this->assertEquals($processedConfiguration, $config['handlers']['main']['process_psr_3_messages']);
}

public function processPsr3MessagesProvider(): iterable
public static function processPsr3MessagesProvider(): iterable
{
yield 'Not specified' => [[], ['enabled' => null]];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PHPUnit\Framework\TestCase;

abstract class DependencyInjectionTest extends TestCase
abstract class DependencyInjectionTestCase extends TestCase
{
/**
* Assertion on the Class of a DIC Service Definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

abstract class FixtureMonologExtensionTest extends DependencyInjectionTest
abstract class FixtureMonologExtensionTestCase extends DependencyInjectionTestCase
{
public function testLoadWithSeveralHandlers()
{
Expand Down
26 changes: 6 additions & 20 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\RequestStack;

class MonologExtensionTest extends DependencyInjectionTest
class MonologExtensionTest extends DependencyInjectionTestCase
{
public function testLoadWithDefault()
{
Expand Down Expand Up @@ -628,7 +628,7 @@ public function testV2Removed(array $handlerOptions)
$loader->load([['handlers' => ['main' => $handlerOptions]]], $container);
}

public function v2RemovedDataProvider(): array
public static function v2RemovedDataProvider(): array
{
return [
[['type' => 'hipchat', 'token' => 'abc123', 'room' => 'foo']],
Expand All @@ -637,33 +637,19 @@ public function v2RemovedDataProvider(): array
];
}

/**
* @dataProvider v1AddedDataProvider
*/
public function testV2AddedOnV1(string $handlerType)
public function testV2AddedOnV1()
{
if (Logger::API !== 1) {
$this->markTestSkipped('Only valid on Monolog V1');

return;
}

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(
\sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType)
);
$this->expectExceptionMessage('"fallbackgroup" was added in Monolog v2, please upgrade if you wish to use it.');

$container = new ContainerBuilder();
$loader = new MonologExtension();

$loader->load([['handlers' => ['main' => ['type' => $handlerType]]]], $container);
}

public function v1AddedDataProvider(): array
{
return [
['fallbackgroup'],
];
$loader->load([['handlers' => ['main' => ['type' => 'fallbackgroup']]]], $container);
}

/**
Expand All @@ -684,7 +670,7 @@ public function testLogLevelfromParameter(array $parameters, array $config, $exp
$this->assertDICConstructorArguments($definition, $expectedArgs);
}

public function provideLoglevelParameterConfig(): array
public static function provideLoglevelParameterConfig(): array
{
return [
'browser console with parameter level' => [
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/XmlMonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class XmlMonologExtensionTest extends FixtureMonologExtensionTest
class XmlMonologExtensionTest extends FixtureMonologExtensionTestCase
{
protected function loadFixture(ContainerBuilder $container, $fixture)
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/YamlMonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class YamlMonologExtensionTest extends FixtureMonologExtensionTest
class YamlMonologExtensionTest extends FixtureMonologExtensionTestCase
{
protected function loadFixture(ContainerBuilder $container, $fixture)
{
Expand Down

0 comments on commit 33bf5ca

Please sign in to comment.