Passed
Push — master ( 905821...42a403 )
by Mr
07:23
created

ChannelMapTest::testConstructWithSelf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 1
b 0
f 1
ccs 7
cts 7
cp 1
cc 1
nc 1
nop 0
crap 1
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\ChannelInterface;
12
use Daikon\MessageBus\Channel\ChannelMap;
13
use InvalidArgumentException;
14
use PHPUnit\Framework\TestCase;
15
16
final class ChannelMapTest extends TestCase
17
{
18 1
    public function testConstructWithSelf(): void
19
    {
20 1
        $channelMock = $this->createMock(ChannelInterface::class);
21 1
        $channelMock->expects($this->exactly(2))->method('getKey')->willReturn('mock');
22 1
        $channelMap = new ChannelMap([$channelMock]);
23 1
        $newMap = new ChannelMap($channelMap);
24 1
        $this->assertCount(1, $newMap);
25 1
        $this->assertFalse($channelMap === $newMap);
26 1
    }
27
28 1
    public function testConstructWithDuplicateKey(): void
29
    {
30 1
        $this->expectException(InvalidArgumentException::class);
31 1
        $channelMock = $this->createMock(ChannelInterface::class);
32 1
        $channelMock->expects($this->exactly(2))->method('getKey')->willReturn('mock');
33 1
        new ChannelMap([$channelMock, $channelMock]);
34
    }
35
36 1
    public function testPush(): void
37
    {
38 1
        $emptyMap = new ChannelMap;
39
        /** @var ChannelInterface $channelMock */
40 1
        $channelMock = $this->createMock(ChannelInterface::class);
41 1
        $channelMap = $emptyMap->with('mock', $channelMock);
42 1
        $this->assertCount(1, $channelMap);
43 1
        $this->assertEquals($channelMock, $channelMap->get('mock'));
44 1
        $this->assertTrue($emptyMap->isEmpty());
45 1
    }
46
}
47