From fb2ecc6c1811eeaa244a5d2318086985e7badce9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 10 Aug 2014 11:52:31 -0500 Subject: [PATCH] Hash: refactor unit tests --- tests/Unit/Crypt/Hash/SHA256_96Test.php | 22 ++++++++++------------ tests/Unit/Crypt/Hash/SHA512_96Test.php | 22 ++++++++++------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/Unit/Crypt/Hash/SHA256_96Test.php b/tests/Unit/Crypt/Hash/SHA256_96Test.php index 14029faf..dc2a874c 100644 --- a/tests/Unit/Crypt/Hash/SHA256_96Test.php +++ b/tests/Unit/Crypt/Hash/SHA256_96Test.php @@ -12,21 +12,19 @@ class Unit_Crypt_Hash_SHA256_96Test extends Unit_Crypt_Hash_SHA256Test return new Crypt_Hash('sha256-96'); } - static public function hashData() + /** + * @dataProvider hashData() + */ + public function testHash($message, $longResult) { - $tests = parent::hashData(); - foreach ($tests as &$test) { - $test[1] = substr($test[1], 0, 24); - } - return $tests; + parent::testHash($message, substr($longResult, 0, 24)); } - static public function hmacData() + /** + * @dataProvider hmacData() + */ + public function testHMAC($key, $message, $longResult) { - $tests = parent::hmacData(); - foreach ($tests as &$test) { - $test[2] = substr($test[2], 0, 24); - } - return $tests; + $this->assertHMACsTo($this->getInstance(), $key, $message, substr($longResult, 0, 24)); } } diff --git a/tests/Unit/Crypt/Hash/SHA512_96Test.php b/tests/Unit/Crypt/Hash/SHA512_96Test.php index d3f7721c..160372e4 100644 --- a/tests/Unit/Crypt/Hash/SHA512_96Test.php +++ b/tests/Unit/Crypt/Hash/SHA512_96Test.php @@ -12,21 +12,19 @@ class Unit_Crypt_Hash_SHA512_96Test extends Unit_Crypt_Hash_SHA512Test return new Crypt_Hash('sha512-96'); } - static public function hashData() + /** + * @dataProvider hashData() + */ + public function testHash($message, $longResult) { - $tests = parent::hashData(); - foreach ($tests as &$test) { - $test[1] = substr($test[1], 0, 24); - } - return $tests; + parent::testHash($message, substr($longResult, 0, 24)); } - static public function hmacData() + /** + * @dataProvider hmacData() + */ + public function testHMAC($key, $message, $longResult) { - $tests = parent::hmacData(); - foreach ($tests as &$test) { - $test[2] = substr($test[2], 0, 24); - } - return $tests; + $this->assertHMACsTo($this->getInstance(), $key, $message, substr($longResult, 0, 24)); } }