@@ -22,79 +22,83 @@ class securitycenterTest extends TestCase
2222{
2323 use TestTrait;
2424
25+ private static $ testNotificationCreate ;
26+ private static $ testNotificationGet ;
27+ private static $ testNotificationUpdate ;
28+
29+ public static function setUpBeforeClass ()
30+ {
31+ self ::$ testNotificationCreate = self ::randomNotificationId ();
32+ self ::$ testNotificationGet = self ::randomNotificationId ();
33+ self ::$ testNotificationUpdate = self ::randomNotificationId ();
34+ }
35+
36+ private function deleteConfig (string $ configId )
37+ {
38+ $ deleteOutput = $ this ->runSnippet ('delete_notification ' , [
39+ self ::getOrganizationId (),
40+ $ configId ,
41+ ]);
42+
43+ $ this ->assertContains ('Notification config was deleted ' , $ deleteOutput );
44+ }
45+
2546 public function testCreateNotification ()
2647 {
2748 $ createOutput = $ this ->runSnippet ('create_notification ' , [
2849 self ::getOrganizationId (),
29- " php-notification-config-create " ,
30- self ::getProject () ,
50+ self :: $ testNotificationCreate ,
51+ self ::$ projectId ,
3152 self ::getTopicName ()
3253 ]);
3354
3455 $ this ->assertContains ('Notification config was created ' , $ createOutput );
3556
36- $ deleteOutput = $ this ->runSnippet ('delete_notification ' , [
37- self ::getOrganizationId (),
38- "php-notification-config-create " ,
39- ]);
40-
41- $ this ->assertContains ('Notification config was deleted ' , $ deleteOutput );
57+ self ::deleteConfig (self ::$ testNotificationCreate );
4258 }
4359
4460 public function testGetNotificationConfig ()
4561 {
4662 $ createOutput = $ this ->runSnippet ('create_notification ' , [
4763 self ::getOrganizationId (),
48- " php-notification-config-get " ,
49- self ::getProject () ,
64+ self :: $ testNotificationGet ,
65+ self ::$ projectId ,
5066 self ::getTopicName ()
5167 ]);
5268
5369 $ this ->assertContains ('Notification config was created ' , $ createOutput );
5470
5571 $ getOutput = $ this ->runSnippet ('get_notification ' , [
5672 self ::getOrganizationId (),
57- " php-notification-config-get " ,
73+ self :: $ testNotificationGet
5874 ]);
5975
6076 $ this ->assertContains ('Notification config was retrieved ' , $ getOutput );
6177
62- $ deleteOutput = $ this ->runSnippet ('delete_notification ' , [
63- self ::getOrganizationId (),
64- "php-notification-config-get " ,
65- ]);
66-
67- $ this ->assertContains ('Notification config was deleted ' , $ deleteOutput );
68-
78+ self ::deleteConfig (self ::$ testNotificationGet );
6979 }
7080
7181 public function testUpdateNotificationConfig ()
7282 {
7383 $ createOutput = $ this ->runSnippet ('create_notification ' , [
7484 self ::getOrganizationId (),
75- " php-notification-config-update " ,
76- self ::getProject () ,
85+ self :: $ testNotificationUpdate ,
86+ self ::$ projectId ,
7787 self ::getTopicName ()
7888 ]);
7989
8090 $ this ->assertContains ('Notification config was created ' , $ createOutput );
8191
8292 $ getOutput = $ this ->runSnippet ('update_notification ' , [
8393 self ::getOrganizationId (),
84- " php-notification-config-update " ,
85- self ::getProject () ,
94+ self :: $ testNotificationUpdate ,
95+ self ::$ projectId ,
8696 self ::getTopicName ()
8797 ]);
8898
8999 $ this ->assertContains ('Notification config was updated ' , $ getOutput );
90100
91- $ deleteOutput = $ this ->runSnippet ('delete_notification ' , [
92- self ::getOrganizationId (),
93- "php-notification-config-update " ,
94- ]);
95-
96- $ this ->assertContains ('Notification config was deleted ' , $ deleteOutput );
97-
101+ self ::deleteConfig (self ::$ testNotificationUpdate );
98102 }
99103
100104 public function testListNotificationConfig ()
@@ -104,18 +108,20 @@ public function testListNotificationConfig()
104108 ]);
105109
106110 $ this ->assertContains ('Notification configs were listed ' , $ listOutput );
107-
108111 }
109112
110- private static function getOrganizationId () {
111- return "1081635000895 " ;
113+ private static function getOrganizationId ()
114+ {
115+ return self ::requireEnv ('GOOGLE_ORGANIZATION_ID ' );
112116 }
113117
114- private static function getProject () {
115- return "project-a-id " ;
118+ private static function getTopicName ()
119+ {
120+ return self ::requireEnv ('GOOGLE_TOPIC_ID ' );
116121 }
117122
118- private static function getTopicName () {
119- return "notifications-sample-topic " ;
123+ private static function randomNotificationId ()
124+ {
125+ return uniqid ('php-notification-config- ' );
120126 }
121127}
0 commit comments