Minor code tidy up

This commit is contained in:
Andrew Millington
2018-02-28 20:33:19 +00:00
parent c9b07f386c
commit a56acc8dd0
5 changed files with 25 additions and 17 deletions

View File

@@ -8,27 +8,32 @@ use PHPUnit\Framework\TestCase;
class CryptTraitTest extends TestCase
{
protected $cryptStub;
protected function setUp()
{
$this->cryptStub = new CryptTraitStub();
}
public function testEncryptDecryptWithPassword()
{
$cryptStub = new CryptTraitStub();
$cryptStub->setEncryptionKey(base64_encode(random_bytes(36)));
$this->cryptStub->setEncryptionKey(base64_encode(random_bytes(36)));
return $this->encryptDecrypt($cryptStub);
$this->encryptDecrypt();
}
public function testEncryptDecryptWithKey()
{
$cryptStub = new CryptTraitStub();
$cryptStub->setEncryptionKey(Key::createNewRandomKey());
$this->cryptStub->setEncryptionKey(Key::createNewRandomKey());
return $this->encryptDecrypt($cryptStub);
$this->encryptDecrypt();
}
protected function encryptDecrypt(CryptTraitStub $cryptStub)
private function encryptDecrypt()
{
$payload = 'alex loves whisky';
$encrypted = $cryptStub->doEncrypt($payload);
$plainText = $cryptStub->doDecrypt($encrypted);
$encrypted = $this->cryptStub->doEncrypt($payload);
$plainText = $this->cryptStub->doDecrypt($encrypted);
$this->assertNotEquals($payload, $encrypted);
$this->assertEquals($payload, $plainText);