Skip to content

Commit 0689fab

Browse files
author
ace-n
committed
Properly check for env vars
1 parent c4250ed commit 0689fab

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

functions/slack_slash_command/test/DeployTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public function testFunction(
5050
$statusCode,
5151
$headers
5252
): void {
53-
$this->requireEnv('SLACK_SECRET');
54-
$this->requireEnv('KG_API_KEY');
55-
5653
$response = $this->client->request(
5754
$method,
5855
'',
@@ -70,11 +67,16 @@ public function testFunction(
7067
}
7168
}
7269

70+
/**
71+
* Deploy the Function.
72+
*
73+
* Overrides CloudFunctionLocalTestTrait::doDeploy().
74+
*/
7375
private static function doDeploy()
7476
{
75-
// Forward required env variables to Cloud Functions
76-
$envVars = 'SLACK_SECRET=' . getenv('SLACK_SECRET') . ',';
77-
$envVars .= 'KG_API_KEY=' . getenv('KG_API_KEY');
77+
// Forward required env variables to Cloud Functions.
78+
$envVars = 'SLACK_SECRET=' . self::requireEnv('SLACK_SECRET') . ',';
79+
$envVars .= 'KG_API_KEY=' . self::requireEnv('KG_API_KEY');
7880

7981
self::$fn->deploy(['--update-env-vars' => $envVars]);
8082
}

functions/slack_slash_command/test/IntegrationTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ class IntegrationTest extends TestCase
3434

3535
private static $entryPoint = 'receiveRequest';
3636

37+
/**
38+
* Run the PHP server locally for the defined function.
39+
*
40+
* Overrides CloudFunctionLocalTestTrait::doRun().
41+
*/
42+
private static function doRun()
43+
{
44+
self::$fn->run([
45+
'SLACK_SECRET' => self::requireEnv('SLACK_SECRET'),
46+
'KG_API_KEY' => self::requireEnv('KG_API_KEY'),
47+
]);
48+
}
49+
3750
/**
3851
* @dataProvider cases
3952
*/
@@ -45,9 +58,6 @@ public function testFunction(
4558
$statusCode,
4659
$headers
4760
): void {
48-
$this->requireEnv('SLACK_SECRET');
49-
$this->requireEnv('KG_API_KEY');
50-
5161
$response = $this->client->request(
5262
$method,
5363
'/',

0 commit comments

Comments
 (0)