Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected number of calls methods fail (for me) #27

Closed
benwaine opened this issue Jun 25, 2011 · 1 comment
Closed

Expected number of calls methods fail (for me) #27

benwaine opened this issue Jun 25, 2011 · 1 comment

Comments

@benwaine
Copy link

This is a method from a suite I'm currently writing.

It tests that given a keyword and a number of tweets desired that the correct URL is generated to make a call to the Twitter search API.

The problem I have is that despite specifying that that methods should only be called once they can be called multiple times and the expectation does not fail.

This happens on all expected number of call arguments I've tried. You can see all my tests at https://github.com/benwaine/TwitterSearch/tree/master/tests. They are a bit scrappy at the moment - it's my first run through!

Thanks for your help.

public function testGetTweetsCorrectUri() {
    $mockHttp = m::mock('\Zend_Http_Client');

    $mockHttp->shouldReceive('setUri')
             ->with('http://search.twitter.com/search.json?q=microsoft&page=1&rpp=100')
             ->once();

    $mockHttp->shouldReceive('request')
            ->once();

    $mockHttpResp = m::mock("\Zend_Http_Response");
    $mockHttpResp->shouldReceive('getBody')
                 ->andReturn(Helper\TweetProvider::getFixture('ClientTest-BasicTweets'));

    $mockHttp->shouldReceive('getLastResponse')
             ->withNoArgs()
             ->once()
             ->andReturn($mockHttpResp);

    $client = new Client($mockHttp);

    $tweets = $client->getTweets(array('microsoft'), 2);

}
@benwaine benwaine closed this as completed Jul 2, 2011
@benwaine
Copy link
Author

benwaine commented Jul 2, 2011

The reason the expectations didn't occur correctly for me was because I didn't use the function add the close function like so:

public function teardown() {
\Mockery::close();
}

The moment I add this it all works as expected.

Sorry for the red herring .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant