1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/message-bus project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Tests\MessageBus; |
10
|
|
|
|
11
|
|
|
use Daikon\MessageBus\Channel\Subscription\Transport\TransportInterface; |
12
|
|
|
use Daikon\MessageBus\Channel\Subscription\Transport\TransportMap; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
final class TransportMapTest extends TestCase |
17
|
|
|
{ |
18
|
1 |
|
public function testConstructWithSelf(): void |
19
|
|
|
{ |
20
|
1 |
|
$transportMock = $this->createMock(TransportInterface::class); |
21
|
1 |
|
$transportMock->expects($this->exactly(2))->method('getKey')->willReturn('mock'); |
22
|
1 |
|
$transportMap = new TransportMap([$transportMock]); |
23
|
1 |
|
$newMap = new TransportMap($transportMap); |
24
|
1 |
|
$this->assertCount(1, $newMap); |
25
|
1 |
|
$this->assertFalse($transportMap === $newMap); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
public function testConstructWithDuplicateKey(): void |
29
|
|
|
{ |
30
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
31
|
1 |
|
$transportMock = $this->createMock(TransportInterface::class); |
32
|
1 |
|
$transportMock->expects($this->exactly(2))->method('getKey')->willReturn('mock'); |
33
|
1 |
|
new TransportMap([$transportMock, $transportMock]); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function testPush(): void |
37
|
|
|
{ |
38
|
1 |
|
$emptyMap = new TransportMap; |
39
|
|
|
/** @var TransportInterface $transportMock */ |
40
|
1 |
|
$transportMock = $this->createMock(TransportInterface::class); |
41
|
1 |
|
$transportMap = $emptyMap->with('mock', $transportMock); |
42
|
1 |
|
$this->assertCount(1, $transportMap); |
43
|
1 |
|
$this->assertEquals($transportMock, $transportMap->get('mock')); |
44
|
1 |
|
$this->assertTrue($emptyMap->isEmpty()); |
45
|
1 |
|
} |
46
|
|
|
} |
47
|
|
|
|