Error Identifier: phpunit.callParent

← Back to phpunit.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

class BaseTestCase extends TestCase
{
	protected function setUp(): void
	{
		// important initialization
	}
}

class MyTest extends BaseTestCase
{
	protected function setUp(): void
	{
		$this->value = true; // Missing call to parent::setUp()
	}
}

Why is it reported? #

This error is reported by the phpstan-phpunit extension.

When a PHPUnit test class overrides setUp() or tearDown() and the parent class (other than TestCase itself) also defines these methods, failing to call the parent method can skip important initialization or cleanup logic. This can lead to subtle test failures or resource leaks.

How to fix it #

Add a call to the parent method:

 <?php declare(strict_types = 1);
 
 class MyTest extends BaseTestCase
 {
 	protected function setUp(): void
 	{
+		parent::setUp();
+
 		$this->value = true;
 	}
 }

Running vendor/bin/phpstan analyse --fix adds the missing call automatically. parent::setUp() is inserted as the first statement of setUp(), and parent::tearDown() is inserted as the last statement of tearDown() (before a trailing return). The fix is not offered for methods declared in traits, or for a tearDown() that has an early return or a throw, because the added call would be skipped on that path.

🔧 This error is auto-fixable. PHPStan can fix it for you. Run the analysis with the --fix option to rewrite the affected code:

vendor/bin/phpstan analyse --fix

To also fix the errors you have ignored, use --fix-ignored. Learn more about --fix »

How to ignore this error #

You can use the identifier phpunit.callParent to ignore this error using a comment:

// @phpstan-ignore phpunit.callParent
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: phpunit.callParent

Rules that report this error #

  • PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule [1] phpstan/phpstan-phpunit
Theme
© 2026 PHPStan s.r.o.