Skip to content

Emit warning when the name of a data provider method begins with test #6300

@franck-paul

Description

@franck-paul
Q A
PHPUnit version 12.4-dev
PHP version 8.4.11
Installation Method Composer

Summary

A data provider method causes a warning about Risky test (This test did not perform any assertions)

How to reproduce

This is my two methods, test and data:

<?php

declare(strict_types=1);

use Dotclear\Helper\Html\WikiToHtml;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class WikiToHtmlTest extends TestCase
{
    ... 
    /* previous test methods */public static function testTagTransformProvider(): array
    {
        return [
            ['em', ["''", "''"]],
            ['strong', ['__', '__']],
            ['abbr', ['??', '??']],
            ['q', ['{{', '}}']],
            ['code', ['@@', '@@']],
            ['del', ['--', '--']],
            ['ins', ['++', '++']],
            ['mark', ['""', '""']],
            ['sup', ['^', '^']],
            ['sub', [',,', ',,']],
            ['i', ['££', '££']],
            ['span', [';;', ';;']],
        ];
    }

    #[DataProvider('testTagTransformProvider')]
    public function testTagTransform(string $tag, array $delimiters): void
    {
        $wiki = new WikiToHtml();

        $phrase = 'Dotclear do blog and do it well';

        $this->assertSame(
            sprintf('<p>Before <%1$s>%2$s</%1$s> After</p>', $tag, $phrase),
            $wiki->transform(sprintf('Before %s%s%s After', $delimiters[0], $phrase, $delimiters[1]))
        );

        $this->assertSame(
            sprintf('<p><%1$s>%2$s</%1$s></p>', $tag, $phrase),
            $wiki->transform(sprintf('%s%s%s', $delimiters[0], $phrase, $delimiters[1]))
        );
    }
}

And the output is:

PHPUnit 12.4-dev by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.11 with Xdebug 3.4.0
Configuration: /Users/.../git-dc/phpunit.dist.xml

.............R...                                                 17 / 17 (100%)

Time: 00:00.309, Memory: 79.00 MB

There was 1 risky test:

1) WikiToHtmlTest::testTagTransformProvider
This test did not perform any assertions

/Users/.../git-dc/tests/unit/src/Helper/Html/WikiToHtmlTest.php:233

OK, but there were issues!
Tests: 17, Assertions: 36, Risky: 1.

Generating code coverage report in HTML format ... done [00:00.122]

Expected behavior

Don't warn about data provider static method as Risky? Or may be I'm doing something wrong ?

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions