Skip to content

Commit fee9dd0

Browse files
committed
test: use Reflection to access protected property in SodiumHandlerTest
1 parent b4c23fd commit fee9dd0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tests/system/Encryption/Handlers/SodiumHandlerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Test\CIUnitTestCase;
1919
use Config\Encryption as EncryptionConfig;
2020
use PHPUnit\Framework\Attributes\Group;
21+
use ReflectionProperty;
2122
use SodiumException;
2223

2324
/**
@@ -164,13 +165,15 @@ public function testBug0IssetThrowsTypeError(): void
164165

165166
public function testBug1MemzeroZeroesInternalKey(): void
166167
{
167-
/** @var SodiumHandler $encrypter */
168-
$encrypter = $this->encryption->initialize($this->config);
169-
$originalKey = $encrypter->key; // @phpstan-ignore-line
168+
$encrypter = $this->encryption->initialize($this->config);
169+
170+
$refKey = new ReflectionProperty($encrypter, 'key');
171+
172+
$originalKey = $refKey->getValue($encrypter);
170173

171174
$encrypter->encrypt('message');
172175

173-
$this->assertSame($originalKey, $encrypter->key); // @phpstan-ignore-line
176+
$this->assertSame($originalKey, $refKey->getValue($encrypter));
174177
}
175178

176179
public function testBug2InvalidKeyLengthThrowsSodiumException(): void

0 commit comments

Comments
 (0)