From d4bbb59db74ca46c51c62097714a469e175606e0 Mon Sep 17 00:00:00 2001 From: Peter Kruithof Date: Tue, 13 May 2014 15:32:54 +0200 Subject: [PATCH] Fixed consumer test --- tests/TreeHouse/Queue/Tests/ConsumerTest.php | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/TreeHouse/Queue/Tests/ConsumerTest.php b/tests/TreeHouse/Queue/Tests/ConsumerTest.php index efa2f42..c8272da 100644 --- a/tests/TreeHouse/Queue/Tests/ConsumerTest.php +++ b/tests/TreeHouse/Queue/Tests/ConsumerTest.php @@ -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();