From 8a7a68947e4491d8dbc778d0d1afb4266065cf56 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 31 Dec 2023 02:07:24 +0800 Subject: [PATCH] test: ensure no .env when EncryptionTest is run --- tests/system/Encryption/EncryptionTest.php | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/system/Encryption/EncryptionTest.php b/tests/system/Encryption/EncryptionTest.php index 9ab09dc77216..d9391d0d1726 100644 --- a/tests/system/Encryption/EncryptionTest.php +++ b/tests/system/Encryption/EncryptionTest.php @@ -25,19 +25,40 @@ final class EncryptionTest extends CIUnitTestCase { private Encryption $encryption; + public static function setUpBeforeClass(): void + { + parent::setUpBeforeClass(); + + if (is_file(ROOTPATH . '.env')) { + rename(ROOTPATH . '.env', ROOTPATH . '.env.bak'); + + putenv('encryption.key'); + unset($_ENV['encryption.key'], $_SERVER['encryption.key']); + } + } + protected function setUp(): void { + parent::setUp(); + $this->encryption = new Encryption(); } + public static function tearDownAfterClass(): void + { + parent::tearDownAfterClass(); + + if (is_file(ROOTPATH . '.env.bak')) { + rename(ROOTPATH . '.env.bak', ROOTPATH . '.env'); + } + } + /** - * __construct test - * * Covers behavior with config encryption key set or not */ public function testConstructor(): void { - // Assume no configuration from set_up() + // Assume no configuration from setUp() $this->assertEmpty($this->encryption->key); // Try with an empty value