我有一堆類常量,我想檢查我的PHPUnit測試中的值。通過PHPUnit的dataProvider動態地訪問類的常量5.5.4
當我運行這個測試,我得到以下錯誤:
1) CRMPiccoBundle\Tests\Services\MailerTest::testConstantValues with data set "Account Verification" ('ACCOUNT_VERIFICATION', 'CRMPicco.co.uk Account Verification') Error: Access to undeclared static property: CRMPiccoBundle\Services\Mailer::$constant
這是我的測試及其相應的數據提供程序:
/**
* @dataProvider constantValueDataProvider
*/
public function testConstantValues(string $constant, $expectedValue)
{
$mailer = new Mailer();
$this->assertEquals($expectedValue, $mailer::$constant);
}
public function constantValueDataProvider()
{
return [
'Account Verification' => [
'ACCOUNT_VERIFICATION',
'CRMPicco.co.uk Account Email Verification'
]];
}
這是怎樣的常數裏面Mailer
聲明:
const ACCOUNT_VERIFICATION = 'CRMPicco.co.uk Account Email Verification';
如何檢查此常數的值?
如果我在測試中做$mailer::ACCOUNT_VERIFICATION
它吐出期望的值,但我想動態地用dataProvider做到這一點。
你可以在'Mailer'類中顯示上述常量的聲明嗎? – BVengerov