Skip to content

Commit 4228264

Browse files
committed
tests: comments added, field names changed.
1 parent f1d036f commit 4228264

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/CloudFunctions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use GuzzleHttp\Psr7\Utils;
77
use Psr\Http\Message\ResponseInterface;
88
use Psr\Http\Message\ServerRequestInterface;
9-
use stdClass;
109

1110
/**
1211
* Class CloudFunctions.

tests/SimpleTestCase.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,60 @@
88

99
/**
1010
* Class Simple TestCase.
11-
* It depends on the <code>gcloud</code> command to obtain the project ID.
1211
*
1312
* @author Martin Zeitler
1413
* @version 1.0.0
1514
*/
1615
class SimpleTestCase extends TestCase {
1716

1817
private static string $project_id;
19-
private static string $test_topic;
20-
private static string $test_bucket;
18+
private static array $json_data;
19+
private static string $pubsub_topic;
20+
private static string $gcs_bucket;
2121

2222
public static function setUpBeforeClass(): void {
2323
require_once __DIR__.'/../index.php';
24-
self::$project_id = self::get_project_id();
25-
self::$test_topic = 'play-notifications';
26-
self::$test_bucket = 'gs://php-cloudfunctions';
24+
self::$project_id = self::get_project_id();
25+
self::$json_data = ['data' => uniqid()];
26+
self::$pubsub_topic = 'play-notifications';
27+
self::$gcs_bucket = 'gs://php-cloudfunctions';
2728
}
28-
29+
30+
/** It depends on the <code>gcloud</code> command to obtain the project ID. */
2931
private static function get_project_id(): string {
3032
$stdout = shell_exec('gcloud config get-value project');
3133
if ($stdout == null) {return 'unknown';}
3234
else {return $stdout;}
3335
}
3436

37+
/** Test: On HTTPS */
3538
public function test_on_https(): void {
36-
$payload = json_encode(['data' => uniqid()]);
39+
$payload = json_encode(self::$json_data);
3740
$request = new ServerRequest('POST', '/', [], $payload);
3841
$response = CloudFunctions::on_https( $request );
3942
// $this->assertTrue($response->getReasonPhrase().equals("OK"));
4043
$this->assertTrue($response->getStatusCode() == 200);
4144
}
4245

46+
/** Test: On Pub/Sub Event */
4347
public function test_on_pubsub(): void {
4448
CloudFunctions::on_pubsub(new CloudEventImmutable(
4549
uniqId(), // id
46-
'//pubsub.googleapis.com/projects/'.self::$project_id.'/topics/'.self::$test_topic, // source
50+
'//pubsub.googleapis.com/projects/'.self::$project_id.'/topics/'.self::$pubsub_topic, // source
4751
'google.cloud.pubsub.topic.v1.messagePublished', // type
4852
['data' => base64_encode('Test')], // data
4953
'application/json' // data content-type
5054
));
5155
self::assertTrue( true );
5256
}
5357

58+
/** Test: On GCS Event */
5459
public function test_on_gcs(): void {
5560
CloudFunctions::on_gcs(new CloudEventImmutable(
5661
uniqId(), // id
5762
'pubsub.googleapis.com', // source
5863
'google.storage.object.finalize', [ // type
59-
'bucket' => self::$test_bucket,
64+
'bucket' => self::$gcs_bucket,
6065
'name' => 'test.json',
6166
'metageneration' => '',
6267
'timeCreated' => time(),

0 commit comments

Comments
 (0)