slovocast/app/tests/Domain/Repository/UserRepositoryTest.php

48 lines
1.4 KiB
PHP

<?php
namespace Slovocast\Tests\Domain\Repository;
use Slovocast\Domain\Repository\User\UserRepository;
use Slovocast\Domain\Entity\User;
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
use Slovocast\Infrastructure\User\BasicUserAuthorization;
use Slovocast\Tests\TestCase;
class UserRepositoryTest extends TestCase
{
protected function getUser(): User
{
return User::fromArray([
'email' => 'dave@slovocast.com',
'name' => 'Dave SH',
'password' => 'hashed_password'
]);
}
public function testRegisteringAUser(): void
{
$user = $this->getUser();
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
$databaseHandler->getConnection()->willReturn(new class {
public function lastInsertId(): int
{
return 100;
}
});
$databaseHandler->insert(UserRepository::INSERT_QUERY, [
':name' => $user->getName(),
':email' => $user->getEmail(),
':password' => $user->getPassword()
])->willReturn(true);
$userRepository = new UserRepository(
$databaseHandler->reveal(),
new BasicUserAuthorization()
);
$results = $userRepository->create($user);
$this->assertTrue($results);
$this->assertEquals(100, $user->getId());
}
}