Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Fix use of mock and stub
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and VincentLanglet committed May 8, 2021
1 parent a456e0f commit 5464c39
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/Iterator/AMQPMessageIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Interop\Amqp\AmqpQueue;
use Interop\Amqp\Impl\AmqpMessage;
use PhpAmqpLib\Channel\AMQPChannel;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase;
use Sonata\NotificationBundle\Iterator\AMQPMessageIterator;
use Sonata\NotificationBundle\Iterator\MessageIteratorInterface;
Expand All @@ -39,7 +41,7 @@ public function testShouldImplementMessageIteratorInterface(): void
*/
public function testCouldBeConstructedWithChannelAndContextAsArguments(): void
{
new AMQPMessageIterator($this->createChannelMock(), $this->createConsumerStub());
new AMQPMessageIterator($this->createChannelStub(), $this->createConsumerMock());
}

public function testShouldIterateOverThreeMessagesAndExit(): void
Expand All @@ -48,13 +50,13 @@ public function testShouldIterateOverThreeMessagesAndExit(): void
$secondMessage = new AmqpMessage('{"body": {"value": "theSecondMessageBody"}, "type": "aType", "state": "aState"}');
$thirdMessage = new AmqpMessage('{"body": {"value": "theThirdMessageBody"}, "type": "aType", "state": "aState"}');

$consumerMock = $this->createConsumerStub('aQueueName');
$consumerMock = $this->createConsumerMock('aQueueName');
$consumerMock
->expects($this->exactly(4))
->method('receive')
->willReturnOnConsecutiveCalls($firstMessage, $secondMessage, $thirdMessage, null);

$iterator = new AMQPMessageIterator($this->createChannelMock(), $consumerMock);
$iterator = new AMQPMessageIterator($this->createChannelStub(), $consumerMock);

$values = [];
foreach ($iterator as $message) {
Expand All @@ -73,9 +75,9 @@ public function testShouldIterateOverThreeMessagesAndExit(): void
/**
* @param mixed $queueName
*
* @return AmqpConsumer|\PHPUnit_Framework_MockObject_MockObject
* @return AmqpConsumer&MockObject
*/
private function createConsumerStub($queueName = null)
private function createConsumerMock($queueName = null)
{
$queue = $this->createMock(AmqpQueue::class);
$queue
Expand All @@ -91,10 +93,10 @@ private function createConsumerStub($queueName = null)
}

/**
* @return AMQPChannel|\PHPUnit_Framework_MockObject_MockObject|AMQPChannel
* @return AMQPChannel&Stub
*/
private function createChannelMock()
private function createChannelStub()
{
return $this->createMock(AMQPChannel::class);
return $this->createStub(AMQPChannel::class);
}
}

0 comments on commit 5464c39

Please sign in to comment.