Skip to content

test: Use PHPUnit attributes for Kirby\Text #7201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: v5/develop
Choose a base branch
from

Conversation

distantnative
Copy link
Member

@distantnative distantnative commented May 11, 2025

Description

This highlights some problems in our test setup: Tests classes linked to EmailKirbyTagTest are only supposed to cover the code from config/tags.php. However, there is no (known) way with PHPUnit to limit code coverage to this. Adding CoversNothing in this PR leaves a lot in config/tags.php marked not covered, even when we have tests. At the same time it reveals some other actually uncovered parts in our code, which get marked covered by e.g. tests in EmailKirbyTagTest when we don't add any coverage limitation attributes.

We should also move for KirbyTags to class-based code where we then can test the core KirbyTags in their dedicated classes each. We can still support the array notation for plugins.

Summary of changes

  • Use CoversClass, CoversNothing and DataProvider PHPUnit PHP attributes instead of DocBlock annotations in the Kirby\Text package

Reasoning

Switching over package by package (or smaller units) to see how the code coverage is affected.

Additional context

Put this for the 5.1.0 milestone to not further add to the list of the 5.0.0 milestone as we want to close this very soon.

The changes were created automatically with Rector:

<?php

declare(strict_types = 1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector;
use Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
	->withPaths([
		__DIR__ . '/tests/Text',
	])
	->withRules([
		CoversAnnotationWithValueToAttributeRector::class,
		DataProviderAnnotationToAttributeRector::class,
		AddVoidReturnTypeWhereNoReturnRector::class
	])
	->withImportNames();

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and CI checks all pass

@distantnative distantnative added this to the 5.1.0 milestone May 11, 2025
@distantnative distantnative self-assigned this May 11, 2025
@distantnative distantnative force-pushed the v5/build/test-text-pkg-phpunit-attributes branch from 4403c9d to 257d770 Compare May 11, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant