Skip to content

Commit

Permalink
update testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
freyhsiao committed Jan 7, 2020
1 parent 2a89fe8 commit 939405c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"illuminate/queue": "5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*",
"ext-json": "*",
"ext-curl": "*",
"aliyunmq/mq-http-sdk": "^1.0"
"aliyunmq/mq-http-sdk": "^1.0",
"guzzlehttp/guzzle": "^6.0.0"
},
"require-dev": {
"php": ">=5.6.4",
"phpunit/phpunit": "~4.8",
"vlucas/phpdotenv": "^3.3"
"vlucas/phpdotenv": "^3.3",
"mockery/mockery": "^1.2.3"
},
"autoload": {
"psr-4": {
Expand Down
45 changes: 40 additions & 5 deletions tests/RocketMQQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Freyo\LaravelQueueRocketMQ\Queue\Jobs\RocketMQJob;
use Freyo\LaravelQueueRocketMQ\Queue\RocketMQQueue;
use Illuminate\Container\Container;
use MQ\Model\Message;
use MQ\Model\TopicMessage;
use MQ\MQConsumer;
use MQ\MQProducer;
Expand Down Expand Up @@ -76,33 +77,67 @@ public function testSize(RocketMQQueue $queue, $config)
*/
public function testPush(RocketMQQueue $queue, $config)
{
$this->assertInstanceOf(TopicMessage::class, $queue->push('App\Jobs\CMQJob@handle'));
$queue = \Mockery::mock(RocketMQQueue::class)
->shouldAllowMockingProtectedMethods();

$queue->expects()
->push('App\Jobs\RocketMQJob@handle')
->andReturn(new TopicMessage('MockMessageBody'));

$this->assertInstanceOf(
TopicMessage::class, $queue->push('App\Jobs\RocketMQJob@handle')
);
}

/**
* @dataProvider provider
*/
public function testPushRaw(RocketMQQueue $queue, $config)
{
$this->assertInstanceOf(TopicMessage::class, $queue->pushRaw('App\Jobs\CMQJob@handle'));
$queue = \Mockery::mock(RocketMQQueue::class)
->shouldAllowMockingProtectedMethods();

$queue->expects()
->pushRaw('App\Jobs\RocketMQJob@handle')
->andReturn(new TopicMessage('MockMessageBody'));

$this->assertInstanceOf(
TopicMessage::class, $queue->pushRaw('App\Jobs\RocketMQJob@handle')
);
}

/**
* @dataProvider provider
*/
public function testLater(RocketMQQueue $queue, $config)
{
$queue->later(0, 'App\Jobs\CMQJob@handle');
$queue = \Mockery::mock(RocketMQQueue::class)
->shouldAllowMockingProtectedMethods();

$queue->expects()
->later(0, 'App\Jobs\RocketMQJob@handle')
->andReturn(new TopicMessage('MockMessageBody'));

$this->assertInstanceOf(
TopicMessage::class, $queue->later(0, 'App\Jobs\RocketMQJob@handle')
);
}

/**
* @dataProvider provider
*/
public function testPop(RocketMQQueue $queue, $config)
{
$queue->setContainer(new Container());
$client = \Mockery::mock(RocketMQQueue::class)
->shouldAllowMockingProtectedMethods();

$client->expects()
->pop()
->andReturn(
\Mockery::mock(RocketMQJob::class)
);

$this->assertInstanceOf(RocketMQJob::class, $queue->pop());
$this->assertInstanceOf(RocketMQJob::class, $client->pop());
}

/**
Expand Down

0 comments on commit 939405c

Please sign in to comment.