简体   繁体   English

php UserTest setup function 的致命错误声明

[英]php fatal error Declaration of UserTest setUp function

I had to do a PHPUnit testing with setUp function given below:我必须使用下面给出的设置 function 进行 PHPUnit 测试:

use PHPUnit\Framework\TestCase;

class UserTest extends TestCase
{
    public function setUp()
    {
       var_dump('1');
    }
}

When I run this test it shows me these errors:当我运行此测试时,它向我显示以下错误:

PHP Fatal error:  Declaration of UserTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void

How can I fix it?我该如何解决?

You need to declare the return type of template methods such as setUp() to be :void .您需要将setUp()等模板方法的返回类型声明为:void This is explained here and here .这是解释herehere

I fixed this error with a quick time by using void method like given below:我通过使用下面给出的 void 方法快速修复了这个错误:

 public function setUp(): void
 {
    var_dump('1');
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM