2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
namespace Test\Unit\Mapper;
|
|
|
|
|
|
|
|
use BitBadger\PDODocument\Mapper\StringMapper;
|
2024-06-21 13:46:41 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2024-06-21 13:46:41 +00:00
|
|
|
/**
|
|
|
|
* Unit tests for the StringMapper class
|
|
|
|
*/
|
|
|
|
#[TestDox('String Mapper (Unit tests)')]
|
2024-06-08 23:58:45 +00:00
|
|
|
class StringMapperTest extends TestCase
|
|
|
|
{
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() succeeds when field is present and string')]
|
2024-08-30 13:24:25 +00:00
|
|
|
public function testMapSucceedsWhenFieldIsPresentAndString(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
|
|
|
$result = ['test_field' => 'test_value'];
|
|
|
|
$mapper = new StringMapper('test_field');
|
|
|
|
$this->assertEquals('test_value', $mapper->map($result), 'String value not returned correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() succeeds when field is present and not string')]
|
2024-08-30 13:24:25 +00:00
|
|
|
public function testMapSucceedsWhenFieldIsPresentAndNotString(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
|
|
|
$result = ['a_number' => 6.7];
|
|
|
|
$mapper = new StringMapper('a_number');
|
|
|
|
$this->assertEquals('6.7', $mapper->map($result), 'Number value not returned correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() succeeds when field is not present')]
|
2024-08-30 13:24:25 +00:00
|
|
|
public function testMapSucceedsWhenFieldIsNotPresent(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
|
|
|
$mapper = new StringMapper('something_else');
|
|
|
|
$this->assertNull($mapper->map([]), 'Missing value not returned correctly');
|
|
|
|
}
|
|
|
|
}
|