Skip to content

Commit

Permalink
Fixed consumer test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkruithof committed May 13, 2014
1 parent b349529 commit d4bbb59
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/TreeHouse/Queue/Tests/ConsumerTest.php
Expand Up @@ -28,18 +28,18 @@ public function testConstructor()

public function testConsume()
{
$message = new Message('test', null, uniqid());

$this->provider->expects($this->at(0))->method('get')->will($this->returnValue($message));
$this->provider->expects($this->at(1))->method('get')->will($this->returnValue($message));
$this->provider->expects($this->at(2))->method('get')->will($this->returnValue(null));

$this->provider->expects($this->exactly(3))->method('get');

$this->processor
->expects($this->exactly(2))
->method('process')
;
$messages = [
new Message('test', null, uniqid()),
new Message('test', null, uniqid()),
];

// keep returning messages until we run out of them
$this->provider->expects($this->any())->method('get')->will($this->returnCallback(function () use (&$messages) {
return empty($messages) ? null : array_shift($messages);
}));

$this->provider->expects($this->exactly(sizeof($messages) + 1))->method('get');
$this->processor->expects($this->exactly(sizeof($messages)))->method('process');

$consumer = new Consumer($this->provider, $this->processor);
$consumer->consume();
Expand Down

0 comments on commit d4bbb59

Please sign in to comment.