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

MetadataEnricherListTest::testPrependEnricher()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
ccs 12
cts 12
cp 1
crap 2
rs 9.9
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