65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pcm\MetadataBundle\Tests\Model;
|
|
|
|
use Pcm\MetadataBundle\Exception\MissingKeyException;
|
|
use Pcm\MetadataBundle\Model\Metadata;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class MetadataTest extends TestCase
|
|
{
|
|
private Metadata $metadata;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$array = []; // Needs to be a var as it's passed by reference
|
|
$this->metadata = new Metadata($array);
|
|
}
|
|
|
|
public function testGetReturnsSetValue(): void
|
|
{
|
|
$value = 'brad woz ere';
|
|
$this->metadata->set('key', $value);
|
|
$result = $this->metadata->get('key');
|
|
$this->assertSame($value, $result);
|
|
}
|
|
|
|
public function testGetThrowsWhenKeyNotSet(): void
|
|
{
|
|
$this->expectException(MissingKeyException::class);
|
|
$this->metadata->get('missing');
|
|
}
|
|
|
|
public function testValueIsOverwritten(): void
|
|
{
|
|
$key = 'key';
|
|
$valueA = 'meta';
|
|
$valueB = 'data';
|
|
|
|
$this->metadata->set($key, $valueA);
|
|
$result = $this->metadata->get($key);
|
|
$this->assertSame($valueA, $result);
|
|
|
|
$this->metadata->set($key, $valueB);
|
|
$result = $this->metadata->get($key);
|
|
$this->assertSame($valueB, $result);
|
|
}
|
|
|
|
public function testHasReturnsTrueWhenKeyIsSet(): void
|
|
{
|
|
$key = 'null';
|
|
$this->metadata->set($key, null);
|
|
$result = $this->metadata->has($key);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testHasReturnsFalseWhenKeyIsNotSet(): void
|
|
{
|
|
$result = $this->metadata->has('missing');
|
|
$this->assertFalse($result);
|
|
}
|
|
}
|
|
|