Add tests

This commit is contained in:
brabli
2025-11-27 15:07:44 +00:00
parent ca29d72615
commit 376aede1ba

View File

@@ -0,0 +1,64 @@
<?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);
}
}