我寫來測試我的代碼的方法,但問題是,當我使用dataProvider
我得到:PHPUnit中警告使用數據提供程序及功能結果
1) Warning The data provider specified for userTest::testItCanValidateApiKeysAndDomainAutoTest is invalid. Call to undefined function show_message()
WARNINGS!
Tests: 5, Assertions: 12, Warnings: 1.
這裏是我的代碼,當我使用它沒有dataProvider
public function testItCanValidateApiKeysAndDomainByInputData(){
$this->user->setApiKey('306942ac');
$this->user->setDomain('test.com');
$this->assertEquals(show_message(103), $this->user->verifyPurchaseKey());
}
和它的工作太棒了,但是當我使用數據提供程序
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());
}
你可能認爲我在通過自動加載加載到另一個項目文件中使用show_message .. 得到了警告信息..
dataProviders在'setUp'或'setUpBeforeClass'方法之前被調用。你是否在這些地方包含了'show_message'函數? – gontrollez
nope,我在另一個名爲config.php的文件中使用show_message(),並期望它自動加載引導程序 –