Skip to content

Commit 80b14c9

Browse files
chore: undo config changes in tests
1 parent 191b321 commit 80b14c9

File tree

1 file changed

+6
-3
lines changed
  • pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core

1 file changed

+6
-3
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/TestCase.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class TestCase {
4444
* @throws Error|Exception The exception thrown by failed Tests, typically an AssertionError.
4545
*/
4646
public function run(): void {
47+
# Need direct config access to revert any changes made by Tests
48+
global $config;
49+
4750
# Collect available environment variables
4851
$this->get_envs();
4952

@@ -61,7 +64,7 @@ class TestCase {
6164
# If this method starts with `test`, run the function.
6265
if (str_starts_with($method, 'test')) {
6366
# Backup the current config so we can undo any changes made during the test
64-
$original_config = config_get_path("");
67+
$original_config = unserialize(serialize($config));
6568

6669
# Set the current method undergoing testing
6770
$this->method = $method;
@@ -75,14 +78,14 @@ class TestCase {
7578
$this->$method();
7679
} catch (Error | Exception $e) {
7780
# Restore the original configuration, teardown the TestCase and throw the encountered error
78-
config_set_path("", $original_config);
81+
$config = $original_config;
7982
write_config("Restored config after API test '$method'");
8083
$this->teardown();
8184
throw $e;
8285
}
8386

8487
# Restore the config as it was when the test began.
85-
config_set_path("", $original_config);
88+
$config = $original_config;
8689
write_config("Restored config after API test '$method'");
8790
}
8891
}

0 commit comments

Comments
 (0)