Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Prophecy. Mocking library.
- //Example of Mock
- /**
- * @test
- */
- public function shouldUseTheExternalCollaborator()
- {
- $myCollaboratorProphecy = $this->prophesize('Collaborator');
- /** @var Collaborator $collaborator */
- $collaborator = $myCollaboratorProphecy->reveal();
- $myClass = new MyClass($collaborator);
- $myClass->run();
- $myCollaboratorProphecy->collaborate()->shouldBeCalled();
- }
- // Example of Stub
- /**
- * @test
- */
- public function shouldReturnTheCollaboratorResponse()
- {
- $myCollaboratorProphecy = $this->prophesize('Collaborator');
- $collaboratorResponse = 'collaborator response';
- $myCollaboratorProphecy->collaborate()->willReturn($collaboratorResponse);
- /** @var Collaborator $collaborator */
- $collaborator = $myCollaboratorProphecy->reveal();
- $myClass = new MyClass($collaborator);
- $response = $myClass->run();
- $this->assertEquals($collaboratorResponse, $response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement