<phpunit bootstrap="src/autoload.php" backupStaticAttributes="true">
</phpunit>
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
RC:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:10:
int(1)
R 2 / 2 (100%)C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:14:
int(2)
Time: 00:00.013, Memory: 6.00 MB
There were 2 risky tests:
1) MyTest::testOne
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:9
2) MyTest::testTwo
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:13
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Risky: 2.
可见并没有因为phpunit配置文件phpunit.xml中的phpunit标签中配置的backupStaticAttributes为true而进行静态变量备份。
那么对于测试类整个类来说也是同样的。
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @backupStaticAttributes disabled
*/
final class MyTest extends TestCase
{
static $a=1;
public function testOne(){
var_dump(self::$a);
self::$a=2;
}
public function testTwo(){
var_dump(self::$a);
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
RC:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:10:
int(1)
R 2 / 2 (100%)C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:14:
int(2)
Time: 00:00.010, Memory: 6.00 MB
There were 2 risky tests:
1) MyTest::testOne
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:9
2) MyTest::testTwo
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:13
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Risky: 2.