3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Core\Storage;
24 use Friendica\Core\Storage\Capability\ICanReadFromStorage;
25 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
26 use Friendica\Core\Storage\Exception\ReferenceStorageException;
27 use Friendica\Test\MockedTest;
29 abstract class StorageTest extends MockedTest
31 /** @return ICanWriteToStorage */
32 abstract protected function getInstance();
35 * Test if the instance is "really" implementing the interface
37 public function testInstance()
39 $instance = $this->getInstance();
40 self::assertInstanceOf(ICanReadFromStorage::class, $instance);
44 * Test basic put, get and delete operations
46 public function testPutGetDelete()
48 $instance = $this->getInstance();
50 $ref = $instance->put('data12345');
51 self::assertNotEmpty($ref);
53 self::assertEquals('data12345', $instance->get($ref));
55 $instance->delete($ref);
59 * Test a delete with an invalid reference
61 public function testInvalidDelete()
63 self::expectException(ReferenceStorageException::class);
65 $instance = $this->getInstance();
67 $instance->delete(-1234456);
71 * Test a get with an invalid reference
73 public function testInvalidGet()
75 self::expectException(ReferenceStorageException::class);
77 $instance = $this->getInstance();
79 $instance->get(-123456);
83 * Test an update with a given reference
85 public function testUpdateReference()
87 $instance = $this->getInstance();
89 $ref = $instance->put('data12345');
90 self::assertNotEmpty($ref);
92 self::assertEquals('data12345', $instance->get($ref));
94 self::assertEquals($ref, $instance->put('data5432', $ref));
95 self::assertEquals('data5432', $instance->get($ref));
99 * Test that an invalid update results in an insert
101 public function testInvalidUpdate()
103 $instance = $this->getInstance();
105 self::assertEquals(-123, $instance->put('data12345', -123));