Skip to content

Commit 37a3ac0

Browse files
author
ace-n
committed
Address comments
1 parent 7b0c624 commit 37a3ac0

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

functions/slack_slash_command/index.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
*/
2929
function isValidSlackWebhook(ServerRequestInterface $request): bool
3030
{
31-
/**
32-
* Unlike most other Cloud Functions languages, PHP does not preserve
33-
* global values between requests. Since we don't use this value elsewhere
34-
* in the sample, it's easiest to declare it within this method itself.
35-
*/
3631
$SLACK_SECRET = getenv('SLACK_SECRET');
3732

3833
// Check for headers
@@ -108,11 +103,6 @@ function formatSlackMessage(Google_Service_Kgsearch_SearchResponse $kgResponse,
108103
*/
109104
function searchKnowledgeGraph(string $query): Google_Service_Kgsearch_SearchResponse
110105
{
111-
/**
112-
* Unlike most other Cloud Functions languages, PHP does not preserve
113-
* global values between requests. Since we don't use this value elsewhere
114-
* in the sample, it's easiest to declare it within this method itself.
115-
*/
116106
$API_KEY = getenv("KG_API_KEY");
117107

118108
$apiClient = new Google\Client();

functions/slack_slash_command/test/DeployTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DeployTest extends TestCase
3737
use CloudFunctionDeploymentTrait;
3838
use TestCasesTrait;
3939

40-
private static $name = 'receiveRequest';
40+
private static $entryPoint = 'receiveRequest';
4141

4242
/**
4343
* @dataProvider cases
@@ -50,6 +50,9 @@ public function testFunction(
5050
$statusCode,
5151
$headers
5252
): void {
53+
$this->requireEnv('SLACK_SECRET');
54+
$this->requireEnv('KG_API_KEY');
55+
5356
$response = $this->client->request(
5457
$method,
5558
'',
@@ -67,13 +70,12 @@ public function testFunction(
6770
}
6871
}
6972

70-
protected static function deployFlags(array $flags = []): array
73+
private static function doDeploy()
7174
{
7275
// Forward required env variables to Cloud Functions
7376
$envVars = 'SLACK_SECRET=' . getenv('SLACK_SECRET') . ',';
7477
$envVars .= 'KG_API_KEY=' . getenv('KG_API_KEY');
7578

76-
$flags['--update-env-vars'] = '"' . $envVars . '"';
77-
return $flags;
79+
self::$fn->deploy(['--update-env-vars' => $envVars]);
7880
}
7981
}

functions/slack_slash_command/test/LocalTest.php renamed to functions/slack_slash_command/test/IntegrationTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
require_once __DIR__ . '/TestCasesTrait.php';
2626

2727
/**
28-
* Class SystemTest.
28+
* Class IntegrationTest.
2929
*/
30-
class SystemTest extends TestCase
30+
class IntegrationTest extends TestCase
3131
{
3232
use CloudFunctionLocalTestTrait;
3333
use TestCasesTrait;
3434

35-
private static $name = 'receiveRequest';
35+
private static $entryPoint = 'receiveRequest';
3636

3737
/**
3838
* @dataProvider cases
@@ -45,6 +45,9 @@ public function testFunction(
4545
$statusCode,
4646
$headers
4747
): void {
48+
$this->requireEnv('SLACK_SECRET');
49+
$this->requireEnv('KG_API_KEY');
50+
4851
$response = $this->client->request(
4952
$method,
5053
'/',

functions/slack_slash_command/test/TestCasesTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
function _valid_headers($body): array
2222
{
23-
2423
// Calculate test case signature
2524
$key = getenv('SLACK_SECRET');
2625
$plaintext = 'v0:0:' . $body;

functions/slack_slash_command/test/UnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class UnitTest extends TestCase
3030
{
3131
use TestCasesTrait;
3232

33-
private static $name = 'receiveRequest';
33+
private static $entryPoint = 'receiveRequest';
3434

3535
public static function setUpBeforeClass(): void
3636
{
@@ -49,7 +49,7 @@ public function testFunction(
4949
$headers
5050
): void {
5151
$request = new ServerRequest($method, '/', $headers, $body);
52-
$response = $this->runFunction(self::$name, [$request]);
52+
$response = $this->runFunction(self::$entryPoint, [$request]);
5353

5454
$this->assertEquals(
5555
$statusCode,

0 commit comments

Comments
 (0)