Passed
Push — master ( 00462a...740508 )
by Mr
02:03
created

MetadataEnricherListTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 22
c 4
b 0
f 0
dl 0
loc 37
ccs 26
cts 26
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testPrependEnricher() 0 15 2
A testWith() 0 8 1
A testConstructWithSelf() 0 8 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/metadata 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\Metadata;
10
11
use Daikon\Metadata\Metadata;
12
use Daikon\Metadata\MetadataEnricherInterface;
13
use Daikon\Metadata\MetadataEnricherList;
0 ignored issues
show
Bug introduced by
The type Daikon\Metadata\MetadataEnricherList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use PHPUnit\Framework\TestCase;
15
16
final class MetadataEnricherListTest extends TestCase
17
{
18 1
    public function testConstructWithSelf(): void
19
    {
20
        /** @var MetadataEnricherInterface $mockEnricher */
21 1
        $mockEnricher = $this->createMock(MetadataEnricherInterface::class);
22 1
        $enricherList = new MetadataEnricherList([$mockEnricher]);
23 1
        $newList = new MetadataEnricherList($enricherList);
24 1
        $this->assertCount(1, $newList);
25 1
        $this->assertFalse($enricherList === $newList);
26 1
    }
27
28 1
    public function testWith(): void
29
    {
30 1
        $emptyList = new MetadataEnricherList;
31
        /** @var MetadataEnricherInterface $mockEnricher */
32 1
        $mockEnricher = $this->createMock(MetadataEnricherInterface::class);
33 1
        $enricherList = $emptyList->push($mockEnricher);
34 1
        $this->assertCount(1, $enricherList);
35 1
        $this->assertTrue($emptyList->isEmpty());
36 1
    }
37
38 1
    public function testPrependEnricher(): void
39
    {
40 1
        $mockEnricher = $this->createMock(MetadataEnricherInterface::class);
41 1
        $mockEnricher->expects($this->once())->method('enrich')->willReturnArgument(0);
42 1
        $enricherList = new MetadataEnricherList([$mockEnricher]);
43 1
        $newList = $enricherList->prependEnricher('key', 'value');
44 1
        $this->assertCount(2, $newList);
45 1
        $this->assertNotSame($enricherList, $newList);
46 1
        $this->assertFalse($enricherList === $newList);
47 1
        $metadata = Metadata::fromNative(['abc' => 'xyz']);
48
        /** @var MetadataEnricherInterface $enricher */
49 1
        foreach ($newList as $enricher) {
50 1
            $metadata = $enricher->enrich($metadata);
51
        }
52 1
        $this->assertEquals(['abc' => 'xyz', 'key' => 'value'], $metadata->toNative());
53 1
    }
54
}
55