Skip to content

Commit

Permalink
add support for phpunit 11 (#157)
Browse files Browse the repository at this point in the history
* phpunit 11

- added sebastian/exporter dependency

* attribute instead of annotation meta

* drop phpunit 9 support

* upped minimal phpunit dependency to 10.5.11
  • Loading branch information
wickedOne authored Apr 26, 2024
1 parent 2bd8962 commit 0fcb91f
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 271 deletions.
8 changes: 4 additions & 4 deletions PhpUnit/AbstractCompilerPassTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\DependencyInjection\ContainerBuilder;

abstract class AbstractCompilerPassTestCase extends AbstractContainerBuilderTestCase
Expand All @@ -16,11 +18,9 @@ abstract protected function registerCompilerPass(ContainerBuilder $container): v

/**
* This test will run the compile method.
*
* @test
*
* @coversNothing
*/
#[Test]
#[CoversNothing]
final public function compilation_should_not_fail_with_empty_container(): void
{
try {
Expand Down
7 changes: 5 additions & 2 deletions PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint
{
private $serviceId;
private $expectedClass;
private $checkExpectedClass;
private $exporter;

public function __construct(
string $serviceId,
Expand All @@ -20,6 +22,7 @@ public function __construct(
$this->serviceId = $serviceId;
$this->expectedClass = $expectedClass;
$this->checkExpectedClass = $checkExpectedClass;
$this->exporter = new Exporter();
}

public function toString(): string
Expand Down Expand Up @@ -85,8 +88,8 @@ private function evaluateClass(ContainerBuilder $containerBuilder, bool $returnR
$this->fail($containerBuilder, sprintf(
'The class of the service definition of "%s" (%s) does not match the expected value (%s)',
$this->serviceId,
$this->exporter()->export($actualClass),
$this->exporter()->export($this->expectedClass)
$this->exporter->export($actualClass),
$this->exporter->export($this->expectedClass)
));
}

Expand Down
7 changes: 5 additions & 2 deletions PhpUnit/ContainerHasParameterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\Constraint\IsIdentical;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\ContainerInterface;

final class ContainerHasParameterConstraint extends Constraint
Expand All @@ -13,6 +14,7 @@ final class ContainerHasParameterConstraint extends Constraint
private $expectedParameterValue;
private $checkParameterValue;
private $strict;
private $exporter;

public function __construct(
string $parameterName,
Expand All @@ -24,6 +26,7 @@ public function __construct(
$this->expectedParameterValue = $expectedParameterValue;
$this->checkParameterValue = $checkParameterValue;
$this->strict = $strict;
$this->exporter = new Exporter();
}

public function toString(): string
Expand Down Expand Up @@ -83,8 +86,8 @@ private function evaluateParameterValue(ContainerInterface $container, bool $ret
$this->fail($container, sprintf(
'The value of parameter "%s" (%s) does not match the expected value (%s)',
$this->parameterName,
$this->exporter()->export($actualValue),
$this->exporter()->export($this->expectedParameterValue)
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedParameterValue)
));
}

Expand Down
12 changes: 8 additions & 4 deletions PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -19,6 +20,7 @@ final class DefinitionArgumentEqualsServiceLocatorConstraint extends Constraint
private $argumentIndex;
private $expectedValue;
private $serviceId;
private $exporter;

public function __construct(string $serviceId, $argumentIndex, array $expectedValue)
{
Expand Down Expand Up @@ -54,6 +56,8 @@ function ($serviceId) {
},
$expectedValue
);

$this->exporter = new Exporter();
}

public function toString(): string
Expand Down Expand Up @@ -126,7 +130,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
sprintf(
'The value of argument with index %s (%s) was expected to an instance of Symfony\Component\DependencyInjection\Reference or \Symfony\Component\DependencyInjection\Definition',
$this->argumentIndex,
$this->exporter()->export($actualValue)
$this->exporter->export($actualValue)
)
);
}
Expand All @@ -141,7 +145,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
sprintf(
'The referenced service class of argument with index %s (%s) was expected to be an instance of Symfony\Component\DependencyInjection\ServiceLocator',
$this->argumentIndex,
$this->exporter()->export($serviceLocatorDef->getClass())
$this->exporter->export($serviceLocatorDef->getClass())
)
);
}
Expand Down Expand Up @@ -172,8 +176,8 @@ private function evaluateServiceDefinition(
sprintf(
'The value of argument with index %s (%s) does not equal to the expected ServiceLocator service-map (%s)',
$this->argumentIndex,
$this->exporter()->export($actualValue),
$this->exporter()->export($this->expectedValue)
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedValue)
)
);
}
Expand Down
11 changes: 7 additions & 4 deletions PhpUnit/DefinitionEqualsServiceLocatorConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -12,6 +13,7 @@
final class DefinitionEqualsServiceLocatorConstraint extends Constraint
{
private $expectedValue;
private $exporter;

public function __construct($expectedValue)
{
Expand All @@ -29,6 +31,7 @@ function ($serviceId) {
},
$expectedValue
);
$this->exporter = new Exporter();
}

