php - Correct way to check if a class has a constant defined with PHPUnit -


i trying find out best, or correct, way check if class has constant defined phpunit. phpunit docs don't seem cover this, makes me wonder if doing correct thing testing - important feature of class.

i have following class:

purchasemanager.php

/**  * message sent when course has been purchased  */ const course_purchased_message = 'coursepurchasedmessage'; 

...and part of it's test class has test:

purchasemanagertest.php

public function testcoursepurchasedmessageconstant() {     $pm = new purchasemanager();     $this->asserttrue(defined(get_class($pm) . '::course_purchased_message')); } 

is correct? passes, i'm interested know if accurate , best practice.

i using phpunit 5.0.8.

i'm using reflection class purpose. has getconstants method returns associative array [<constant_name> => <constant_value>, ...].

something like:

public function testhassiteexportedconstant() {     $mailer = new \reflectionclass(siteexporter::class);     $this->assertarrayhaskey('site_exported', $mailer->getconstants()); } 

Comments