Completed
Push — master ( 8ba281...57dab7 )
by Tomáš
07:15
created

BunnyManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Portiny\RabbitMQ\Tests;
5
6
use Bunny\Async\Client as AsyncClient;
7
use Bunny\Client;
8
use Portiny\RabbitMQ\BunnyManager;
9
use React\EventLoop\Factory;
10
11
final class BunnyManagerTest extends AbstractContainerTestCase
12
{
13
	/**
14
	 * @var BunnyManager
15
	 */
16
	private $bunnyManager;
17
18
	protected function setUp(): void
19
	{
20
		parent::setUp();
21
22
		$this->bunnyManager = $this->createBunnyManager();
23
	}
24
25
	public function testGetClient(): void
26
	{
27
		$client = $this->bunnyManager->getClient();
28
29
		$this->assertInstanceOf(Client::class, $client);
30
		$this->assertSame($client, $this->bunnyManager->getClient());
31
	}
32
33
	public function testGetAsyncClient(): void
34
	{
35
		$loop = Factory::create();
36
		$this->bunnyManager->setLoop($loop);
37
38
		$client = $this->bunnyManager->getClient();
39
40
		$this->assertInstanceOf(AsyncClient::class, $client);
41
		$this->assertSame($client, $this->bunnyManager->getClient());
42
	}
43
44
	public function testGetClassNameByAlias(): void
45
	{
46
		$this->assertSame('App\\Service\\Consumer\\TestConsumer', $this->bunnyManager->getClassNameByAlias('myAlias'));
47
		$this->assertNull($this->bunnyManager->getClassNameByAlias('nonExisting'));
48
	}
49
50
	protected function createBunnyManager(): BunnyManager
51
	{
52
		return new BunnyManager(
53
			$this->container,
54
			[
55
				'aliases' => [
56
					'myAlias' => 'App\\Service\\Consumer\\TestConsumer',
57
				],
58
				'connection' => [
59
					'host' => '127.0.0.10',
60
					'port' => 9999,
61
					'user' => 'guest',
62
					'password' => 'guest',
63
					'vhost' => '/',
64
					'timeout' => 1,
65
					'heartbeat' => 60.0,
66
					'persistent' => false,
67
					'path' => '/',
68
					'tcp_nodelay' => false,
69
				],
70
			]
71
		);
72
	}
73
}
74