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()); }
public function persist(Storage $storage) { $this->file->writeContents(\Psc\TPL\TPL::miniTemplate($this->template, array('dataPHP' => '$data = ' . var_export($storage->getData()->getData(), TRUE) . ';')), File::EXCLUSIVE); return $this; }