mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-25 18:53:25 +02:00
32 lines
875 B
PHP
32 lines
875 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Structural\DataMapper\Tests;
|
|
|
|
use DesignPatterns\Structural\DataMapper\StorageAdapter;
|
|
use DesignPatterns\Structural\DataMapper\User;
|
|
use DesignPatterns\Structural\DataMapper\UserMapper;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DataMapperTest extends TestCase
|
|
{
|
|
public function testCanMapUserFromStorage()
|
|
{
|
|
$storage = new StorageAdapter([1 => ['username' => 'domnikl', 'email' => 'liebler.dominik@gmail.com']]);
|
|
$mapper = new UserMapper($storage);
|
|
|
|
$user = $mapper->findById(1);
|
|
|
|
$this->assertInstanceOf(User::class, $user);
|
|
}
|
|
|
|
public function testWillNotMapInvalidData()
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$storage = new StorageAdapter([]);
|
|
$mapper = new UserMapper($storage);
|
|
|
|
$mapper->findById(1);
|
|
}
|
|
}
|