Browse Source

Fixup Database behaviour

pull/10582/head
Philipp 6 months ago
parent
commit
470ba8b61b
No known key found for this signature in database GPG Key ID: 9A28B7D4FF5667BD
  1. 2
      src/Model/Storage/Database.php
  2. 6
      tests/src/Model/Storage/DatabaseStorageTest.php
  3. 5
      tests/src/Model/Storage/FilesystemStorageTest.php
  4. 6
      tests/src/Model/Storage/StorageTest.php

2
src/Model/Storage/Database.php

@ -101,7 +101,7 @@ class Database implements ISelectableStorage
public function delete(string $reference)
{
try {
if (!$this->dba->delete('storage', ['id' => $reference])) {
if (!$this->dba->delete('storage', ['id' => $reference]) || $this->dba->affectedRows() === 0) {
throw new ReferenceStorageException(sprintf('Database storage failed to delete %s', $reference));
}
} catch (Exception $exception) {

6
tests/src/Model/Storage/DatabaseStorageTest.php

@ -21,16 +21,14 @@
namespace Friendica\Test\src\Model\Storage;
use Friendica\Core\L10n;
use Friendica\Factory\ConfigFactory;
use Friendica\Model\Storage\Database;
use Friendica\Model\Storage\IStorage;
use Friendica\Model\Storage\ISelectableStorage;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\Profiler;
use Mockery\MockInterface;
use Psr\Log\NullLogger;
class DatabaseStorageTest extends StorageTest
@ -65,7 +63,7 @@ class DatabaseStorageTest extends StorageTest
return new Database($dba);
}
protected function assertOption(IStorage $storage)
protected function assertOption(ISelectableStorage $storage)
{
self::assertEmpty($storage->getOptions());
}

5
tests/src/Model/Storage/FilesystemStorageTest.php

@ -24,13 +24,12 @@ namespace Friendica\Test\src\Model\Storage;
use Friendica\Core\Config\IConfig;
use Friendica\Core\L10n;
use Friendica\Model\Storage\Filesystem;
use Friendica\Model\Storage\IStorage;
use Friendica\Model\Storage\ISelectableStorage;
use Friendica\Model\Storage\StorageException;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Profiler;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStream;
use Psr\Log\NullLogger;
class FilesystemStorageTest extends StorageTest
{
@ -65,7 +64,7 @@ class FilesystemStorageTest extends StorageTest
return new Filesystem($this->config, $l10n);
}
protected function assertOption(IStorage $storage)
protected function assertOption(ISelectableStorage $storage)
{
self::assertEquals([
'storagepath' => [

6
tests/src/Model/Storage/StorageTest.php

@ -21,17 +21,17 @@
namespace Friendica\Test\src\Model\Storage;
use Friendica\Model\Storage\ISelectableStorage;
use Friendica\Model\Storage\IStorage;
use Friendica\Model\Storage\ReferenceStorageException;
use Friendica\Model\Storage\StorageException;
use Friendica\Test\MockedTest;
abstract class StorageTest extends MockedTest
{
/** @return IStorage */
/** @return ISelectableStorage */
abstract protected function getInstance();
abstract protected function assertOption(IStorage $storage);
abstract protected function assertOption(ISelectableStorage $storage);
/**
* Test if the instance is "really" implementing the interface

Loading…
Cancel
Save