This question had some unanswered time, but I ran into this problem. This is not possible; however, at least one dirty job:
In the test file
<?php class SomeClass { const FOOBAR = 'foobar'; } class SomeTest extends PHPUnit_Framework_TestCase { public function setUp() { $mock = $this->getMock( 'SomeClass' ); } }
Then you use your mocked object to mock functionality, and you use the class constant in the same way as you originally did. For instance:
// Call a method on mocked object // (would need to add this method to your mock, of course) $mock->doSomething(); // Use the constant $fooBar = SomeClass::FOOBAR;
This is dirty, so I'm sure that everything can be confusing if you use some kind of autoload that tries to load the actual SomeClass class, but it will work βfineβ if you don't Download the original SomeClass .
I am definitely interested in hearing other solutions, as well as getting some feedback on how dirty this is.
source share