Menu

← Back to phpunit.*

Error Identifier: phpunit.callParent

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;
 	}
 }

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.