Fork me on GitHub
a Sensio Labs Product

Space Sets (v3.64.0) edition

Rule php_unit_test_case_static_method_calls

Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::.

Warning

Using this rule is risky

Risky when PHPUnit methods are overridden or not accessible, or when project has PHPUnit incompatibilities.

Configuration

call_type

The call type to use for referring to PHPUnit methods.

Allowed values: 'self', 'static' and 'this'

Default value: 'static'

methods

Dictionary of method => call_type values that differ from the default strategy.

Allowed types: list<string>

Default value: []

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
 final class MyTest extends \PHPUnit_Framework_TestCase
 {
     public function testMe()
     {
-        $this->assertSame(1, 2);
-        self::assertSame(1, 2);
+        static::assertSame(1, 2);
+        static::assertSame(1, 2);
         static::assertSame(1, 2);
     }
 }

Example #2

With configuration: ['call_type' => 'this'].

--- Original
+++ New
 <?php
 final class MyTest extends \PHPUnit_Framework_TestCase
 {
     public function testMe()
     {
         $this->assertSame(1, 2);
-        self::assertSame(1, 2);
-        static::assertSame(1, 2);
+        $this->assertSame(1, 2);
+        $this->assertSame(1, 2);
     }
 }

Rule sets

The rule is part of the following rule set:

References

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.