Skip to content

Commit 5f655f1

Browse files
authored
Merge pull request #8392 from paulbalandan/encryption-test-with-env
test: ensure no .env when EncryptionTest is run
2 parents 7b7e63c + 8a7a689 commit 5f655f1

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

tests/system/Encryption/EncryptionTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,40 @@ final class EncryptionTest extends CIUnitTestCase
2525
{
2626
private Encryption $encryption;
2727

28+
public static function setUpBeforeClass(): void
29+
{
30+
parent::setUpBeforeClass();
31+
32+
if (is_file(ROOTPATH . '.env')) {
33+
rename(ROOTPATH . '.env', ROOTPATH . '.env.bak');
34+
35+
putenv('encryption.key');
36+
unset($_ENV['encryption.key'], $_SERVER['encryption.key']);
37+
}
38+
}
39+
2840
protected function setUp(): void
2941
{
42+
parent::setUp();
43+
3044
$this->encryption = new Encryption();
3145
}
3246

47+
public static function tearDownAfterClass(): void
48+
{
49+
parent::tearDownAfterClass();
50+
51+
if (is_file(ROOTPATH . '.env.bak')) {
52+
rename(ROOTPATH . '.env.bak', ROOTPATH . '.env');
53+
}
54+
}
55+
3356
/**
34-
* __construct test
35-
*
3657
* Covers behavior with config encryption key set or not
3758
*/
3859
public function testConstructor(): void
3960
{
40-
// Assume no configuration from set_up()
61+
// Assume no configuration from setUp()
4162
$this->assertEmpty($this->encryption->key);
4263

4364
// Try with an empty value

0 commit comments

Comments
 (0)