Skip to content

Commit 2c32585

Browse files
committed
[pheanstalk] add tests for context and destination.
1 parent 455ac47 commit 2c32585

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace Enqueue\Pheanstalk\Tests;
4+
5+
use Enqueue\Null\NullQueue;
6+
use Enqueue\Pheanstalk\PheanstalkContext;
7+
use Enqueue\Psr\InvalidDestinationException;
8+
use Enqueue\Psr\PsrContext;
9+
use Enqueue\Test\ClassExtensionTrait;
10+
use Pheanstalk\Connection;
11+
use Pheanstalk\Pheanstalk;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class PheanstalkContextTest extends TestCase
15+
{
16+
use ClassExtensionTrait;
17+
18+
public function testShouldImplementPsrContextInterface()
19+
{
20+
$this->assertClassImplements(PsrContext::class, PheanstalkContext::class);
21+
}
22+
23+
public function testCouldBeConstructedWithPheanstalkAsFirstArgument()
24+
{
25+
new PheanstalkContext($this->createPheanstalkMock());
26+
}
27+
28+
public function testThrowNotImplementedOnCreateTemporaryQueue()
29+
{
30+
$context = new PheanstalkContext($this->createPheanstalkMock());
31+
32+
$this->expectException(\LogicException::class);
33+
$this->expectExceptionMessage('Not implemented');
34+
$context->createTemporaryQueue();
35+
}
36+
37+
public function testThrowInvalidDestinationIfInvalidDestinationGivenOnCreateConsumer()
38+
{
39+
$context = new PheanstalkContext($this->createPheanstalkMock());
40+
41+
$this->expectException(InvalidDestinationException::class);
42+
$context->createConsumer(new NullQueue('aQueue'));
43+
}
44+
45+
public function testShouldAllowGetPheanstalkSetInConstructor()
46+
{
47+
$pheanstalk = $this->createPheanstalkMock();
48+
49+
$context = new PheanstalkContext($pheanstalk);
50+
51+
$this->assertSame($pheanstalk, $context->getPheanstalk());
52+
}
53+
54+
public function testShouldDoConnectionDisconnectOnContextClose()
55+
{
56+
$connection = $this->createMock(Connection::class);
57+
$connection
58+
->expects($this->once())
59+
->method('disconnect')
60+
;
61+
62+
$pheanstalk = $this->createPheanstalkMock();
63+
$pheanstalk
64+
->expects($this->once())
65+
->method('getConnection')
66+
->willReturn($connection)
67+
;
68+
69+
$context = new PheanstalkContext($pheanstalk);
70+
71+
$context->close();
72+
}
73+
74+
/**
75+
* @return \PHPUnit_Framework_MockObject_MockObject|Pheanstalk
76+
*/
77+
private function createPheanstalkMock()
78+
{
79+
return $this->createMock(Pheanstalk::class);
80+
}
81+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Enqueue\Pheanstalk\Tests;
4+
5+
use Enqueue\Pheanstalk\PheanstalkDestination;
6+
use Enqueue\Psr\PsrQueue;
7+
use Enqueue\Psr\PsrTopic;
8+
use Enqueue\Test\ClassExtensionTrait;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class PheanstalkDestinationTest extends TestCase
12+
{
13+
use ClassExtensionTrait;
14+
15+
public function testShouldImplementPsrQueueInterface()
16+
{
17+
$this->assertClassImplements(PsrQueue::class, PheanstalkDestination::class);
18+
}
19+
20+
public function testShouldImplementPsrTopicInterface()
21+
{
22+
$this->assertClassImplements(PsrTopic::class, PheanstalkDestination::class);
23+
}
24+
25+
public function testShouldAllowGetNameSetInConstructor()
26+
{
27+
$destionation = new PheanstalkDestination('theDestinationName');
28+
29+
$this->assertSame('theDestinationName', $destionation->getName());
30+
}
31+
}

0 commit comments

Comments
 (0)