public function load(Storage $storage) { if ($this->file->exists()) { require $this->file; // require nicht require_once if (!isset($data)) { throw new \Psc\Exception('Invalid state of storageFile: ' . $this->file . ' This is critical due to hacking!'); } } else { $data = array(); } $storage->setData($data); return $this; }
public function testStorage() { $storage = new Storage(new PHPStorageDriver($this->storageFile)); $data = array('eins' => 'dataeins', 'drei' => array('datadreiisarray'), 'vier' => 7); $storage->setData($data); $storage->persist(); $this->assertFileExists((string) $this->storageFile); unset($storage); /* Load Test */ $persistedStorage = new Storage(new PHPStorageDriver($this->storageFile)); $this->assertEquals($data, $persistedStorage->init()->getData()->toArray()); /* modify Test */ $persistedStorage->getData()->set('fuenf', 5); $data['fuenf'] = 5; $this->assertEquals($data, $persistedStorage->getData()->toArray()); $persistedStorage->persist(); /* load modified Test */ $modifiedStorage = new Storage(new PHPStorageDriver($this->storageFile)); $this->assertEquals(array(), $modifiedStorage->getData()->toArray()); $this->assertEquals($data, $modifiedStorage->init()->getData()->toArray()); }