public function toString(): string
Expand Down Expand Up @@ -70,8 +73,8 @@ private function evaluateServiceDefinitionClass(Definition $definition, bool $re
$definition,
sprintf(
'class %s was expected as service definition class, found %s instead',
$this->exporter()->export(ServiceLocator::class),
$this->exporter()->export($definition->getClass())
$this->exporter->export(ServiceLocator::class),
$this->exporter->export($definition->getClass())
)
);
}
Expand All @@ -90,8 +93,8 @@ private function evaluateArgumentIndex(Definition $definition, bool $returnResul
$definition,
sprintf(
'The service-map %s does not equal to the expected service-map (%s)',
$this->exporter()->export($actualValue),
$this->exporter()->export($this->expectedValue)
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedValue)
)
);
}
Expand Down
5 changes: 4 additions & 1 deletion PhpUnit/DefinitionHasMethodCallConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\Definition;

final class DefinitionHasMethodCallConstraint extends Constraint
{
private $methodName;
private $arguments;
private $index;
private $exporter;

public function __construct(string $methodName, array $arguments = [], $index = null)
{
Expand All @@ -21,6 +23,7 @@ public function __construct(string $methodName, array $arguments = [], $index =
$this->methodName = $methodName;
$this->arguments = $arguments;
$this->index = $index;
$this->exporter = new Exporter();
}

public function evaluate($other, string $description = '', bool $returnResult = false): bool
Expand Down Expand Up @@ -55,7 +58,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
sprintf(
'None of the method calls matched the expected method "%s" with arguments %s with %s invocation order index',
$this->methodName,
$this->exporter()->export($this->arguments),
$this->exporter->export($this->arguments),
(null === $this->index) ? 'any' : sprintf('"%s"', $this->index)
)
);
Expand Down
5 changes: 4 additions & 1 deletion PhpUnit/DefinitionHasTagConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\Definition;

final class DefinitionHasTagConstraint extends Constraint
{
private $name;
private $attributes;
private $exporter;

public function __construct(string $name, array $attributes = [])
{
$this->name = $name;
$this->attributes = $attributes;
$this->exporter = new Exporter();
}

public function evaluate($other, string $description = '', bool $returnResult = false): bool
Expand Down Expand Up @@ -42,7 +45,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
sprintf(
'None of the tags matched the expected name "%s" with attributes %s',
$this->name,
$this->exporter()->export($this->attributes)
$this->exporter->export($this->attributes)
)
);
}
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ container:

## Version Guidance

| Version | Released | PHPUnit | Status |
|---------|--------------|-------------|------------|
| 4.x | Mar 28, 2019 | 8.x and 9.x | Latest |
| 3.x | Mar 5, 2018 | 7.x | Bugfixes |
| 2.x | May 9, 2017 | 6.x | Bugfixes |
| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL |
| Version | Released | PHPUnit | Status |
|---------|--------------|-------------|----------|
| 5.x | Jan 23, 2024 | 9.x, 10.x | Latest |
| 4.x | Mar 28, 2019 | 8.x and 9.x | Bugfixes |
| 3.x | Mar 5, 2018 | 7.x | Bugfixes |
| 2.x | May 9, 2017 | 6.x | Bugfixes |
| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL |
13 changes: 5 additions & 8 deletions Tests/Loader/LoaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Matthias\SymfonyDependencyInjectionTest\Tests\Loader;

use Matthias\SymfonyDependencyInjectionTest\Loader\LoaderFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -13,11 +15,8 @@

class LoaderFactoryTest extends TestCase
{
/**
* @test
*
* @dataProvider fileProvider
*/
#[Test]
#[DataProvider('fileProvider')]
public function it_creates_the_appropriate_file_loader_based_on_the_extension($file, $expectedClass): void
{
$factory = new LoaderFactory();
Expand All @@ -26,9 +25,7 @@ public function it_creates_the_appropriate_file_loader_based_on_the_extension($f
$this->assertInstanceOf($expectedClass, $loader);
}

/**
* @test
*/
#[Test]
public function it_creates_a_closure_loader_when_source_is_a_closure(): void
{
$source = function (): void {
Expand Down
9 changes: 3 additions & 6 deletions Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndAddThemWithMethodCallsCompilerPass;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndSetThemAsArgumentCompilerPass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -17,9 +18,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void
$container->addCompilerPass(new CollectServicesAndSetThemAsArgumentCompilerPass());
}

/**
* @test
*/
#[Test]
public function if_compiler_pass_collects_services_by_adding_method_calls_these_can_be_asserted_to_exist(): void
{
$collectingService = new Definition();
Expand Down Expand Up @@ -52,9 +51,7 @@ public function if_compiler_pass_collects_services_by_adding_method_calls_these_
);
}

/**
* @test
*/
#[Test]
public function if_compiler_pass_collects_services_by_setting_constructor_argument_it_can_be_asserted_to_exist(): void
{
$collectingService = new Definition();
Expand Down
5 changes: 2 additions & 3 deletions Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\DependableExtension;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonDependablePrependableExtension;
use PHPUnit\Framework\Attributes\Test;

class AbstractDependableExtensionTestCaseTest extends AbstractExtensionTestCase
{
Expand All @@ -16,9 +17,7 @@ protected function getContainerExtensions(): array
];
}

/**
* @test
*/
#[Test]
public function prepend_invoked_before_any_load(): void
{
$this->load();
Expand Down
5 changes: 2 additions & 3 deletions Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleConfiguration;
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleExtension;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
Expand All @@ -21,9 +22,7 @@ protected function getConfiguration(): ConfigurationInterface
return new SimpleConfiguration();
}

/**
* @test
*/
#[Test]
public function it_compares_expected_configuration_values_with_values_loaded_from_files(): void
{
$sources = [
Expand Down
Loading

0 comments on commit 0fcb91f

Please sign in to comment.