Skip to content

Commit 7a65f41

Browse files
ConorEdwardsCPgibiw
authored andcommitted
Fix boolean parsing for environment variables
1 parent 8b66b17 commit 7a65f41

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

src/Config/ConfigLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function overrideWithEnvVariables(): void
131131
$this->config->setRootSuite($value);
132132
break;
133133
case "qase_debug":
134-
$this->config->setDebug($value);
134+
$this->config->setDebug(filter_var($value, FILTER_VALIDATE_BOOLEAN));
135135
break;
136136
case "qase_logging_console":
137137
$this->parseLoggingConsole($value);
@@ -146,7 +146,7 @@ private function overrideWithEnvVariables(): void
146146
$this->config->testops->setProject($value);
147147
break;
148148
case "qase_testops_defect":
149-
$this->config->testops->setDefect($value);
149+
$this->config->testops->setDefect(filter_var($value, FILTER_VALIDATE_BOOLEAN));
150150
break;
151151
case "qase_testops_show_public_report_link":
152152
$this->config->testops->setShowPublicReportLink(filter_var($value, FILTER_VALIDATE_BOOLEAN));
@@ -167,7 +167,7 @@ private function overrideWithEnvVariables(): void
167167
$this->config->testops->run->setDescription($value);
168168
break;
169169
case "qase_testops_run_complete":
170-
$this->config->testops->run->setComplete($value);
170+
$this->config->testops->run->setComplete(filter_var($value, FILTER_VALIDATE_BOOLEAN));
171171
break;
172172
case "qase_testops_run_tags":
173173
$this->config->testops->run->setTags(array_map('trim', explode(',', $value)));
@@ -188,7 +188,7 @@ private function overrideWithEnvVariables(): void
188188
$this->parseConfigurationValues($value);
189189
break;
190190
case "qase_testops_configurations_create_if_not_exists":
191-
$this->config->testops->configurations->setCreateIfNotExists($value);
191+
$this->config->testops->configurations->setCreateIfNotExists(filter_var($value, FILTER_VALIDATE_BOOLEAN));
192192
break;
193193
case "qase_testops_status_filter":
194194
$this->parseStatusFilter($value);

tests/ConfigLoaderTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,84 @@ public function testStatusFilterFromEnvEmpty(): void
155155
// Clean up
156156
putenv('QASE_TESTOPS_STATUS_FILTER');
157157
}
158+
159+
/**
160+
* @dataProvider booleanProvider
161+
*/
162+
public function testDebugFromEnv(bool $expected): void
163+
{
164+
// Set environment variable with spaces
165+
putenv("QASE_DEBUG=$expected");
166+
167+
$configLoader = new ConfigLoader($this->logger);
168+
$config = $configLoader->getConfig();
169+
170+
$debug = $config->getDebug();
171+
$this->assertEquals($expected, $debug);
172+
173+
// Clean up
174+
putenv('QASE_DEBUG');
175+
}
176+
177+
/**
178+
* @dataProvider booleanProvider
179+
*/
180+
public function testDefectFromEnv(bool $expected): void
181+
{
182+
// Set environment variable with spaces
183+
putenv("QASE_TESTOPS_DEFECT=$expected");
184+
185+
$configLoader = new ConfigLoader($this->logger);
186+
$config = $configLoader->getConfig();
187+
188+
$isDefect = $config->testops->isDefect();
189+
$this->assertEquals($expected, $isDefect);
190+
191+
// Clean up
192+
putenv('QASE_TESTOPS_DEFECT');
193+
}
194+
195+
/**
196+
* @dataProvider booleanProvider
197+
*/
198+
public function testRunCompleteFromEnv(bool $expected): void
199+
{
200+
// Set environment variable with spaces
201+
putenv("QASE_TESTOPS_RUN_COMPLETE=$expected");
202+
203+
$configLoader = new ConfigLoader($this->logger);
204+
$config = $configLoader->getConfig();
205+
206+
$isComplete = $config->testops->run->isComplete();
207+
$this->assertEquals($expected, $isComplete);
208+
209+
// Clean up
210+
putenv('QASE_TESTOPS_RUN_COMPLETE');
211+
}
212+
213+
/**
214+
* @dataProvider booleanProvider
215+
*/
216+
public function testCreateConfigurationsIfNotExistFromEnv(bool $expected): void
217+
{
218+
// Set environment variable with spaces
219+
putenv("QASE_TESTOPS_CONFIGURATIONS_CREATE_IF_NOT_EXISTS=$expected");
220+
221+
$configLoader = new ConfigLoader($this->logger);
222+
$config = $configLoader->getConfig();
223+
224+
$isCreateIfNotExists = $config->testops->configurations->isCreateIfNotExists();
225+
$this->assertEquals($expected, $isCreateIfNotExists);
226+
227+
// Clean up
228+
putenv('QASE_TESTOPS_CONFIGURATIONS_CREATE_IF_NOT_EXISTS');
229+
}
230+
231+
public static function booleanProvider(): array
232+
{
233+
return [
234+
[true],
235+
[false],
236+
];
237+
}
158238
}

0 commit comments

Comments
 (0)