jeudi 6 octobre 2016

Access class constant dynamically through dataProvider with PHPUnit 5.5.4

I have a bunch of class constants that I would like to check the value of in my PHPUnit test.

When I run this test I get the following error:

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

This is my test and its corresponding dataProvider:

/**
 * @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'
        ]];
}

How can I check the value of this constant?

If I do $mailer::ACCOUNT_VERIFICATION inside the test it spits out the expected value, but I would like to do this dynamically with a dataProvider.

Aucun commentaire:

Enregistrer un commentaire