Skip to content

Commit 92d9bb1

Browse files
Fix code style
1 parent b65d486 commit 92d9bb1

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

tests/Utils/CryptKeyTest.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function testKeyFileCreation()
3333

3434
$key = new CryptKey($keyContent);
3535

36-
$this->assertEquals(
37-
'file://' . \sys_get_temp_dir() . '/' . \sha1($keyContent) . '.key',
38-
$key->getKeyPath()
39-
);
36+
$this->assertEquals(self::generateKeyPath($keyContent), $key->getKeyPath());
4037

4138
$keyContent = \file_get_contents(__DIR__ . '/../Stubs/private.key.crlf');
4239

@@ -46,10 +43,7 @@ public function testKeyFileCreation()
4643

4744
$key = new CryptKey($keyContent);
4845

49-
$this->assertEquals(
50-
'file://' . \sys_get_temp_dir() . '/' . \sha1($keyContent) . '.key',
51-
$key->getKeyPath()
52-
);
46+
$this->assertEquals(self::generateKeyPath($keyContent), $key->getKeyPath());
5347
}
5448

5549
public function testUnsupportedKeyType()
@@ -65,13 +59,13 @@ public function testUnsupportedKeyType()
6559
'private_key_type' => OPENSSL_KEYTYPE_DSA,
6660
]);
6761
// Get private key
68-
\openssl_pkey_export($res, $privkey, 'mystrongpassword');
69-
$path = 'file://' . \sys_get_temp_dir() . '/' . \sha1($privkey) . '.key';
62+
\openssl_pkey_export($res, $keyContent, 'mystrongpassword');
63+
$path = self::generateKeyPath($keyContent);
7064

71-
new CryptKey($privkey, 'mystrongpassword');
65+
new CryptKey($keyContent, 'mystrongpassword');
7266
} finally {
7367
if (isset($path)) {
74-
@unlink($path);
68+
@\unlink($path);
7569
}
7670
}
7771
}
@@ -86,19 +80,18 @@ public function testECKeyType()
8680
'private_key_type' => OPENSSL_KEYTYPE_EC,
8781
]);
8882
// Get private key
89-
\openssl_pkey_export($res, $privkey, 'mystrongpassword');
83+
\openssl_pkey_export($res, $keyContent, 'mystrongpassword');
9084

91-
$key = new CryptKey($privkey, 'mystrongpassword');
92-
$path = 'file://' . \sys_get_temp_dir() . '/' . \sha1($privkey) . '.key';
85+
$key = new CryptKey($keyContent, 'mystrongpassword');
86+
$path = self::generateKeyPath($keyContent);
9387

9488
$this->assertEquals($path, $key->getKeyPath());
9589
$this->assertEquals('mystrongpassword', $key->getPassPhrase());
96-
9790
} catch (\Throwable $e) {
9891
$this->fail('The EC key was not created');
9992
} finally {
10093
if (isset($path)) {
101-
@unlink($path);
94+
@\unlink($path);
10295
}
10396
}
10497
}
@@ -113,19 +106,29 @@ public function testRSAKeyType()
113106
'private_key_type' => OPENSSL_KEYTYPE_RSA,
114107
]);
115108
// Get private key
116-
\openssl_pkey_export($res, $privkey, 'mystrongpassword');
109+
\openssl_pkey_export($res, $keyContent, 'mystrongpassword');
117110

118-
$key = new CryptKey($privkey, 'mystrongpassword');
119-
$path = 'file://' . \sys_get_temp_dir() . '/' . \sha1($privkey) . '.key';
111+
$key = new CryptKey($keyContent, 'mystrongpassword');
112+
$path = self::generateKeyPath($keyContent);
120113

121114
$this->assertEquals($path, $key->getKeyPath());
122115
$this->assertEquals('mystrongpassword', $key->getPassPhrase());
123116
} catch (\Throwable $e) {
124117
$this->fail('The RSA key was not created');
125118
} finally {
126119
if (isset($path)) {
127-
@unlink($path);
120+
@\unlink($path);
128121
}
129122
}
130123
}
124+
125+
/**
126+
* @param string $keyContent
127+
*
128+
* @return string
129+
*/
130+
private static function generateKeyPath($keyContent)
131+
{
132+
return 'file://' . \sys_get_temp_dir() . '/' . \sha1($keyContent) . '.key';
133+
}
131134
}

0 commit comments

Comments
 (0)