Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. // Prophecy. Mocking library.
  4.  
  5. //Example of Mock
  6.  
  7. /**
  8. * @test
  9. */
  10. public function shouldUseTheExternalCollaborator()
  11. {
  12. $myCollaboratorProphecy = $this->prophesize('Collaborator');
  13. /** @var Collaborator $collaborator */
  14. $collaborator = $myCollaboratorProphecy->reveal();
  15. $myClass = new MyClass($collaborator);
  16. $myClass->run();
  17. $myCollaboratorProphecy->collaborate()->shouldBeCalled();
  18. }
  19.  
  20. // Example of Stub
  21.  
  22. /**
  23. * @test
  24. */
  25. public function shouldReturnTheCollaboratorResponse()
  26. {
  27. $myCollaboratorProphecy = $this->prophesize('Collaborator');
  28. $collaboratorResponse = 'collaborator response';
  29. $myCollaboratorProphecy->collaborate()->willReturn($collaboratorResponse);
  30. /** @var Collaborator $collaborator */
  31. $collaborator = $myCollaboratorProphecy->reveal();
  32. $myClass = new MyClass($collaborator);
  33. $response = $myClass->run();
  34. $this->assertEquals($collaboratorResponse, $response);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement