/** * @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 testGetPasswordFromJson() { $storage = new TestStorage(); $password = new Password('secretId', 'password', strtotime('+1 hour'), 30); $jsonData = $password->getJson(); $returnedPassword = $storage->getPasswordFromJson($jsonData); $this->assertEquals($password->getId(), $returnedPassword->getId()); $this->assertEquals($password->getPassword(), $returnedPassword->getPassword()); $this->assertEquals($password->getTtl(), $returnedPassword->getTtl()); $this->assertEquals($password->getViews(), $returnedPassword->getViews()); }
/** * @covers PhPsst\Password::getTtl */ public function testGetTtl() { $this->assertEquals(123, $this->password->getTtl()); }