Skip to content

Commit e67dd09

Browse files
committed
add exception assert
1 parent c402e2e commit e67dd09

File tree

1 file changed

+21
-23
lines changed
  • dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/SecretStorage

1 file changed

+21
-23
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/SecretStorage/FileStorageTest.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@
88
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers\SecretStorage;
99

1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\FileStorage;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1112
use ReflectionClass;
13+
use ReflectionException;
1214
use tests\unit\Util\MagentoTestCase;
1315

1416
class FileStorageTest extends MagentoTestCase
1517
{
1618
/**
1719
* Test basic encryption/decryption functionality in FileStorage class.
20+
* @throws TestFrameworkException|ReflectionException
1821
*/
1922
public function testBasicEncryptDecrypt(): void
2023
{
2124
$testKey = 'magento/myKey';
2225
$testValue = 'myValue';
23-
$creds = ["$testKey=$testValue"];
26+
$cred = ["$testKey=$testValue"];
2427

2528
$fileStorage = new FileStorage();
2629
$reflection = new ReflectionClass(FileStorage::class);
2730

2831
// Emulate initialize() function result with the test credentials
2932
$reflectionMethod = $reflection->getMethod('encryptCredFileContents');
3033
$reflectionMethod->setAccessible(true);
31-
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$creds]);
34+
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$cred]);
3235

3336
// Set encrypted test credentials to the private 'secretData' property
3437
$reflectionProperty = $reflection->getProperty('secretData');
@@ -48,34 +51,29 @@ public function testBasicEncryptDecrypt(): void
4851

4952
/**
5053
* Test empty value encryption/decryption functionality in FileStorage class.
54+
* @return void
55+
* @throws TestFrameworkException|ReflectionException
5156
*/
5257
public function testEmptyValueEncryptDecrypt(): void
5358
{
54-
$testKey = 'magento/myKey';
55-
$testValue = '';
56-
$creds = ["$testKey"];
59+
$this->expectException(TestFrameworkException::class);
5760

58-
$fileStorage = new FileStorage();
59-
$reflection = new ReflectionClass(FileStorage::class);
60-
61-
// Emulate initialize() function result with the test credentials
62-
$reflectionMethod = $reflection->getMethod('encryptCredFileContents');
63-
$reflectionMethod->setAccessible(true);
64-
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$creds]);
65-
66-
// Set encrypted test credentials to the private 'secretData' property
67-
$reflectionProperty = $reflection->getProperty('secretData');
68-
$reflectionProperty->setAccessible(true);
69-
$reflectionProperty->setValue($fileStorage, $secretData);
61+
$testKey = 'magento/myKey';
62+
$cred = ["$testKey"];
7063

71-
$encryptedCred = $fileStorage->getEncryptedValue($testKey);
64+
$fileStorage = new FileStorage();
65+
$reflection = new ReflectionClass(FileStorage::class);
7266

73-
// assert the value we've gotten is in fact not identical to our test value
74-
$this->assertNotEquals($testValue, $encryptedCred);
67+
// Emulate initialize() function result with the test credentials
68+
$reflectionMethod = $reflection->getMethod('encryptCredFileContents');
69+
$reflectionMethod->setAccessible(true);
70+
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$cred]);
7571

76-
$actualValue = $fileStorage->getDecryptedValue($encryptedCred);
72+
// Set encrypted test credentials to the private 'secretData' property
73+
$reflectionProperty = $reflection->getProperty('secretData');
74+
$reflectionProperty->setAccessible(true);
75+
$reflectionProperty->setValue($fileStorage, $secretData);
7776

78-
// assert that we are able to successfully decrypt our secret value
79-
$this->assertEquals($testValue, $actualValue);
77+
$fileStorage->getEncryptedValue($testKey);
8078
}
8179
}

0 commit comments

Comments
 (0)