loadProvider(); } public function tearDown(): void { parent::tearDown(); // Always clear the provider at the end $this->provider->clear(); } private function loadProvider() { /** @var Storage $objectStorageComponent */ $objectStorageComponent = Factory::getInstance('storage'); $this->provider = $objectStorageComponent->getStorage(); } public function testFoundation() { $this->assertInstanceOf('\FuzeWorks\Storage\iStorageProvider', $this->provider); } /** * @depends testFoundation */ public function testSave() { $testData = ['hello', 'world', 'foo' => 'bar']; // First assert it does not exist yet $this->assertNull($this->provider->getItem('testData')); $this->assertFalse($this->provider->hasItem('testData')); // Write the data $this->assertTrue($this->provider->save('testData', $testData)); // Read the data $this->assertTrue($this->provider->hasItem('testData')); $this->assertEquals(['hello', 'world', 'foo' => 'bar'], $this->provider->getItem('testData')); } /** * @depends testSave */ public function testDeleteItem() { $testData = ['o', 'm', 'g']; // First assert that the data does not exist yet $this->assertNull($this->provider->getItem('testDeleteData')); // Write the data $this->assertTrue($this->provider->save('testDeleteData', $testData)); // Read the data $this->assertEquals(['o', 'm', 'g'], $this->provider->getItem('testDeleteData')); // Delete the data $this->assertTrue($this->provider->deleteItem('testDeleteData')); // And test that it is truly gone $this->assertNull($this->provider->getItem('testDeleteData')); } /** * @depends testDeleteItem */ public function testDeleteItems() { $testData = 'lord'; $testData2 = 'almighty'; // First assert that the data does not exist yet $this->assertNull($this->provider->getItem('testDeleteData1')); $this->assertNull($this->provider->getItem('testDeleteData2')); // Write the data $this->assertTrue($this->provider->save('testDeleteData1', $testData)); $this->assertTrue($this->provider->save('testDeleteData2', $testData2)); // Read the data $this->assertEquals( ['testDeleteData1' => 'lord', 'testDeleteData2' => 'almighty'], $this->provider->getItems(['testDeleteData1', 'testDeleteData2']) ); // Delete the data $this->assertTrue($this->provider->deleteItems(['testDeleteData1', 'testDeleteData2'])); // And test that it is truly gone $this->assertNull($this->provider->getItem('testDeleteData1')); $this->assertNull($this->provider->getItem('testDeleteData2')); } /** * @depends testDeleteItems */ public function testClear() { $testData = ['not', 'my', 'department']; // First assert it does not exist yet $this->assertNull($this->provider->getItem('testClearData')); $this->provider->save('testClearData', $testData); // Test that it can be read $this->assertEquals(['not', 'my', 'department'], $this->provider->getItem('testClearData')); // Then attempt to clean it $this->assertTrue($this->provider->clear()); // And check that it cannot be read $this->assertNull($this->provider->getItem('testClearData')); } public function testItemNotExist() { $this->assertNull($this->provider->getItem('doesNotExist')); } public function testGetMultipleItems() { $testData1 = ['tao', 'te', 'ching']; $testData2 = ['plato', 'aristotle']; // First assert they do not exist $this->assertNull($this->provider->getItem('philo1')); $this->assertNull($this->provider->getItem('philo2')); $this->assertEquals(['philo1' => null, 'philo2' => null], $this->provider->getItems(['philo1', 'philo2'])); // Then write both $this->assertTrue($this->provider->save('philo1', $testData1)); $this->assertTrue($this->provider->save('philo2', $testData2)); // Then read $this->assertEquals([ 'philo1' => ['tao', 'te', 'ching'], 'philo2' => ['plato', 'aristotle'] ], $this->provider->getItems(['philo1', 'philo2'])); } public function testItemMetaData() { $testData = ['meine', 'gute']; $metaData = ['someKey' => 'someValue']; // First assert that the data does not exist $this->assertNull($this->provider->getItem('testData')); $this->assertNull($this->provider->getItemMeta('testData')); // Then save the data $this->assertTrue($this->provider->save('testData', $testData, $metaData)); // Check the metaData $this->assertEquals(['someKey' => 'someValue'], $this->provider->getItemMeta('testData')); // Remove the key $this->provider->deleteItem('testData'); $this->assertNull($this->provider->getItemMeta('testData')); } }