From 065ef5db996c5bebc4eee840b791289b7c53aecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Tue, 19 Jul 2016 17:15:36 +0200 Subject: [PATCH] CryptKey tests --- src/CryptKey.php | 4 ++++ tests/CryptKeyTest.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/CryptKeyTest.php 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() + ); + } +}