您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-convertDeprecationsToExceptions
发布时间:2021-10-09 23:02:30编辑:雪饮阅读()
在phpunit中一个测试方法中若触发了E_DEPRECATED或E_USER_DEPRECATED错误则该测试方法将被标记为错误。
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
public function testOne(){
\trigger_error('foo', \E_DEPRECATED);
}
public function testTwo(){
\trigger_error('foo', \E_USER_DEPRECATED);
}
}
运行结果:
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.
EE 2 / 2 (100%)
Time: 00:00.009, Memory: 6.00 MB
There were 2 errors:
1) MyTest::testOne
Invalid error type specified
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:6
2) MyTest::testTwo
foo
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:9
ERRORS!
Tests: 2, Assertions: 0, Errors: 2.
这种设定是由属性convertDeprecationsToExceptions为true决定,其默认就是true。
那么可以在phpunit配置文件phpunit.xml中phpunit元素上面配置为false就可以关闭掉这种设定。
phpunit.xml:
<phpunit bootstrap="src/autoload.php" convertDeprecationsToExceptions="false">
</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.
ER 2 / 2 (100%)
Deprecated: foo in C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php on line 9
Call Stack:
0.0002 405320 1. {main}() C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit:0
0.0053 1118880 2. PHPUnit\TextUI\Command::main(???) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit:92
0.0053 1118992 3. PHPUnit\TextUI\Command->run(array(4), true) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\TextUI\Command.php:96
0.0282 3575896 4. PHPUnit\TextUI\TestRunner->run(class PHPUnit\Framework\TestSuite, array(15), array(0), true) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\TextUI\Command.php:143
0.0561 3897664 5. PHPUnit\Framework\TestSuite->run(class PHPUnit\Framework\TestResult) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:670
0.0622 4167320 6. MyTest->run(class PHPUnit\Framework\TestResult) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\Framework\TestSuite.php:677
0.0622 4167320 7. PHPUnit\Framework\TestResult->run(class MyTest) C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\Framework\TestCase.php:885
0.0622 4167936 8. MyTest->runBare() C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\Framework\TestResult.php:722
0.0623 4185360 9. MyTest->runTest() C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\Framework\TestCase.php:1133
0.0623 4185360 10. MyTest->testTwo() C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\src\Framework\TestCase.php:1527
0.0623 4185360 11. trigger_error(string(3), long) C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:9
Time: 00:00.011, Memory: 6.00 MB
There was 1 error:
1) MyTest::testOne
Invalid error type specified
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:6
--
There was 1 risky test:
1) MyTest::testTwo
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:8
ERRORS!
可以看到这次它是异常就会原封不动的再次抛出来的。
关键字词:phpunit,convertDeprecationsToExceptions
相关文章
- phpunit-phpunit.xml-phpunit-columns
- phpunit-phpunit.xml-phpunit-backupStaticAttributes
- phpunit-phpunit.xml-backupGlobals的覆盖
- phpunit-phpunit.xml-phpunit-backupStaticAttributes
- phpunit配置文件中的backupGlobals
- phpunit-colors属性的开启(命令行中用auto)
- phpunit-colors属性的关闭(never)
- phpunit-colors属性
- phpunit-测试结果缓存文件配置-cacheResultFile
- phpunit-测试结果缓存-cacheResult