/** * @param Password $password * @param bool $allowOverwrite */ public function store(Password $password, $allowOverwrite = false) { if (!$allowOverwrite && $this->get($password->getId())) { throw new PhPsstException('The ID already exists', PhPsstException::ID_IS_ALREADY_TAKEN); } $this->client->set($password->getId(), $password->getJson()); $this->client->expireat($password->getId(), $password->getTtl()); }
/** * @covers PhPsst\Storage\Storage::getPasswordFromJson */ public function testDeleteOnExpired() { $storage = new TestStorage(); $password = new Password('secretId', 'password', 300, 30); $jsonData = $password->getJson(); $returnedPassword = $storage->getPasswordFromJson($jsonData); $this->assertNull($returnedPassword); }
/** * @covers PhPsst\Password::getJson */ public function testGetJson() { $password = new Password('superSecretId', 'superSecretPassword', 123232321244, 983926); $jsonData = $password->getJson(); $this->assertContains('superSecretId', $jsonData); $this->assertContains('superSecretPassword', $jsonData); $this->assertContains('123232321244', $jsonData); $this->assertContains('983926', $jsonData); }
/** * @param Password $password */ protected function writeFile(Password $password) { $jsonData = $password->getJson(); $fileName = $this->getFileName($password); if (!is_writable(dirname($fileName)) || !file_put_contents($fileName, $jsonData)) { throw new \RuntimeException('Can not write file'); } $this->garbageCollection(); }