Yii2为什么PhpStorm不';t自动完成单元测试方法
我的测试看起来像:Yii2为什么PhpStorm不';t自动完成单元测试方法,yii2,Yii2,我的测试看起来像: <?php namespace backend\tests\unit; use backend\modules\crm\models\CrmClient; class ClientTest extends \Codeception\Test\Unit { /** * @var \frontend\tests\UnitTester */ protected $tester; public function testCli
<?php
namespace backend\tests\unit;
use backend\modules\crm\models\CrmClient;
class ClientTest extends \Codeception\Test\Unit
{
/**
* @var \frontend\tests\UnitTester
*/
protected $tester;
public function testClientFields()
{
$client = new CrmClient();
$client->setCompany('12345');
$this->assertTrue($client->validate(['company']));
}
}
您需要调用codeception build命令,例如,/vendor/bin/codecept build
为所有套件生成基类。这将使用文件夹/tests/\u support/\u generated/
(基本测试文件夹结构)中的文档生成帮助程序函数
第二种解决方案:
将UnitTester
变量传递到函数中,然后使用它代替$this
,例如:
public function testClientFields(UnitTester $I)
{
$client = new CrmClient();
$client->setCompany('12345');
$I->assertTrue($client->validate(['company']));
}
您需要调用codeception build命令,例如/vendor/bin/codecept build
,为所有套件生成基类。这将使用文件夹/tests/\u support/\u generated/
(基本测试文件夹结构)中的文档生成帮助程序函数
第二种解决方案:
将UnitTester
变量传递到函数中,然后使用它代替$this
,例如:
public function testClientFields(UnitTester $I)
{
$client = new CrmClient();
$client->setCompany('12345');
$I->assertTrue($client->validate(['company']));
}
非常感谢。非常感谢。谢谢你!还有一件事。这两种解决方案都可以工作,但在第二个解决方案中,我得到:[ArgumentCountError]参数太少,无法运行backend\tests\unit\ClientTest::testClientFields(),0传入/home/projects/toma/transport/vendor/phpunit/phpunit/src/Framework/TestCase.php第1153行,由于该参数,预期正好为1。我应该在哪里设置它?尝试删除extends\Codeception\Test\Unit
和$tester
变量,不再需要了。谢谢!非常感谢。谢谢你!还有一件事。这两种解决方案都可以工作,但在第二个解决方案中,我得到:[ArgumentCountError]参数太少,无法运行backend\tests\unit\ClientTest::testClientFields(),0传入/home/projects/toma/transport/vendor/phpunit/phpunit/src/Framework/TestCase.php第1153行,由于该参数,预期正好为1。我应该在哪里设置它?尝试删除extends\Codeception\Test\Unit
,并且不再需要$tester
变量。