diff --git a/src/CryptKey.php b/src/CryptKey.php index adcacfd3..aedeafb0 100644 --- a/src/CryptKey.php +++ b/src/CryptKey.php @@ -51,6 +51,8 @@ class CryptKey /** * @param string $key * + * @throws \RuntimeException + * * @return string */ private function saveKeyToFile($key) @@ -58,7 +60,9 @@ class CryptKey $keyPath = sys_get_temp_dir() . '/' . sha1($key) . '.key'; if (!file_exists($keyPath) && !touch($keyPath)) { + // @codeCoverageIgnoreStart throw new \RuntimeException('"%s" key file could not be created', $keyPath); + // @codeCoverageIgnoreEnd } file_put_contents($keyPath, $key); diff --git a/tests/CryptKeyTest.php b/tests/CryptKeyTest.php new file mode 100644 index 00000000..c7f7f4a0 --- /dev/null +++ b/tests/CryptKeyTest.php @@ -0,0 +1,36 @@ +assertEquals('file://' . $keyFile, $key->getKeyPath()); + $this->assertEquals('secret', $key->getPassPhrase()); + } + + public function testKeyFileCreation() + { + $keyContent = file_get_contents(__DIR__ . '/Stubs/public.key'); + $key = new CryptKey($keyContent); + + $this->assertEquals( + 'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key', + $key->getKeyPath() + ); + } +}