Migrate remaining implementation
This commit is contained in:
@@ -4,7 +4,7 @@ namespace Test\Unit\Mapper;
|
||||
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Field;
|
||||
use BitBadger\PDODocument\Mapper\JsonMapper;
|
||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -21,26 +21,26 @@ class TestDocument
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit tests for the JsonMapper class
|
||||
* Unit tests for the DocumentMapper class
|
||||
*/
|
||||
class JsonMapperTest extends TestCase
|
||||
class DocumentMapperTest extends TestCase
|
||||
{
|
||||
public function testConstructorSucceedsWithDefaultField(): void
|
||||
{
|
||||
$mapper = new JsonMapper(Field::class);
|
||||
$mapper = new DocumentMapper(Field::class);
|
||||
$this->assertEquals('data', $mapper->fieldName, 'Default field name should have been "data"');
|
||||
}
|
||||
|
||||
public function testConstructorSucceedsWithSpecifiedField(): void
|
||||
{
|
||||
$mapper = new JsonMapper(Field::class, 'json');
|
||||
$mapper = new DocumentMapper(Field::class, 'json');
|
||||
$this->assertEquals('json', $mapper->fieldName, 'Field name not recorded correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds with valid JSON')]
|
||||
public function testMapSucceedsWithValidJSON(): void
|
||||
{
|
||||
$doc = (new JsonMapper(TestDocument::class))->map(['data' => '{"id":7,"subDoc":{"id":22,"name":"tester"}}']);
|
||||
$doc = (new DocumentMapper(TestDocument::class))->map(['data' => '{"id":7,"subDoc":{"id":22,"name":"tester"}}']);
|
||||
$this->assertNotNull($doc, 'The document should not have been null');
|
||||
$this->assertEquals(7, $doc->id, 'ID not filled correctly');
|
||||
$this->assertNotNull($doc->subDoc, 'The sub-document should not have been null');
|
||||
@@ -52,6 +52,6 @@ class JsonMapperTest extends TestCase
|
||||
public function testMapFailsWithInvalidJSON(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
(new JsonMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
||||
(new DocumentMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user