2222use Google\Cloud\TestUtils\ExecuteCommandTrait;
2323use Google\Cloud\TestUtils\TestTrait;
2424use PHPUnit\Framework\TestCase;
25+ use PHPUnitRetry\RetryTrait;
2526
2627class alertsTest extends TestCase
2728{
2829 use ExecuteCommandTrait;
2930 use TestTrait;
31+ use RetryTrait;
3032
3133 private static $commandFile = __DIR__ . '/../alerts.php';
3234 private static $policyId;
@@ -43,9 +45,17 @@ public function testCreatePolicy()
4345 self::$policyId = $matches[1];
4446 }
4547
48+ /**
49+ * @depends testCreatePolicy
50+ * @retryAttempts 2
51+ * @retryDelaySeconds 10
52+ */
4653 public function testEnablePolicies()
4754 {
48- $policyName = AlertPolicyServiceClient::alertPolicyName(self::$projectId, self::$policyId);
55+ $policyName = AlertPolicyServiceClient::alertPolicyName(
56+ self::$projectId,
57+ self::$policyId
58+ );
4959 $output = $this->runAlertCommand('enable-policies', [
5060 'filter' => sprintf('name = "%s"', $policyName),
5161 'enable' => true,
@@ -54,13 +64,25 @@ public function testEnablePolicies()
5464 sprintf('Policy %s is already enabled', $policyName),
5565 $output
5666 );
67+ }
5768
69+ /**
70+ * @depends testEnablePolicies
71+ */
72+ public function testDisablePolicies()
73+ {
74+ $policyName = AlertPolicyServiceClient::alertPolicyName(
75+ self::$projectId,
76+ self::$policyId
77+ );
5878 $output = $this->runAlertCommand('enable-policies', [
5979 'filter' => sprintf('name = "%s"', $policyName),
6080 'enable' => false,
6181 ]);
62-
63- $this->assertStringContainsString(sprintf('Disabled %s', $policyName), $output);
82+ $this->assertStringContainsString(
83+ sprintf('Disabled %s', $policyName),
84+ $output
85+ );
6486 }
6587
6688 /** @depends testCreatePolicy */
@@ -148,10 +170,11 @@ public function testListChannels()
148170 $this->assertStringContainsString(self::$channelId, $output);
149171 }
150172
151- /** @depends testCreateChannel */
152- public function testBackupAndRestore()
173+ /**
174+ * @depends testCreateChannel
175+ */
176+ public function testBackupPolicies()
153177 {
154- // backup
155178 $output = $this->runAlertCommand('backup-policies');
156179 $this->assertStringContainsString('Backed up alert policies', $output);
157180
@@ -163,8 +186,15 @@ public function testBackupAndRestore()
163186 $this->assertGreaterThan(0, count($backup['channels']));
164187 $this->assertStringContainsString(self::$policyId, $backupJson);
165188 $this->assertStringContainsString(self::$channelId, $backupJson);
189+ }
166190
167- // restore
191+ /**
192+ * @depends testBackupPolicies
193+ * @retryAttempts 2
194+ * @retryDelaySeconds 10
195+ */
196+ public function testRestorePolicies()
197+ {
168198 $output = $this->runAlertCommand('restore-policies');
169199 $this->assertStringContainsString('Restored alert policies', $output);
170200 }
0 commit comments