Daniel J. Summers
d067f8983f
- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
* @license MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Test\Unit\Mapper;
|
|
|
|
use BitBadger\PDODocument\Mapper\StringMapper;
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Unit tests for the StringMapper class
|
|
*/
|
|
#[TestDox('String Mapper (Unit tests)')]
|
|
class StringMapperTest extends TestCase
|
|
{
|
|
#[TestDox('map() succeeds when field is present and string')]
|
|
public function testMapSucceedsWhenFieldIsPresentAndString(): void
|
|
{
|
|
$result = ['test_field' => 'test_value'];
|
|
$mapper = new StringMapper('test_field');
|
|
$this->assertEquals('test_value', $mapper->map($result), 'String value not returned correctly');
|
|
}
|
|
|
|
#[TestDox('map() succeeds when field is present and not string')]
|
|
public function testMapSucceedsWhenFieldIsPresentAndNotString(): void
|
|
{
|
|
$result = ['a_number' => 6.7];
|
|
$mapper = new StringMapper('a_number');
|
|
$this->assertEquals('6.7', $mapper->map($result), 'Number value not returned correctly');
|
|
}
|
|
|
|
#[TestDox('map() succeeds when field is not present')]
|
|
public function testMapSucceedsWhenFieldIsNotPresent(): void
|
|
{
|
|
$mapper = new StringMapper('something_else');
|
|
$this->assertNull($mapper->map([]), 'Missing value not returned correctly');
|
|
}
|
|
}
|