Guest User

Untitled

a guest
Apr 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. // test class
  4. class Snap_MockObject_Mockable_With_Static_Members {
  5. protected static function getTrue() {
  6. return true;
  7. }
  8. public static function getProtectedTrue() {
  9. return self::getTrue();
  10. }
  11. }
  12.  
  13. // create a mock, with getTrue punched out to return false instead
  14. // then call getProtectedTrue on our mock
  15. // we should get false back
  16.  
  17. class Snap_MockObject_Test_MockGenerationWithOverridingStaticMethods extends Snap_UnitTestCase {
  18. public function setUp() {
  19. $this->mocked_obj = $this->mock('Snap_MockObject_Mockable_With_Static_Members')
  20. ->requiresInheritance()
  21. ->setReturnValue('getTrue', false)
  22. ->construct();
  23. }
  24. public function tearDown() {
  25. unset($this->mocked_obj);
  26. }
  27.  
  28. // we use call_user_func_array because we have no clue what the name of
  29. // $this->mocked_obj is, which would make static method testing
  30. // impossible.
  31. // this can be overhauled with Late Static Bindings some day
  32. public function testProtectedMethodCallsOverriddenCorrectly() {
  33. return $this->assertFalse(SNAP_callStatic($this->mocked_obj, 'getProtectedTrue'), array()));
  34. }
  35. }
Add Comment
Please, Sign In to add comment