sebastianbergmann / phpunit

The PHP Unit Testing framework.

Home Page:https://phpunit.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid abstract test warning

danrot opened this issue · comments

Since PHPUnit 10 warning for abstract test classes like the following are displayed:

Class App\Tests\AbstractTest declared in /var/www/tests/AbstractTest.php is abstract

I get why this might be useful, but I am actively using abstract test cases to allow running the same tests against multiple different implementations. I have explained that in more detail in a blog post on my website.

I am totally aware that these test classes are abstract, in my specific example this is the whole point. So I want to get rid of this warning, but I found no really good way. What I ended up doing is listing every file in the phpunit.xml file like so:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
		 backupGlobals="false"
		 colors="true"
		 bootstrap="tests/bootstrap.php"
>
	<testsuites>
		<testsuite name="Project Test Suite">
			<directory>tests</directory>
			<exclude>tests/AbstractTest1.php</exclude>
			<exclude>tests/AbstractTest2.php</exclude>
		</testsuite>
	</testsuites>
</phpunit>

While this works, it is a bit cumbersome, because I ahve to add a exclude line for every abstract test case. Now I am wondering if I can somehow deactivate that warning or at least exclude files using a file pattern. I haven't found a way to do that in the current documentation, therefore I think it would be useful to implement that. If this is already possible in some way I am happy to hear about it 🙁

Can't you rename them?

That's only because they end in *Test. If you rename it to *Testcase, you don't get a warning.

@mfn I guess I could, but I don't think it's very nice of a tool to force me to change names like that.

The name of abstract test case classes must not end in Test. Rename your abstract test case class(es) to have their name end in TestCase, for example, and you will not get this warning.