Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. class ClassWithProtectedMethod
  3. {
  4. public function foo()
  5. {
  6. return $this->bar();
  7. }
  8.  
  9. protected function bar()
  10. {
  11. return 'bar';
  12. }
  13. }
  14.  
  15. class ProtectedStubTest extends PHPUnit_Framework_TestCase
  16. {
  17. public function testProtectedStub()
  18. {
  19. $stub = $this->getMock('ClassWithProtectedMethod', array('bar'));
  20.  
  21. $stub->expects($this->any())
  22. ->method('bar')
  23. ->will($this->returnValue('stub'));
  24.  
  25. $this->assertEquals('stub', $stub->foo());
  26. }
  27. }
  28. ?>
  29.  
  30. sb@vmware ~ % phpunit ProtectedStubTest
  31. PHPUnit 3.5.2 by Sebastian Bergmann.
  32.  
  33. .
  34.  
  35. Time: 0 seconds, Memory: 7.00Mb
  36.  
  37. OK (1 test, 2 assertions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement