mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-08 00:54:26 +02:00
allow inserting username with UserDeletedRepository
This commit is contained in:
parent
23d052c7fe
commit
00b4bd19d8
2 changed files with 52 additions and 0 deletions
|
@ -9,8 +9,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Friendica\Database\Repository;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DatabaseException;
|
||||
|
||||
/**
|
||||
* Repository for deleted users
|
||||
*/
|
||||
final class UserDeletedRepository
|
||||
{
|
||||
private Database $database;
|
||||
|
@ -20,6 +25,25 @@ final class UserDeletedRepository
|
|||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a deleted user by username.
|
||||
*
|
||||
* @throws \Exception If the username could not be inserted
|
||||
*/
|
||||
public function insertByUsername(string $username): void
|
||||
{
|
||||
$result = $this->database->insert('userd', ['username' => $username]);
|
||||
|
||||
if ($result === false) {
|
||||
throw new Exception(sprintf('Error while inserting username `%s` as deleted user.', $username));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a deleted username exists.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function existsByUsername(string $username): bool
|
||||
{
|
||||
return $this->database->exists('userd', ['username' => $username]);
|
||||
|
|
|
@ -9,12 +9,40 @@ declare(strict_types=1);
|
|||
|
||||
namespace Friendica\Test\Unit\Database\Repository;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\Repository\UserDeletedRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UserDeletedRepositoryTest extends TestCase
|
||||
{
|
||||
public function testInsertByUsernameReturnsFalse(): void
|
||||
{
|
||||
$database = $this->createMock(Database::class);
|
||||
$database->expects($this->once())->method('insert')->willReturnMap([
|
||||
['userd', ['username' => 'test'], 0, true],
|
||||
]);
|
||||
|
||||
$repo = new UserDeletedRepository($database);
|
||||
|
||||
$repo->insertByUsername('test');
|
||||
}
|
||||
|
||||
public function testInsertByUsernameThrowsException(): void
|
||||
{
|
||||
$database = $this->createMock(Database::class);
|
||||
$database->expects($this->once())->method('insert')->willReturnMap([
|
||||
['userd', ['username' => 'test'], 0, false],
|
||||
]);
|
||||
|
||||
$repo = new UserDeletedRepository($database);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('Error while inserting username `test` as deleted user.');
|
||||
|
||||
$repo->insertByUsername('test');
|
||||
}
|
||||
|
||||
public function testExistsByUsernameReturnsTrue(): void
|
||||
{
|
||||
$database = $this->createStub(Database::class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue