From 0979bbb835f3e57963d9fb50defd21e81bc81459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Mon, 16 Dec 2024 16:52:39 +0100 Subject: [PATCH] Support PHP>8.1 --- .github/workflows/code.yml | 11 ++--- .github/workflows/sonar.yml | 4 +- .github/workflows/tests.yml | 2 +- .gitignore | 1 + .php-cs-fixer.dist.php | 3 ++ CHANGELOG.md | 6 +++ compose.yaml | 4 +- composer.json | 8 ++-- phpstan.neon.dist | 6 ++- phpunit.xml.dist | 15 +++++- run | 8 +++- src/Document.php | 12 ++--- src/FrontMatter.php | 36 ++++++--------- src/FrontMatterChain.php | 5 +- src/FrontMatterInterface.php | 4 -- src/Processor/ProcessorInterface.php | 4 -- src/Processor/YamlProcessor.php | 11 +++++ src/Twig/DataToTwigConvertor.php | 46 +++++++++---------- src/Twig/FrontMatterLoader.php | 5 +- tests/DocumentTest.php | 5 ++ tests/FrontMatterChainTest.php | 25 +++++----- tests/FrontMatterTest.php | 33 ++++++------- ...ontMatterLeagueCommonMarkExtensionTest.php | 12 +++-- tests/Processor/ProcessorDecoratorTest.php | 9 ++-- tests/Pug/PugCommentFrontMatterTest.php | 5 ++ tests/Twig/DataToTwigConvertorTest.php | 7 ++- tests/Twig/FrontMatterLoaderTest.php | 15 ++++-- tests/Twig/TwigCommentFrontMatterTest.php | 5 ++ 28 files changed, 171 insertions(+), 136 deletions(-) diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index fd7a92c..3230019 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -12,15 +12,9 @@ jobs: strategy: matrix: deps_strategy: [ '', '--prefer-lowest' ] - php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] + php: [ '8.1', '8.2', '8.3', '8.4' ] symfony: [ ^3.0, ^4.0, ^5.0, ^6.0, ^7.0 ] exclude: - - php: '7.4' - symfony: ^6.0 - - php: '7.4' - symfony: ^7.0 - - php: '8.0' - symfony: ^7.0 - php: '8.1' symfony: ^7.0 steps: @@ -31,7 +25,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - coverage: pcov tools: composer:v2 - name: Install dependencies @@ -39,6 +32,8 @@ jobs: - name: Code style run: vendor/bin/php-cs-fixer fix --ansi --allow-risky=yes --dry-run + env: + PHP_CS_FIXER_IGNORE_ENV: 1 - name: Code quality run: vendor/bin/phpstan analyse --no-progress --ansi diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 031d97e..c691592 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -21,7 +21,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.4 coverage: xdebug tools: composer:v2 @@ -32,7 +32,7 @@ jobs: run: vendor/bin/phpunit --coverage-clover=coverage.xml - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: SonarSource/sonarqube-scan-action@4.2.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 76a3eca..874db25 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: deps_strategy: [ '', '--prefer-lowest' ] - php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] + php: [ '8.1', '8.2', '8.3', '8.4' ] steps: - name: Update code uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index a86443f..dc431ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .phpunit.result.cache .runner composer.lock +coverage/ phpstan.neon phpunit.xml psalm.xml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f11665a..53a1390 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -12,10 +12,13 @@ return (new PhpCsFixer\Config()) ->setRules([ + '@PhpCsFixer' => true, '@PSR12:risky' => true, + '@PHP84Migration' => true, 'header_comment' => [ 'header' => $header, ], + 'php_unit_attributes' => true, ]) ->setLineEnding("\n") ->setUsingCache(false) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe80a6e..80c85db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +2.1.0 (2024-12-xx) +------------------ + +* PHP 8.4 support +* Drop PHP 7 support + 2.0.0 (2024-02-22) ------------------ diff --git a/compose.yaml b/compose.yaml index cfe05a4..2db9949 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,10 +1,12 @@ services: php: - image: "minidocks/php:${PHP_VERSION:-8.3}" + image: "minidocks/php:${PHP_VERSION:-8.4}" volumes: - .:$PWD - ~/.composer/cache:/composer-cache - ~/.composer/auth.json:/composer/auth.json environment: PATH_SUFFIX: './vendor/bin' + PHP_EXT_XDEBUG: 1 + PHP_XDEBUG__MODE: coverage working_dir: $PWD diff --git a/composer.json b/composer.json index 0f8fdeb..a904a01 100644 --- a/composer.json +++ b/composer.json @@ -24,17 +24,17 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "symfony/yaml": "^3.4.31 || ^4.3.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "ext-json": "*", - "friendsofphp/php-cs-fixer": "^3.41", + "friendsofphp/php-cs-fixer": "^3.65", "league/commonmark": "^2.0", "mthaml/mthaml": "^1.3", "nette/neon": "^2.2 || ^3.0", - "phpunit/phpunit": "^9.6", - "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.5", + "phpstan/phpstan": "^2.0", "twig/twig": "^3.0", "yosymfony/toml": "^1.0" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c93b6a8..48e229c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,8 @@ parameters: - level: 8 + level: 10 paths: - src - tests - checkMissingIterableValueType: false + ignoreErrors: + - + identifier: missingType.iterableValue diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 81a95fe..cafcc08 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,20 @@ - - + + ./src + + + diff --git a/run b/run index fa86098..36f3f3f 100755 --- a/run +++ b/run @@ -28,11 +28,11 @@ task_composer__normalize()( composer normalize "$@" ) # Run tests # @service php -task_tests()( phpunit --colors=always "$@" ) +task_tests()( XDEBUG_MODE=coverage phpunit --colors=always --coverage-html coverage "$@" ) # Fix code style # @service php -task_cs()( php-cs-fixer fix --ansi --allow-risky=yes "$@" ) +task_cs()( PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --ansi --allow-risky=yes "$@" ) # Analyse code # @service php @@ -44,3 +44,7 @@ task_clean()( _docker_compose down --remove-orphans "$@" ) # Run shell with tools # @service php task_tools()( sh "$@" ) + +task_act__tests__latest()( + act -j phpunit --matrix php:8.4 --matrix deps_strategy: +) diff --git a/src/Document.php b/src/Document.php index dae4883..4c492f7 100644 --- a/src/Document.php +++ b/src/Document.php @@ -21,7 +21,6 @@ class Document private $data; /** - * @param string $content * @param array $data */ public function __construct(string $content = '', array $data = []) @@ -30,6 +29,11 @@ public function __construct(string $content = '', array $data = []) $this->data = $data; } + public function __toString(): string + { + return $this->content; + } + public function getContent(): string { return $this->content; @@ -57,6 +61,7 @@ public function setContent(string $content): self /** * @param array $data + * * @return $this */ public function setData(array $data): self @@ -65,9 +70,4 @@ public function setData(array $data): self return $this; } - - public function __toString(): string - { - return $this->content; - } } diff --git a/src/FrontMatter.php b/src/FrontMatter.php index 2bd8e83..3d8590c 100644 --- a/src/FrontMatter.php +++ b/src/FrontMatter.php @@ -24,6 +24,14 @@ final class FrontMatter implements FrontMatterInterface private ProcessorInterface $processor; private string $regexp; + public function __construct(?ProcessorInterface $processor = null, string $startSep = '---', string $endSep = '---') + { + $this->startSep = $startSep; + $this->endSep = $endSep; + $this->processor = $processor ?: new YamlProcessor(); + $this->regexp = $this->getRegExp($startSep, $endSep); + } + public static function createYaml(): self { return new self(new YamlProcessor(), '---', '---'); @@ -39,20 +47,9 @@ public static function createJson(): self return new self(new JsonWithoutBracesProcessor(), '{', '}'); } - public function __construct(?ProcessorInterface $processor = null, string $startSep = '---', string $endSep = '---') - { - $this->startSep = $startSep; - $this->endSep = $endSep; - $this->processor = $processor ?: new YamlProcessor(); - $this->regexp = $this->getRegExp($startSep, $endSep); - } - - /** - * {@inheritdoc} - */ public function parse(string $source): Document { - if (preg_match($this->regexp, $source, $matches) !== 1) { + if (1 !== preg_match($this->regexp, $source, $matches)) { return new Document($source); } @@ -64,9 +61,6 @@ public function parse(string $source): Document return new Document($matches[2], $data); } - /** - * {@inheritdoc} - */ public function dump(Document $document): string { $data = trim($this->processor->dump($document->getData())); @@ -77,12 +71,9 @@ public function dump(Document $document): string return sprintf("%s\n%s\n%s\n%s", $this->startSep, $data, $this->endSep, $document->getContent()); } - /** - * {@inheritdoc} - */ public function exists(string $source): bool { - return preg_match($this->regexp, $source) === 1; + return 1 === preg_match($this->regexp, $source); } private function cancelIndentation(string $string): string @@ -93,16 +84,17 @@ private function cancelIndentation(string $string): string return trim($string); } - return trim((string) preg_replace("/^$indent/m", '', $string)); + return trim((string) preg_replace("/^{$indent}/m", '', $string)); } private function revealIndention(string $string): string { $separator = "\r\n"; $line = strtok($string, $separator); - while ($line !== false) { - if (trim($line) !== '') { + while (false !== $line) { + if ('' !== trim($line)) { preg_match('/^(\s+)/', $line, $match); + return $match[1] ?? ''; } $line = strtok($separator); diff --git a/src/FrontMatterChain.php b/src/FrontMatterChain.php index b5fcf82..4bf2ca6 100644 --- a/src/FrontMatterChain.php +++ b/src/FrontMatterChain.php @@ -12,7 +12,6 @@ namespace Webuni\FrontMatter; -use InvalidArgumentException; use Webuni\FrontMatter\Pug\PugCommentFrontMatter; use Webuni\FrontMatter\Twig\TwigCommentFrontMatter; @@ -25,14 +24,14 @@ public function __construct(iterable $adapters) { foreach ($adapters as $adapter) { if (!$adapter instanceof FrontMatterInterface) { - throw new InvalidArgumentException('Adapter should be instance of '.FrontMatterInterface::class); + throw new \InvalidArgumentException('Adapter should be instance of '.FrontMatterInterface::class); } $this->adapters[] = $adapter; } if (empty($this->adapters)) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( 'It is necessary add at least one front matter adapter '.FrontMatterInterface::class ); } diff --git a/src/FrontMatterInterface.php b/src/FrontMatterInterface.php index b7aa477..1421c30 100644 --- a/src/FrontMatterInterface.php +++ b/src/FrontMatterInterface.php @@ -30,8 +30,6 @@ public function exists(string $source): bool; * Parse source. * * @param string $source The source - * - * @return Document */ public function parse(string $source): Document; @@ -39,8 +37,6 @@ public function parse(string $source): Document; * Dump document. * * @param Document $document The document - * - * @return string */ public function dump(Document $document): string; } diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index d82446e..72c62bc 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -18,8 +18,6 @@ interface ProcessorInterface * Parses front matter string into a data. * * @param string $string The string - * - * @return array */ public function parse(string $string): array; @@ -27,8 +25,6 @@ public function parse(string $string): array; * Dumps a data to a string. * * @param array $data The data - * - * @return string */ public function dump(array $data): string; } diff --git a/src/Processor/YamlProcessor.php b/src/Processor/YamlProcessor.php index b4e6a94..31d928a 100644 --- a/src/Processor/YamlProcessor.php +++ b/src/Processor/YamlProcessor.php @@ -16,11 +16,22 @@ final class YamlProcessor implements ProcessorInterface { + /** + * @var int-mask-of + */ private int $parseFlags; + + /** + * @var int-mask-of + */ private int $dumpFlags; private int $inline; private int $indent; + /** + * @param int-mask-of $parseFlags + * @param int-mask-of $dumpFlags + */ public function __construct(int $parseFlags = 0, int $dumpFlags = 0, int $inline = 2, int $indent = 4) { $this->parseFlags = $parseFlags; diff --git a/src/Twig/DataToTwigConvertor.php b/src/Twig/DataToTwigConvertor.php index 39b75e0..4085f9b 100644 --- a/src/Twig/DataToTwigConvertor.php +++ b/src/Twig/DataToTwigConvertor.php @@ -12,13 +12,16 @@ namespace Webuni\FrontMatter\Twig; -use DateTimeInterface; - class DataToTwigConvertor { - /** @var callable */ + /** @var callable(array): string */ private $convertor; + protected function __construct(callable $convertor) + { + $this->convertor = $convertor; + } + public function __invoke(array $data): string { $convertor = $this->convertor; @@ -26,39 +29,32 @@ public function __invoke(array $data): string return (string) $convertor($data); } - protected function __construct(callable $convertor) - { - $this->convertor = $convertor; - } - /** - * Data will not be written to the twig template - * - * @return self + * Data will not be written to the twig template. */ public static function nothing(): self { - return new self(function () { + return new self(static function (): string { return ''; }); } /** * @psalm-suppress MixedAssignment + * * @param bool $force Define the value of the variable even if it is passed to the template - * @return self */ public static function vars(bool $force = true): self { - return new self(function (array $data) use ($force) { + return new self(static function (array $data) use ($force): string { $content = ''; foreach ($data as $key => $value) { if (is_int($key)) { - //TODO add log + // TODO add log continue; } - $value = ($force ? '' : "$key is defined ? $key : ") . self::valueToTwig($value); + $value = ($force ? '' : "{$key} is defined ? {$key} : ").self::valueToTwig($value); $content .= "{% set {$key} = {$value} %}\n"; } @@ -67,16 +63,15 @@ public static function vars(bool $force = true): self } /** - * Converts data to one twig variable + * Converts data to one twig variable. * * @param string $name Variable name * @param bool $force Define the value of the variable even if it is passed to the template - * @return self */ public static function var(string $name, bool $force = true): self { - return new self(function (array $data) use ($name, $force) { - $value = ($force ? '' : "$name is defined ? $name : ") . self::valueToTwig($data); + return new self(static function (array $data) use ($name, $force): string { + $value = ($force ? '' : "{$name} is defined ? {$name} : ").self::valueToTwig($data); return "{% set {$name} = {$value} %}\n"; }); @@ -84,21 +79,22 @@ public static function var(string $name, bool $force = true): self /** * @psalm-suppress MixedAssignment + * * @param mixed $value - * @return string */ protected static function valueToTwig($value): string { - if ($value instanceof DateTimeInterface) { - return '(' . $value->getTimestamp() . "|date_modify('0sec'))"; + if ($value instanceof \DateTimeInterface) { + return '('.$value->getTimestamp()."|date_modify('0sec'))"; } if (is_array($value)) { $twig = '{'; foreach ($value as $key => $val) { - $twig .= "$key: ".static::valueToTwig($val).", "; + $twig .= "{$key}: ".static::valueToTwig($val).', '; } - return $twig."}"; + + return $twig.'}'; } return (string) json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/src/Twig/FrontMatterLoader.php b/src/Twig/FrontMatterLoader.php index 1c20631..c374642 100644 --- a/src/Twig/FrontMatterLoader.php +++ b/src/Twig/FrontMatterLoader.php @@ -31,8 +31,7 @@ public function __construct( FrontMatterInterface $parser, LoaderInterface $loader, ?DataToTwigConvertor $convertor = null - ) - { + ) { $this->loader = $loader; $this->parser = $parser; $this->convertor = $convertor ?? DataToTwigConvertor::nothing(); @@ -66,7 +65,7 @@ public function getSourceContext(string $name): Source $content = ($this->convertor)($document->getData()).$content; - $lines = substr_count($code, "\n", 0, - strlen($content)); + $lines = substr_count($code, "\n", 0, -strlen($content)); $content = str_repeat("\n", $lines + 1).$content; return new Source($content, $source->getName(), $source->getPath()); diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index bcaa36c..9d528ae 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -12,9 +12,14 @@ namespace Webuni\FrontMatter\Tests; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\Document; +/** + * @internal + */ +#[CoversNothing] final class DocumentTest extends TestCase { public function testReturnContent(): void diff --git a/tests/FrontMatterChainTest.php b/tests/FrontMatterChainTest.php index 117bfbc..14c911c 100644 --- a/tests/FrontMatterChainTest.php +++ b/tests/FrontMatterChainTest.php @@ -12,14 +12,17 @@ namespace Webuni\FrontMatter\Tests; -use ArrayObject; -use InvalidArgumentException; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\Document; -use Webuni\FrontMatter\FrontMatter; use Webuni\FrontMatter\FrontMatterChain; use Webuni\FrontMatter\FrontMatterInterface; +/** + * @internal + */ +#[CoversNothing] final class FrontMatterChainTest extends TestCase { private FrontMatterChain $chain; @@ -31,7 +34,7 @@ protected function setUp(): void public function testEmptyAdapters(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage( 'It is necessary add at least one front matter adapter '.FrontMatterInterface::class ); @@ -41,23 +44,19 @@ public function testEmptyAdapters(): void public function testInvalidArrayOfAdapters(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Adapter should be instance of '.FrontMatterInterface::class); - new FrontMatterChain([new ArrayObject()]); + new FrontMatterChain([new \ArrayObject()]); } - /** - * @dataProvider getFrontMatter - */ + #[DataProvider('getFrontMatter')] public function testExists(string $source, array $data, string $content, bool $exists): void { self::assertSame($exists, $this->chain->exists($source)); } - /** - * @dataProvider getFrontMatter - */ + #[DataProvider('getFrontMatter')] public function testParse(string $source, array $data, string $content): void { $document = $this->chain->parse($source); @@ -74,7 +73,7 @@ public function testDumpViaFirstAdapter(): void public static function getFrontMatter(): array { return [ - ["Content", [], 'Content', false], + ['Content', [], 'Content', false], ["---\nfoo: bar\n---\nContent", ['foo' => 'bar'], 'Content', true], ["{\n \"foo\": \"bar\"\n}\nContent", ['foo' => 'bar'], 'Content', true], ]; diff --git a/tests/FrontMatterTest.php b/tests/FrontMatterTest.php index 4fee1d1..799674b 100644 --- a/tests/FrontMatterTest.php +++ b/tests/FrontMatterTest.php @@ -12,6 +12,8 @@ namespace Webuni\FrontMatter\Tests; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\Document; use Webuni\FrontMatter\FrontMatter; @@ -20,11 +22,13 @@ use Webuni\FrontMatter\Processor\NeonProcessor; use Webuni\FrontMatter\Processor\TomlProcessor; +/** + * @internal + */ +#[CoversNothing] final class FrontMatterTest extends TestCase { - /** - * @dataProvider getYaml - */ + #[DataProvider('getYaml')] public function testYaml(string $string, array $data, string $content, bool $hasFrontMatter): void { $frontMatter = new FrontMatter(); @@ -51,16 +55,13 @@ public function testEmptyYaml(): void self::assertDocument([], 'Content', $document); } - /** - * @dataProvider getSeparator - */ + #[DataProvider('getSeparator')] public function testYamlWithCustomSeparator( string $string, array $data, string $content, bool $hasFrontMatter - ): void - { + ): void { $frontMatter = new FrontMatter(null, ''); $document = $frontMatter->parse($string); @@ -69,9 +70,7 @@ public function testYamlWithCustomSeparator( self::assertEquals($string, $frontMatter->dump($document)); } - /** - * @dataProvider getJson - */ + #[DataProvider('getJson')] public function testJson(string $string, array $data, string $content, bool $hasFrontMatter): void { $frontMatter = new FrontMatter(new JsonProcessor()); @@ -82,9 +81,7 @@ public function testJson(string $string, array $data, string $content, bool $has self::assertEquals($string, $frontMatter->dump($document)); } - /** - * @dataProvider getPlainJson - */ + #[DataProvider('getPlainJson')] public function testPlainJson(string $string, array $data, string $content, bool $hasFrontMatter): void { $frontMatter = new FrontMatter(new JsonWithoutBracesProcessor(), '{', '}'); @@ -95,9 +92,7 @@ public function testPlainJson(string $string, array $data, string $content, bool self::assertEquals($string, $frontMatter->dump($document)); } - /** - * @dataProvider getYaml - */ + #[DataProvider('getYaml')] public function testNeon(string $string, array $data, string $content, bool $hasFrontMatter): void { $frontMatter = new FrontMatter(new NeonProcessor()); @@ -108,9 +103,7 @@ public function testNeon(string $string, array $data, string $content, bool $has self::assertEquals($string, $frontMatter->dump($document)); } - /** - * @dataProvider getToml - */ + #[DataProvider('getToml')] public function testToml(string $string, array $data, string $content, bool $hasFrontMatter): void { $frontMatter = new FrontMatter(new TomlProcessor()); diff --git a/tests/Markdown/FrontMatterLeagueCommonMarkExtensionTest.php b/tests/Markdown/FrontMatterLeagueCommonMarkExtensionTest.php index 9a8a48a..3c7df9a 100644 --- a/tests/Markdown/FrontMatterLeagueCommonMarkExtensionTest.php +++ b/tests/Markdown/FrontMatterLeagueCommonMarkExtensionTest.php @@ -12,16 +12,20 @@ namespace Webuni\FrontMatter\Tests\Markdown; -use League\CommonMark\DocParser; -use League\CommonMark\Environment as Environment1; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Parser\MarkdownParser; use League\CommonMark\Renderer\HtmlRenderer; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\FrontMatter; use Webuni\FrontMatter\Markdown\FrontMatterLeagueCommonMarkExtension; +/** + * @internal + */ +#[CoversNothing] final class FrontMatterLeagueCommonMarkExtensionTest extends TestCase { private Environment $environment; @@ -36,9 +40,7 @@ protected function setUp(): void $this->environment = $environment; } - /** - * @dataProvider getData - */ + #[DataProvider('getData')] public function testConvert(string $markdown, string $html, array $data): void { $parser = new MarkdownParser($this->environment); diff --git a/tests/Processor/ProcessorDecoratorTest.php b/tests/Processor/ProcessorDecoratorTest.php index bf0550c..712b4aa 100644 --- a/tests/Processor/ProcessorDecoratorTest.php +++ b/tests/Processor/ProcessorDecoratorTest.php @@ -12,11 +12,16 @@ namespace Processor; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\Processor\ProcessorDecorator; use Webuni\FrontMatter\Processor\ProcessorInterface; +/** + * @internal + */ +#[CoversNothing] final class ProcessorDecoratorTest extends TestCase { private MockObject $wrapped; @@ -41,6 +46,4 @@ public function testDump(): void } } -final class DummyProcessorDecorator extends ProcessorDecorator -{ -} +final class DummyProcessorDecorator extends ProcessorDecorator {} diff --git a/tests/Pug/PugCommentFrontMatterTest.php b/tests/Pug/PugCommentFrontMatterTest.php index d69b491..67b985f 100644 --- a/tests/Pug/PugCommentFrontMatterTest.php +++ b/tests/Pug/PugCommentFrontMatterTest.php @@ -12,10 +12,15 @@ namespace Pug; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\FrontMatter; use Webuni\FrontMatter\Pug\PugCommentFrontMatter; +/** + * @internal + */ +#[CoversNothing] final class PugCommentFrontMatterTest extends TestCase { public function testCreate(): void diff --git a/tests/Twig/DataToTwigConvertorTest.php b/tests/Twig/DataToTwigConvertorTest.php index 26f727f..93beee1 100644 --- a/tests/Twig/DataToTwigConvertorTest.php +++ b/tests/Twig/DataToTwigConvertorTest.php @@ -12,17 +12,22 @@ namespace Webuni\FrontMatter\Tests\Twig; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Yaml; use Webuni\FrontMatter\Twig\DataToTwigConvertor; +/** + * @internal + */ +#[CoversNothing] final class DataToTwigConvertorTest extends TestCase { private array $data; protected function setUp(): void { - $this->data = Yaml::parse((string) file_get_contents(__DIR__.'/data.yaml'), Yaml::PARSE_DATETIME); + $this->data = (array) Yaml::parse((string) file_get_contents(__DIR__.'/data.yaml'), Yaml::PARSE_DATETIME); } public function testNothing(): void diff --git a/tests/Twig/FrontMatterLoaderTest.php b/tests/Twig/FrontMatterLoaderTest.php index ffca1d5..b66cb7f 100644 --- a/tests/Twig/FrontMatterLoaderTest.php +++ b/tests/Twig/FrontMatterLoaderTest.php @@ -12,6 +12,8 @@ namespace Webuni\FrontMatter\Tests\Twig; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Twig\Loader\LoaderInterface; @@ -19,10 +21,15 @@ use Webuni\FrontMatter\FrontMatter; use Webuni\FrontMatter\Twig\FrontMatterLoader; +/** + * @internal + */ +#[CoversNothing] final class FrontMatterLoaderTest extends TestCase { private FrontMatter $frontMatter; - /** @var MockObject&LoaderInterface */ + + /** @var LoaderInterface&MockObject */ private MockObject $originalLoader; private FrontMatterLoader $loader; @@ -54,9 +61,7 @@ public function testExists(): void self::assertTrue($loader->exists($name)); } - /** - * @dataProvider getSource - */ + #[DataProvider('getSource')] public function testGetSourceContext(string $source, string $content, array $data): void { $name = 'name'; @@ -75,7 +80,7 @@ public function testGetSourceContext(string $source, string $content, array $dat public static function getSource(): array { return [ - ["{{ foo }}", '{{ foo }}', []], + ['{{ foo }}', '{{ foo }}', []], ["---\nfoo: bar\n---\n{{ foo }}", "\n\n\n\n{{ foo }}", ['foo' => 'bar']], ]; } diff --git a/tests/Twig/TwigCommentFrontMatterTest.php b/tests/Twig/TwigCommentFrontMatterTest.php index 3fc00eb..0a9e222 100644 --- a/tests/Twig/TwigCommentFrontMatterTest.php +++ b/tests/Twig/TwigCommentFrontMatterTest.php @@ -12,10 +12,15 @@ namespace Webuni\FrontMatter\Tests\Twig; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use Webuni\FrontMatter\FrontMatter; use Webuni\FrontMatter\Twig\TwigCommentFrontMatter; +/** + * @internal + */ +#[CoversNothing] final class TwigCommentFrontMatterTest extends TestCase { public function testCreate(): void