Skip to content

Commit

Permalink
migrate to PHPUnit 11 (see #216)
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Oct 31, 2024
1 parent e39a262 commit 0c8b519
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
with:
composer-options: "--prefer-dist --no-scripts"

- # https://github.com/sebastianbergmann/phpunit/tree/10.5
name: Unit tests with PHPUnit 10
- # https://github.com/sebastianbergmann/phpunit/tree/11.4
name: Unit tests with PHPUnit 11
run: vendor/bin/phpunit --no-progress --testdox --do-not-cache-result
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
bootstrap="autoload.php"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
Expand Down
37 changes: 7 additions & 30 deletions tests/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Generator;
use Overtrue\PHPLint\Cache;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use Symfony\Component\Cache\CacheItem;

use function dirname;
Expand All @@ -28,6 +29,12 @@
* @author Laurent Laville
* @since Release 9.0.0
*/
#[CoversMethod(Cache::class, 'hasItem')]
#[CoversMethod(Cache::class, 'getItem')]
#[CoversMethod(Cache::class, 'saveItem')]
#[CoversMethod(Cache::class, 'clear')]
#[CoversMethod(Cache::class, 'isHit')]
#[CoversMethod(Cache::class, 'getCalls')]
final class CacheTest extends TestCase
{
private static Cache $cache;
Expand Down Expand Up @@ -65,17 +72,11 @@ static function ($key, $value, $isHit) {
self::$cache = $cache;
}

/**
* @covers \Overtrue\PHPLint\Cache::hasItem
*/
public function testHasItem(): void
{
$this->assertTrue(self::$cache->hasItem(__FILE__));
}

/**
* @covers \Overtrue\PHPLint\Cache::getItem
*/
public function testGetItem(): void
{
// expected
Expand All @@ -87,9 +88,6 @@ public function testGetItem(): void
$this->assertSame($item->get(), $cacheItem->get());
}

/**
* @covers \Overtrue\PHPLint\Cache::saveItem
*/
public function testSaveItem(): void
{
$filename = dirname(__DIR__) . '/EndToEnd/LintCommandTest.php';
Expand All @@ -103,59 +101,38 @@ public function testSaveItem(): void
$this->assertEquals($fingerprint, self::$cache->getItem($filename)->get());
}

/**
* @covers \Overtrue\PHPLint\Cache::clear
*/
public function testClearPool(): void
{
$cleared = self::$cache->clear();
$this->assertTrue($cleared);
}

/**
* @covers \Overtrue\PHPLint\Cache::isHit
*/
public function testCacheHit(): void
{
$this->assertTrue(self::$cache->isHit(__FILE__));
}

/**
* @covers \Overtrue\PHPLint\Cache::isHit
*/
public function testCacheMiss(): void
{
$this->assertFalse(self::$cache->isHit(dirname(__DIR__) . '/EndToEnd/LintCommandTest.php'));
}

/**
* @covers \Overtrue\PHPLint\Cache::isHit
*/
public function testCacheMissWithFileUnknown(): void
{
$this->assertFalse(self::$cache->isHit(dirname(__DIR__) . '/Finder/FinderTest.php'));
}

/**
* @covers \Overtrue\PHPLint\Cache::isHit
*/
public function testCacheMissWithWrongFileFingerprint(): void
{
$this->assertFalse(self::$cache->isHit(dirname(__DIR__) . '/Configuration/ConfigResolverTest.php'));
}

/**
* @covers \Overtrue\PHPLint\Cache::getCalls
*/
public function testGetCalls(): void
{
// cache init calls count
$this->assertCount(3, self::$cache->getCalls());
}

/**
* @covers \Overtrue\PHPLint\Cache::saveItem
*/
public function testFilenameHasReservedCharacters(): void
{
$filename = dirname(__DIR__) . '/EndToEnd/Reserved@Keywords.php';
Expand Down
15 changes: 5 additions & 10 deletions tests/Configuration/ConsoleConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
use Overtrue\PHPLint\Command\LintCommand;
use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver;
use Overtrue\PHPLint\Configuration\OptionDefinition;
use Overtrue\PHPLint\Configuration\OptionsFactory;
use Overtrue\PHPLint\Configuration\Resolver;
use Overtrue\PHPLint\Event\EventDispatcher;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\Console\Input\ArrayInput;

use Symfony\Component\OptionsResolver\OptionsResolver;

use function dirname;
use function realpath;

#[CoversMethod(ConsoleOptionsResolver::class, 'getOption')]
#[CoversMethod(ConsoleOptionsResolver::class, 'getOptions')]
final class ConsoleConfigTest extends TestCase
{
/**
* @covers \Overtrue\PHPLint\Configuration\ConsoleOptionsResolver::getOption
*/
public function testConfigFileNotReadable(): void
{
$dispatcher = new EventDispatcher([]);
Expand All @@ -44,10 +42,7 @@ public function testConfigFileNotReadable(): void
$this->assertFalse(realpath($resolver->getOption(OptionDefinition::CONFIGURATION)));
}

/**
* @covers \Overtrue\PHPLint\Configuration\ConsoleOptionsResolver::getOptions
* @dataProvider commandInputProvider
*/
#[DataProvider('commandInputProvider')]
public function testCommandConfig(array $arguments, callable $fetchExpected): void
{
$dispatcher = new EventDispatcher([]);
Expand Down
13 changes: 5 additions & 8 deletions tests/Configuration/YamlConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
use Overtrue\PHPLint\Command\LintCommand;
use Overtrue\PHPLint\Configuration\FileOptionsResolver;
use Overtrue\PHPLint\Configuration\OptionDefinition;
use Overtrue\PHPLint\Configuration\OptionsFactory;
use Overtrue\PHPLint\Configuration\Resolver;
use Overtrue\PHPLint\Event\EventDispatcher;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;

#[CoversMethod(FileOptionsResolver::class, 'getOption')]
#[CoversMethod(FileOptionsResolver::class, 'getOptions')]
final class YamlConfigTest extends TestCase
{
/**
* @covers \Overtrue\PHPLint\Configuration\FileOptionsResolver
*/
public function testInvalidYamlFile(): void
{
$this->expectException(InvalidOptionsException::class);
Expand All @@ -41,10 +41,7 @@ public function testInvalidYamlFile(): void
new FileOptionsResolver($input);
}

/**
* @covers \Overtrue\PHPLint\Configuration\FileOptionsResolver::getOptions
* @dataProvider commandInputProvider
*/
#[DataProvider('commandInputProvider')]
public function testYamlConfig(array $arguments, callable $fetchExpected): void
{
$dispatcher = new EventDispatcher([]);
Expand Down
9 changes: 2 additions & 7 deletions tests/EndToEnd/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Overtrue\PHPLint\Command\LintCommand;
use Overtrue\PHPLint\Console\Application;
use Overtrue\PHPLint\Event\EventDispatcher;
use Overtrue\PHPLint\Extension\OutputFormat;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -27,6 +27,7 @@
* @author Laurent Laville
* @since Release 9.0.0
*/
#[CoversMethod(LintCommand::class, '')]
final class LintCommandTest extends TestCase
{
private ?CommandTester $commandTester;
Expand Down Expand Up @@ -54,9 +55,6 @@ protected function tearDown(): void
$this->commandTester = null;
}

/**
* @covers \Overtrue\PHPLint\Command\LintCommand
*/
public function testLintDirectoryWithoutConfigurationAndCache(): void
{
$arguments = [
Expand All @@ -74,9 +72,6 @@ public function testLintDirectoryWithoutConfigurationAndCache(): void
);
}

/**
* @covers \Overtrue\PHPLint\Command\LintCommand
*/
public function testLintSyntaxErrorFileWithoutConfigurationAndCache(): void
{
$arguments = [
Expand Down
11 changes: 2 additions & 9 deletions tests/Finder/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Overtrue\PHPLint\Event\EventDispatcher;
use Overtrue\PHPLint\Finder;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use Symfony\Component\Console\Input\ArrayInput;

use function array_keys;
Expand All @@ -33,11 +34,9 @@
* @author Laurent Laville
* @since Release 9.0.0
*/
#[CoversMethod(Finder::class, 'getFiles')]
final class FinderTest extends TestCase
{
/**
* @covers \Overtrue\PHPLint\Finder::getFiles
*/
public function testAllPhpFilesFoundShouldExists(): void
{
$dispatcher = new EventDispatcher([]);
Expand All @@ -62,9 +61,6 @@ public function testAllPhpFilesFoundShouldExists(): void
}
}

/**
* @covers \Overtrue\PHPLint\Finder::getFiles
*/
public function testAllPathShouldExistsAndReadable(): void
{
$this->expectException(LogicException::class);
Expand All @@ -86,9 +82,6 @@ public function testAllPathShouldExistsAndReadable(): void
count($finder->getFiles());
}

/**
* @covers \Overtrue\PHPLint\Finder::getFiles
*/
public function testSearchPhpFilesWithCondition(): void
{
$dispatcher = new EventDispatcher([]);
Expand Down
5 changes: 2 additions & 3 deletions tests/Output/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Overtrue\PHPLint\Output\JunitOutput;
use Overtrue\PHPLint\Output\LinterOutput;
use Overtrue\PHPLint\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversMethod;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -37,6 +38,7 @@
* @author Laurent Laville
* @since Release 9.5.3
*/
#[CoversMethod(JunitOutput::class, 'format')]
final class OutputTest extends TestCase
{
private LinterOutput $linterOutput;
Expand Down Expand Up @@ -73,9 +75,6 @@ protected function setUp(): void
$this->linterOutput->setContext($configResolver, $startTime, 2, $defaults);
}

/**
* @covers \Overtrue\PHPLint\Output\JunitOutput::format
*/
public function testJunitOutput(): void
{
$stream = fopen('php://memory', 'w+');
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/phpunit/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^11.0"
}
}

0 comments on commit 0c8b519

Please sign in to comment.