in Education by
I am trying to find out the best, or correct, way to check if a class has a constant defined with PHPUnit. The PHPUnit docs don't seem to cover this, which makes me wonder if I am doing the correct thing by testing this - however it is an important feature of my class. I have the following class: PurchaseManager.php /** * Message sent when a course has been purchased */ const COURSE_PURCHASED_MESSAGE = 'coursePurchasedMessage'; ...and part of it's test class has this test: PurchaseManagerTest.php public function testCoursePurchasedMessageConstant() { $pm = new PurchaseManager(); $this->assertTrue(defined(get_class($pm) . '::COURSE_PURCHASED_MESSAGE')); } Is this correct? It passes, but i'm just interested to know if this is accurate and best practice. I am using PHPUnit 5.0.8. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I'm using Reflection class for this purpose. It has getConstants method which returns an associative array [ => , ...]. Something like: public function testHasSiteExportedConstant() { $mailer = new \ReflectionClass(SiteExporter::class); $this->assertArrayHasKey('SITE_EXPORTED', $mailer->getConstants()); }

Related questions

0 votes
    I am trying to find out the best, or correct, way to check if a class has a constant defined ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    To implement a custom untyped user-defined aggregation function, the user has to extend the ... 2. UserDefinedAggregateFunction 3. UDFAggregateFunction 4. UserDefinedFunction...
asked Oct 22, 2020 in Technology by JackTerrance
0 votes
    Which of the following constant are defined in Character wrapper? (a) MAX_RADIX (b) MAX_VALUE (c) TYPE ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of the following constant are defined in Boolean wrapper? (a) TRUE (b) FALSE (c) TYPE (d) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    I have set up a cronjob to run a script daily. This script pulls out a list of Ids from a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    I have set up a cronjob to run a script daily. This script pulls out a list of Ids from a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Which of the following is the correct way of implementing an interface salary by class manager? (a) class manager ... Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is the correct way of implementing an interface A by class B? (a) class B extends A{ ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of these is an correct way of defining generic class? (a) class name(T1, T2, , Tn) { /* ... Interfaces & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of these is an correct way making a list that is upper bounded by class Number? (a) List...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
0 votes
    Which of these is an correct way of defining generic class? (a) class name(T1, T2, , Tn) { ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    I know there are several threads on this already, but I've hit a brick wall and can't find any ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
...