mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-08 00:04:27 +02:00
move repositories and models into own namespace, create interfaces
This commit is contained in:
parent
e66568b78f
commit
febcdd72c7
13 changed files with 301 additions and 194 deletions
77
tests/Unit/Repository/UserdRepositoryTest.php
Normal file
77
tests/Unit/Repository/UserdRepositoryTest.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Repository;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DatabaseException;
|
||||
use Friendica\Database\Repository\DeletedUserRepository;
|
||||
use Friendica\Repository\UserdRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UserdRepositoryTest extends TestCase
|
||||
{
|
||||
public function testImplementationOfInterfaces(): void
|
||||
{
|
||||
$repo = new UserdRepository($this->createMock(Database::class));
|
||||
|
||||
$this->assertInstanceOf(DeletedUserRepository::class, $repo);
|
||||
}
|
||||
|
||||
public function testInsertByUsernameCallsDatabase(): void
|
||||
{
|
||||
$database = $this->createMock(Database::class);
|
||||
$database->expects($this->once())->method('insert')->willReturnMap([
|
||||
['userd', ['username' => 'test'], 0, true],
|
||||
]);
|
||||
|
||||
$repo = new UserdRepository($database);
|
||||
|
||||
$repo->insertByUsername('test');
|
||||
}
|
||||
|
||||
public function testInsertByUsernameThrowsException(): void
|
||||
{
|
||||
$database = $this->createMock(Database::class);
|
||||
$database->expects($this->exactly(2))->method('throwExceptionsOnErrors');
|
||||
$database->expects($this->once())->method('insert')->willThrowException(
|
||||
new DatabaseException('An error occured.', 0, 'SQL query')
|
||||
);
|
||||
|
||||
$repo = new UserdRepository($database);
|
||||
|
||||
$this->expectException(DatabaseException::class);
|
||||
|
||||
$repo->insertByUsername('test');
|
||||
}
|
||||
|
||||
public function testExistsByUsernameReturnsTrue(): void
|
||||
{
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('exists')->willReturnMap([
|
||||
['userd', ['username' => 'test'], true],
|
||||
]);
|
||||
|
||||
$repo = new UserdRepository($database);
|
||||
|
||||
$this->assertTrue($repo->existsByUsername('test'));
|
||||
}
|
||||
|
||||
public function testExistsByUsernameReturnsFalse(): void
|
||||
{
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('exists')->willReturnMap([
|
||||
['userd', ['username' => 'test'], false],
|
||||
]);
|
||||
|
||||
$repo = new UserdRepository($database);
|
||||
|
||||
$this->assertFalse($repo->existsByUsername('test'));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue