Created
January 2, 2014 11:39
-
-
Save tomphp/8218012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TestClassSpec extends ObjectBehavior | |
{ | |
public function it_runs_action1(ActionClass $action) { | |
$action->action1()->shouldBeCalled(); | |
// I have to add this here even though it is not the focus of this test? | |
$action->action2()->shouldBeCalled(); | |
$this->run($action); | |
} | |
public function it_runs_action2(ActionClass $action) { | |
$action->action2()->shouldBeCalled(); | |
// I have to add this here even though it is not the focus of this test? | |
$action->action1()->shouldBeCalled(); | |
$this->run($action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@docteurklein I'm not sure what you are saying is wrong? What I was trying to highlight was that in the TDD cycle you write the smallest possible failing test. In my contrived example this could be
This works fine and is simple to implement and get to pass by simply calling
$action->action1();
Next you write the next failing tests, this again should be quite simple like so:
Again this reads well and you can see what is supposed to be happening but when you run it it fails with a message saying that in the second test
action1()
was called unexpectedly. The reason for this is once you set an expectation (I think Prophecy uses the termpromise
) any other calls are treated as being unexpected.My issue was that I was then adding
$this->action1()->shouldBeCalled();
to the 2nd test so it allows the other action to also be called in the method. My problem with that was I feltshouldBeCalled()
was too strong since it's not the focus of the test, I just want to know thataction2()
was called.After that has been done and the implementation is added the first test then fails with an unexpected
action2()
for exactly the same reason so something has to be added there also.I got a reply on twitter from @everzet explaining that I could simply use
willReturn()
instead to allow the method to be called like so:This is better imho because it allows it to be called without say that it should be which is not a require of this particular test.