2024-11-17 03:54:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Slovocast\Tests\Domain\Repository;
|
|
|
|
|
|
|
|
use Slovocast\Domain\Repository\User\UserRepository;
|
|
|
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
|
|
|
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
|
|
|
use Slovocast\Tests\TestCase;
|
2024-11-18 02:03:48 +00:00
|
|
|
use Prophecy\Argument;
|
|
|
|
|
2024-11-17 03:54:26 +00:00
|
|
|
|
|
|
|
class UserRepositoryTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testRegisteringAUser(): void
|
|
|
|
{
|
2024-11-18 01:47:18 +00:00
|
|
|
$user = $this->getUserFromArray();
|
2024-11-17 03:54:26 +00:00
|
|
|
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
2024-11-18 01:47:18 +00:00
|
|
|
|
2024-11-18 02:40:16 +00:00
|
|
|
$databaseHandler
|
2024-11-18 02:54:45 +00:00
|
|
|
->execute(Argument::type('string'), Argument::type('array'))
|
2024-11-18 03:00:08 +00:00
|
|
|
->willReturn(true);
|
2024-11-18 02:40:16 +00:00
|
|
|
|
|
|
|
$databaseHandler
|
|
|
|
->getConnection()
|
|
|
|
->willReturn(new class {
|
|
|
|
public function lastInsertId(): int
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-11-17 03:54:26 +00:00
|
|
|
$userRepository = new UserRepository(
|
|
|
|
$databaseHandler->reveal(),
|
|
|
|
new BasicUserAuthorization()
|
|
|
|
);
|
|
|
|
|
2024-11-18 02:05:12 +00:00
|
|
|
/**
|
|
|
|
* We are testing if the User entity has been mutated by the `create`
|
|
|
|
* method in the UserRepository.
|
|
|
|
*/
|
2024-11-18 02:40:16 +00:00
|
|
|
$results = $userRepository->create($user);
|
|
|
|
$this->assertTrue($results);
|
2024-11-17 03:54:26 +00:00
|
|
|
$this->assertEquals(100, $user->getId());
|
2024-11-18 02:40:16 +00:00
|
|
|
|
|
|
|
$user->setName("Dave Smith-Hayes");
|
|
|
|
$results = $userRepository->update($user);
|
|
|
|
$this->assertTrue($results);
|
|
|
|
$this->assertEquals(
|
|
|
|
$user->getUpdatedAt()->format("dmY"),
|
|
|
|
(new \DateTime())->format("dmY")
|
|
|
|
);
|
2024-11-17 03:54:26 +00:00
|
|
|
}
|
|
|
|
}
|