2020namespace Google \Cloud \Samples \Functions \ImageMagick \Test ;
2121
2222use Google \Cloud \Storage \StorageClient ;
23- use Google \Cloud \Logging \LoggingClient ;
2423use Google \Cloud \TestUtils \CloudFunctionDeploymentTrait ;
2524use PHPUnit \Framework \TestCase ;
2625
@@ -40,31 +39,15 @@ class DeployTest extends TestCase
4039 use CloudFunctionDeploymentTrait;
4140 use TestCasesTrait;
4241
43- /** @var string */
44- private static $ entryPoint = 'blurOffensiveImages ' ;
45-
46- /** @var string */
47- private static $ functionSignatureType = 'cloudevent ' ;
48-
49- /** @var string */
50- // The test starts by copying images from this bucket.
42+ // The test uses this bucket to copy images.
5143 private const FIXTURE_SOURCE_BUCKET = 'cloud-devrel-public ' ;
5244
53- /** @var string */
54- // This is the bucket the deployed function monitors.
55- // The test copies image from FIXTURE_SOURCE_BUCKET to this one.
45+ /**
46+ * This is the bucket the deployed function monitors.
47+ * The test copies image from FIXTURE_SOURCE_BUCKET to this one.
48+ */
5649 private static $ monitoredBucket ;
5750
58- /** @var string */
59- // The function saves any blurred images to this bucket.
60- private static $ blurredBucket ;
61-
62- /** @var StorageClient */
63- private static $ storageClient ;
64-
65- /** @var LoggingClient */
66- private static $ loggingClient ;
67-
6851 /**
6952 * @dataProvider cases
7053 */
@@ -75,16 +58,13 @@ public function testFunction(
7558 $ expected ,
7659 $ statusCode
7760 ): void {
78- // Upload target file.
79- $ fixtureBucket = self :: $ storageClient -> bucket ( self :: FIXTURE_SOURCE_BUCKET );
80- $ object = $ fixtureBucket -> object ( $ fileName );
61+ // Trigger the cloud storage event by copying the image over
62+ $ storageClient = new StorageClient ( );
63+ $ fixtureBucket = $ storageClient -> bucket ( self :: FIXTURE_SOURCE_BUCKET );
8164
65+ $ object = $ fixtureBucket ->object ($ fileName );
8266 $ object ->copy (self ::$ monitoredBucket , ['name ' => $ fileName ]);
8367
84- // Give event and log systems a head start.
85- // If log retrieval fails to find logs for our function within retry limit, increase sleep time.
86- sleep (5 );
87-
8868 $ fiveMinAgo = date (\DateTime::RFC3339 , strtotime ('-5 minutes ' ));
8969 $ this ->processFunctionLogs ($ fiveMinAgo , function (\Iterator $ logs ) use ($ expected , $ label ) {
9070 // Concatenate all relevant log messages.
@@ -108,20 +88,11 @@ public function testFunction(
10888 private static function doDeploy ()
10989 {
11090 // Initialize variables
111- if (empty (self ::$ monitoredBucket )) {
112- self ::$ monitoredBucket = self ::requireEnv ('GOOGLE_STORAGE_BUCKET ' );
113- }
114- if (empty (self ::$ blurredBucket )) {
115- self ::$ blurredBucket = self ::requireEnv ('BLURRED_BUCKET_NAME ' );
116- }
117-
118- if (empty (self ::$ storageClient )) {
119- self ::$ storageClient = new StorageClient ();
120- }
91+ self ::$ monitoredBucket = self ::requireEnv ('GOOGLE_STORAGE_BUCKET ' );
92+ $ blurredBucket = self ::requireEnv ('BLURRED_BUCKET_NAME ' );
12193
12294 // Forward required env variables to Cloud Functions.
123- $ envVars = 'GOOGLE_STORAGE_BUCKET= ' . self ::$ monitoredBucket . ', ' ;
124- $ envVars .= 'BLURRED_BUCKET_NAME= ' . self ::$ blurredBucket ;
95+ $ envVars = sprintf ('BLURRED_BUCKET_NAME=%s ' , $ blurredBucket );
12596
12697 self ::$ fn ->deploy (
12798 ['--update-env-vars ' => $ envVars ],
0 commit comments