PHPUnit中使用数据提供程序和函数作为结果的警告
我编写了一个测试代码的方法,但问题是当我使用PHPUnit中使用数据提供程序和函数作为结果的警告,phpunit,warnings,Phpunit,Warnings,我编写了一个测试代码的方法,但问题是当我使用dataProvider时,我得到了: 1)警告 为userTest::TestCanValidateApikeysandDomainAutoTest指定的数据提供程序无效。 调用未定义函数show_message() 警告 测试:5,断言:12,警告:1。 这是我在没有数据提供者的情况下使用它时的代码 public function testItCanValidateApiKeysAndDomainByInputData(){ $this-&
dataProvider
时,我得到了:
1)警告
为userTest::TestCanValidateApikeysandDomainAutoTest指定的数据提供程序无效。
调用未定义函数show_message()
警告代码>
测试:5,断言:12,警告:1。
这是我在没有数据提供者的情况下使用它时的代码
public function testItCanValidateApiKeysAndDomainByInputData(){
$this->user->setApiKey('306942ac');
$this->user->setDomain('test.com');
$this->assertEquals(show_message(103), $this->user->verifyPurchaseKey());
}
它工作得很好,但是当我使用dataProvider时
public function inputApiKeys()
{
return array(
array(
'f5e47ee75672b855a8d76f5d54aa7ce6914',
'reza.com',
false,
),
array(
'f5e47asdasdasd',
'reza.com',
show_message(100),
),
array(
'0ecc580a009d929b13337509721a4',
'test12.com',
show_message(102),
),
array(
'0ecc580a009d9230604659b13337509721a4',
'127.0.0.1',
show_message(1,
'6233c772-e214-a45d8c1e04e2'),
),
array(
'0ecc580a009d9204659b13337509721a4',
'localhost',
show_message(1,
'6233c772a45d8c1e04e2'),
),
array(
'ac45e9ff50c5aac05d25c2605d2195f33b4',
'mm.mu.com',
show_message(102),
),
array(
'ac45e9f1aeab519f50c5aac05d25c2605d2195f33b4',
'reza.wpengine.com',
show_message(103),
),
array(
'000604659b13337509721a4',
'mnm.wpengine.com',
'6233c772-3-9cc4-a45d8c1e04e2'),
);
}
/**
* @dataProvider inputApiKeys
*/
public function testItCanValidateApiKeysAndDomainAutoTest($apikey, $domain, $result)
{
$this->user->setApiKey($apikey);
$this->user->setDomain($domain);
$this->assertEquals($result, $this->user->verifyPurchaseKey());
}
您可以考虑在AutoLoad加载的另一个文件中使用Suffi消息到Project…
收到警告消息。在数据提供程序函数末尾返回创建的数据结构非常重要:
return $reza;
这通常会使它起作用。至少我试过你的代码,如果我全局声明一个show\u message()
函数,它在这里就可以工作
调用未定义函数show_message()
的消息表明此函数不在数据提供程序的范围内。如果在测试函数中直接调用show_message()
,这似乎很奇怪。因此,我认为,如果不使用数据提供程序,代码中可能会有更大的不同。在setUp
或setUpBeforeClass
方法之前调用数据提供程序。你是否在这些地方包含了show_message函数?不,我在另一个名为config.php的文件中使用show_message(),希望它能自动加载bootstrapsorry关于代码,我是debuggig,它是旧的,在代码中,我返回了数组,但它仍然不工作。我扩展了关于调用未定义函数的回答。请检查show_message()
的定义位置。