BunnyManagerTest::testGetAsyncClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Portiny\RabbitMQ\Tests;
4
5
use Bunny\Async\Client as AsyncClient;
6
use Bunny\Client;
7
use PHPUnit\Framework\TestCase;
8
use Portiny\RabbitMQ\BunnyManager;
9
use Portiny\RabbitMQ\Tests\Source\TestConsumer;
10
use React\EventLoop\Factory;
11
12
final class BunnyManagerTest extends TestCase
13
{
14
	/**
15
	 * @var BunnyManager
16
	 */
17
	private $bunnyManager;
18
19
20
	protected function setUp(): void
21
	{
22
		parent::setUp();
23
24
		$this->bunnyManager = $this->createBunnyManager();
25
	}
26
27
28
	public function testGetClient(): void
29
	{
30
		$client = $this->bunnyManager->getClient();
31
32
		self::assertInstanceOf(Client::class, $client);
33
		self::assertSame($client, $this->bunnyManager->getClient());
34
	}
35
36
37
	public function testGetAsyncClient(): void
38
	{
39
		$loop = Factory::create();
0 ignored issues
show
Deprecated Code introduced by
The function React\EventLoop\Factory::create() has been deprecated: 1.2.0 See Loop::get() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
		$loop = /** @scrutinizer ignore-deprecated */ Factory::create();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40
		$this->bunnyManager->setLoop($loop);
41
42
		$client = $this->bunnyManager->getClient();
43
44
		self::assertInstanceOf(AsyncClient::class, $client);
45
		self::assertSame($client, $this->bunnyManager->getClient());
46
	}
47
48
49
	public function testGetClassNameByAlias(): void
50
	{
51
		self::assertInstanceOf(TestConsumer::class, $this->bunnyManager->getConsumerByAlias('myAlias'));
52
		self::assertNull($this->bunnyManager->getConsumerByAlias('nonExisting'));
53
	}
54
55
56
	protected function createBunnyManager(): BunnyManager
57
	{
58
		return new BunnyManager(
59
			[
60
				'host' => '127.0.0.10',
61
				'port' => 9999,
62
				'user' => 'guest',
63
				'password' => 'guest',
64
				'vhost' => '/',
65
				'timeout' => 1,
66
				'heartbeat' => 60.0,
67
				'persistent' => false,
68
				'path' => '/',
69
				'tcp_nodelay' => false,
70
			],
71
			[
72
				'myAlias' => 'Portiny\\RabbitMQ\\Tests\\Source\\TestConsumer',
73
			],
74
			[new TestConsumer()],
75
			[],
76
			[]
77
		);
78
	}
79
80
}
81