mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-12 01:54:26 +02:00
Change repository naming to avoid naming conflicts
This commit is contained in:
parent
febcdd72c7
commit
02fb800d12
13 changed files with 186 additions and 177 deletions
97
tests/Unit/Database/Repository/CacheTableRepositoryTest.php
Normal file
97
tests/Unit/Database/Repository/CacheTableRepositoryTest.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?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\Database\Repository;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DatabaseException;
|
||||
use Friendica\Database\Repository\CacheTableRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Throwable;
|
||||
|
||||
class CacheTableRepositoryTest extends TestCase
|
||||
{
|
||||
public function testGetAllKeysValidUntilReturnsArray(): void
|
||||
{
|
||||
$stmt = new \stdClass;
|
||||
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('select')->willReturnMap([
|
||||
['cache', ['k'], ['`expires` >= ?', '2025-04-16 10:12:01'], [], $stmt],
|
||||
]);
|
||||
$database->method('fetch')->willReturnOnConsecutiveCalls(
|
||||
['k' => 'value1'],
|
||||
['k' => 'value2'],
|
||||
['k' => 'value3'],
|
||||
false
|
||||
);
|
||||
|
||||
$repo = new CacheTableRepository($database);
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
'value1',
|
||||
'value2',
|
||||
'value3',
|
||||
],
|
||||
$repo->getAllKeysValidUntil('2025-04-16 10:12:01')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAllKeysValidUntilThrowsException(): void
|
||||
{
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('select')->willThrowException($this->createStub(Throwable::class));
|
||||
|
||||
$repo = new CacheTableRepository($database);
|
||||
|
||||
$this->expectException(DatabaseException::class);
|
||||
|
||||
$repo->getAllKeysValidUntil('2025-04-16 10:12:01');
|
||||
}
|
||||
|
||||
public function testGetAllKeysValidUntilWithPrefixReturnsArray(): void
|
||||
{
|
||||
$stmt = new \stdClass;
|
||||
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('select')->willReturnMap([
|
||||
['cache', ['k'], ['`expires` >= ?', '2025-04-16 10:12:01'], [], $stmt],
|
||||
]);
|
||||
$database->method('fetch')->willReturnOnConsecutiveCalls(
|
||||
['k' => 'value1'],
|
||||
['k' => 'value2'],
|
||||
['k' => 'value3'],
|
||||
false
|
||||
);
|
||||
|
||||
$repo = new CacheTableRepository($database);
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
'value1',
|
||||
'value2',
|
||||
'value3',
|
||||
],
|
||||
$repo->getAllKeysValidUntilWithPrefix('2025-04-16 10:12:01', 'prefix')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAllKeysValidUntilWithPrefixThrowsException(): void
|
||||
{
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('select')->willThrowException($this->createStub(Throwable::class));
|
||||
|
||||
$repo = new CacheTableRepository($database);
|
||||
|
||||
$this->expectException(DatabaseException::class);
|
||||
|
||||
$repo->getAllKeysValidUntilWithPrefix('2025-04-16 10:12:01', 'prefix');
|
||||
}
|
||||
}
|
77
tests/Unit/Database/Repository/UserdTableRepositoryTest.php
Normal file
77
tests/Unit/Database/Repository/UserdTableRepositoryTest.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\Database\Repository;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DatabaseException;
|
||||
use Friendica\Database\Repository\UserdTableRepository;
|
||||
use Friendica\Repository\DeletedUserRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UserdTableRepositoryTest extends TestCase
|
||||
{
|
||||
public function testImplementationOfInterfaces(): void
|
||||
{
|
||||
$repo = new UserdTableRepository($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 UserdTableRepository($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 UserdTableRepository($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 UserdTableRepository($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 UserdTableRepository($database);
|
||||
|
||||
$this->assertFalse($repo->existsByUsername('test'));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue