Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Jun 5, 2020
1 parent 00462a0 commit 7405087
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/MetadataEnricherList.php
Expand Up @@ -17,13 +17,11 @@ public function __construct(iterable $enrichers = [])
$this->init($enrichers, [MetadataEnricherInterface::class]);
}

public function prependEnricher(string $namespace, string $value): self
public function prependEnricher(string $key, string $value): self
{
return $this->unshift(
new CallbackMetadataEnricher(
function (MetadataInterface $metadata) use ($namespace, $value): MetadataInterface {
return $metadata->with($namespace, $value);
}
fn(MetadataInterface $metadata): MetadataInterface => $metadata->with($key, $value)
)
);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Metadata/MetadataEnricherListTest.php
Expand Up @@ -8,6 +8,7 @@

namespace Daikon\Tests\Metadata;

use Daikon\Metadata\Metadata;
use Daikon\Metadata\MetadataEnricherInterface;
use Daikon\Metadata\MetadataEnricherList;
use PHPUnit\Framework\TestCase;
Expand All @@ -33,4 +34,21 @@ public function testWith(): void
$this->assertCount(1, $enricherList);
$this->assertTrue($emptyList->isEmpty());
}

public function testPrependEnricher(): void
{
$mockEnricher = $this->createMock(MetadataEnricherInterface::class);
$mockEnricher->expects($this->once())->method('enrich')->willReturnArgument(0);
$enricherList = new MetadataEnricherList([$mockEnricher]);
$newList = $enricherList->prependEnricher('key', 'value');
$this->assertCount(2, $newList);
$this->assertNotSame($enricherList, $newList);
$this->assertFalse($enricherList === $newList);
$metadata = Metadata::fromNative(['abc' => 'xyz']);
/** @var MetadataEnricherInterface $enricher */
foreach ($newList as $enricher) {
$metadata = $enricher->enrich($metadata);
}
$this->assertEquals(['abc' => 'xyz', 'key' => 'value'], $metadata->toNative());
}
}

0 comments on commit 7405087

Please sign in to comment.