Skip to content

Commit

Permalink
Upgrade Infection to version 0.28 and refactor tests
Browse files Browse the repository at this point in the history
The Infection testing tool has been updated to version 0.28 from 0.27. This required some refactors in the tests in DecodingTest.php, updating attributes and changing the test functions to be more concise. Additionally, a bootstrap file was added for PHPUnit, and minor changes were made to the Rector and ECS configurations.
  • Loading branch information
Spomky committed Apr 12, 2024
1 parent e9ca7ad commit 6f8ad4b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 43 deletions.
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
"require": {
"php": ">=8.0",
"spomky-labs/cbor-php": "^3.0",
"symfony/config": "^5.3|^6.0",
"symfony/dependency-injection": "^5.3|^6.0",
"symfony/http-kernel": "^5.3|^6.0"
"symfony/config": "^5.3|^6.0|^7.0",
"symfony/dependency-injection": "^5.3|^6.0|^7.0",
"symfony/http-kernel": "^5.3|^6.0|^7.0"
},
"require-dev": {
"infection/infection": "^0.27",
"infection/infection": "^0.28",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.0",
"rector/rector": "^0.16",
"symfony/framework-bundle": "^5.3|^6.0",
"symfony/phpunit-bridge": "^5.3|^6.0",
"symplify/easy-coding-standard": "^11.0"
"phpunit/phpunit": "^10.1|^11.0",
"rector/rector": "^1.0",
"symfony/framework-bundle": "^5.3|^6.0|^7.0",
"symfony/phpunit-bridge": "^5.3|^6.0|^7.0",
"symplify/easy-coding-standard": "^12.0"
},
"config": {
"sort-packages": true,
Expand Down
13 changes: 9 additions & 4 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
$config->import(SetList::NAMESPACES);
$config->import(SetList::STRICT);

$services = $config->services();
$config->rule(StrictParamFixer::class);
$config->rule(StrictComparisonFixer::class);
$config->rule(ArrayIndentationFixer::class);
Expand Down Expand Up @@ -89,9 +88,15 @@
'import_functions' => true,
]);

$config->services()
->remove(PhpUnitTestClassRequiresCoversFixer::class);
$config->parallel();
$config->paths([__DIR__]);
$config->skip([__DIR__ . '/.github', __DIR__ . '/build', __DIR__ . '/vendor', __DIR__ . '/var']);
$config->skip(
[
__DIR__ . '/.github',
__DIR__ . '/build',
__DIR__ . '/vendor',
__DIR__ . '/var',
PhpUnitTestClassRequiresCoversFixer::class,
]
);
};
31 changes: 17 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory>./vendor</directory>
<directory>./tests</directory>
</exclude>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
Expand All @@ -21,7 +18,13 @@
<ini name="memory_limit" value="-1"/>
<server name="KERNEL_CLASS" value="SpomkyLabs\CborBundle\Tests\AppKernel"/>
</php>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<source>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./vendor</directory>
<directory>./tests</directory>
</exclude>
</source>
</phpunit>
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $config): void {
$config->import(SetList::DEAD_CODE);
$config->import(LevelSetList::UP_TO_PHP_80);
$config->import(\Rector\PHPUnit\Set\PHPUnitLevelSetList::UP_TO_PHPUNIT_100);
$config->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
$config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES);
$config->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$config->parallel();
$config->paths([__DIR__ . '/src', __DIR__ . '/tests']);
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/Compiler/OtherObjectCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ final class OtherObjectCompilerPass implements CompilerPassInterface
{
public const TAG = 'cbor.other_object';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if (! $container->hasDefinition(OtherObjectManagerInterface::class)) {
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/Compiler/TagCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ final class TagCompilerPass implements CompilerPassInterface
{
public const TAG = 'cbor.tag';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if (! $container->hasDefinition(TagManagerInterface::class)) {
Expand Down
2 changes: 1 addition & 1 deletion src/SpomkyLabsCborBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getContainerExtension(): SpomkyLabsCborExtension
return new SpomkyLabsCborExtension();
}

public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new TagCompilerPass());
Expand Down
20 changes: 12 additions & 8 deletions tests/Functional/DecodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@

use CBOR\Decoder;
use CBOR\Normalizable;
use function is_string;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Test;
use RuntimeException;
use SpomkyLabs\CborBundle\CBORDecoder;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use function is_string;

/**
* @internal
*/
final class DecodingTest extends KernelTestCase
{
/**
#[Test]
public static /**
* @test
*/
public static function theDecoderServiceIsAvailable(): void
function theDecoderServiceIsAvailable(): void
{
//Given
static::bootKernel();
Expand All @@ -28,13 +32,13 @@ public static function theDecoderServiceIsAvailable(): void
static::assertTrue(static::getContainer()->has(Decoder::class));
}

/**
#[Test]
#[DataProvider('getInputs')]
#[Depends('testTheDecoderServiceIsAvailable')]
public static /**
* @test
* @depends theDecoderServiceIsAvailable
*
* @dataProvider getInputs
*/
public static function theDecoderCanDecodeInputs(string $data, string $expectedNormalizedValue): void
function theDecoderCanDecodeInputs(string $data, string $expectedNormalizedValue): void
{
//Given
static::bootKernel();
Expand Down
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

use Symfony\Component\ErrorHandler\ErrorHandler;

ErrorHandler::register(null, false);

0 comments on commit 6f8ad4b

Please sign in to comment.