Skip to content

Commit e229c43

Browse files
test: skip integrations without env vars
1 parent 32c3976 commit e229c43

11 files changed

Lines changed: 63 additions & 24 deletions

File tree

tests/Messaging/Adapter/Base.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ protected function assertResponse(array $response): void
4444
$this->assertEquals('', $response['results'][0]['error'], \var_export($response, true));
4545
$this->assertEquals('success', $response['results'][0]['status'], \var_export($response, true));
4646
}
47+
48+
/**
49+
* @param array<string> $variables
50+
*/
51+
protected function requireEnv(array $variables): void
52+
{
53+
foreach ($variables as $variable) {
54+
$value = \getenv($variable);
55+
56+
if ($value === false || $value === '') {
57+
$this->markTestSkipped('Missing required environment variable: '.$variable);
58+
}
59+
}
60+
}
4761
}

tests/Messaging/Adapter/Chat/DiscordTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
class DiscordTest extends Base
1111
{
12-
public function testSendMessage(): void
12+
public function test_send_message(): void
1313
{
14+
$this->requireEnv(['DISCORD_WEBHOOK_URL']);
15+
1416
$url = \getenv('DISCORD_WEBHOOK_URL');
1517

1618
$sender = new Discord($url);
@@ -45,13 +47,13 @@ public static function invalidURLProvider(): array
4547
/**
4648
* @dataProvider invalidURLProvider
4749
*/
48-
public function testInvalidURLs(string $invalidURL): void
50+
public function test_invalid_ur_ls(string $invalidURL): void
4951
{
5052
$this->expectException(InvalidArgumentException::class);
5153
new Discord($invalidURL);
5254
}
5355

54-
public function testValidURLVariations(): void
56+
public function test_valid_url_variations(): void
5557
{
5658
// Valid URL format variations
5759
$validURLs = [
@@ -66,12 +68,12 @@ public function testValidURLVariations(): void
6668
// If we get here, the URL was accepted
6769
$this->assertTrue(true, "Valid URL variant '{$label}' was accepted as expected");
6870
} catch (InvalidArgumentException $e) {
69-
$this->fail("Valid URL variant '{$label}' was rejected: " . $e->getMessage());
71+
$this->fail("Valid URL variant '{$label}' was rejected: ".$e->getMessage());
7072
}
7173
}
7274
}
7375

74-
public function testWebhookIDExtraction(): void
76+
public function test_webhook_id_extraction(): void
7577
{
7678
// Create a reflection of Discord to access protected properties
7779
$webhookId = '123456789012345678';

tests/Messaging/Adapter/Email/MailgunTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
class MailgunTest extends Base
1111
{
12-
public function testSendEmail(): void
12+
public function test_send_email(): void
1313
{
14+
$this->requireEnv(['MAILGUN_API_KEY', 'MAILGUN_DOMAIN', 'TEST_EMAIL', 'TEST_CC_EMAIL', 'TEST_BCC_EMAIL', 'TEST_BCC_NAME']);
15+
1416
$key = \getenv('MAILGUN_API_KEY');
1517
$domain = \getenv('MAILGUN_DOMAIN');
1618

@@ -42,8 +44,10 @@ public function testSendEmail(): void
4244
$this->assertResponse($response);
4345
}
4446

45-
public function testSendEmailWithAttachments(): void
47+
public function test_send_email_with_attachments(): void
4648
{
49+
$this->requireEnv(['MAILGUN_API_KEY', 'MAILGUN_DOMAIN', 'TEST_EMAIL']);
50+
4751
$key = \getenv('MAILGUN_API_KEY');
4852
$domain = \getenv('MAILGUN_DOMAIN');
4953

@@ -66,9 +70,9 @@ public function testSendEmailWithAttachments(): void
6670
fromEmail: $fromEmail,
6771
attachments: [new Attachment(
6872
name: 'image.png',
69-
path: __DIR__ . '/../../../assets/image.png',
73+
path: __DIR__.'/../../../assets/image.png',
7074
type: 'image/png'
71-
),],
75+
), ],
7276
);
7377

7478
$response = $sender->send($message);

tests/Messaging/Adapter/Email/ResendTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@
1010
class ResendTest extends Base
1111
{
1212
private Resend $sender;
13+
1314
private string $testEmail;
1415

1516
protected function setUp(): void
1617
{
1718
parent::setUp();
19+
$this->requireEnv(['RESEND_API_KEY', 'RESEND_TEST_EMAIL']);
20+
1821
$key = \getenv('RESEND_API_KEY');
1922
$this->sender = new Resend($key);
2023
$this->testEmail = \getenv('RESEND_TEST_EMAIL');
2124

2225
sleep(2);
2326
}
2427

25-
public function testSendEmail(): void
28+
public function test_send_email(): void
2629
{
2730
$to = $this->testEmail;
2831
$subject = 'Test Subject';
@@ -46,7 +49,7 @@ public function testSendEmail(): void
4649
$this->assertResponse($response);
4750
}
4851

49-
public function testSendEmailWithHtml(): void
52+
public function test_send_email_with_html(): void
5053
{
5154
$to = $this->testEmail;
5255
$subject = 'Test HTML Subject';
@@ -67,7 +70,7 @@ public function testSendEmailWithHtml(): void
6770
$this->assertResponse($response);
6871
}
6972

70-
public function testSendEmailWithReplyTo(): void
73+
public function test_send_email_with_reply_to(): void
7174
{
7275
$to = $this->testEmail;
7376
$subject = 'Test Reply-To Subject';
@@ -90,7 +93,7 @@ public function testSendEmailWithReplyTo(): void
9093
$this->assertResponse($response);
9194
}
9295

93-
public function testSendMultipleEmails(): void
96+
public function test_send_multiple_emails(): void
9497
{
9598
$to1 = $this->testEmail;
9699
$to2 = $this->testEmail;
@@ -115,7 +118,7 @@ public function testSendMultipleEmails(): void
115118
$this->assertEquals('success', $response['results'][1]['status'], \var_export($response, true));
116119
}
117120

118-
public function testSendEmailWithFileAttachment(): void
121+
public function test_send_email_with_file_attachment(): void
119122
{
120123
$message = new Email(
121124
to: [$this->testEmail],
@@ -135,7 +138,7 @@ public function testSendEmailWithFileAttachment(): void
135138
$this->assertResponse($response);
136139
}
137140

138-
public function testSendEmailWithStringAttachment(): void
141+
public function test_send_email_with_string_attachment(): void
139142
{
140143
$message = new Email(
141144
to: [$this->testEmail],
@@ -156,7 +159,7 @@ public function testSendEmailWithStringAttachment(): void
156159
$this->assertResponse($response);
157160
}
158161

159-
public function testSendEmailWithAttachmentExceedingMaxSize(): void
162+
public function test_send_email_with_attachment_exceeding_max_size(): void
160163
{
161164
$this->expectException(\Exception::class);
162165
$this->expectExceptionMessage('Total attachment size exceeds');

tests/Messaging/Adapter/Email/SendgridTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
class SendgridTest extends Base
1111
{
12-
public function testSendEmail(): void
12+
public function test_send_email(): void
1313
{
14+
$this->requireEnv(['SENDGRID_API_KEY', 'TEST_EMAIL', 'TEST_FROM_EMAIL', 'TEST_CC_EMAIL', 'TEST_BCC_EMAIL', 'TEST_BCC_NAME']);
15+
1416
$key = getenv('SENDGRID_API_KEY');
1517
$sender = new Sendgrid($key);
1618

@@ -36,8 +38,10 @@ public function testSendEmail(): void
3638
$this->assertResponse($response);
3739
}
3840

39-
public function testSendEmailWithAttachment(): void
41+
public function test_send_email_with_attachment(): void
4042
{
43+
$this->requireEnv(['SENDGRID_API_KEY', 'TEST_EMAIL', 'TEST_FROM_EMAIL']);
44+
4145
$key = \getenv('SENDGRID_API_KEY');
4246
$sender = new Sendgrid($key);
4347

@@ -54,7 +58,7 @@ public function testSendEmailWithAttachment(): void
5458
fromEmail: $fromEmail,
5559
attachments: [new Attachment(
5660
name: 'image.png',
57-
path: __DIR__ . '/../../../assets/image.png',
61+
path: __DIR__.'/../../../assets/image.png',
5862
type: 'image/png'
5963
)],
6064
);

tests/Messaging/Adapter/Push/APNSTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class APNSTest extends Base
99
protected function setUp(): void
1010
{
1111
parent::setUp();
12+
$this->requireEnv(['APNS_AUTHKEY_8KVVCLA3HL', 'APNS_AUTH_ID', 'APNS_TEAM_ID', 'APNS_BUNDLE_ID', 'APNS_TO']);
1213

1314
$authKey = \getenv('APNS_AUTHKEY_8KVVCLA3HL');
1415
$authKeyId = \getenv('APNS_AUTH_ID');

tests/Messaging/Adapter/Push/FCMTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FCMTest extends Base
99
protected function setUp(): void
1010
{
1111
parent::setUp();
12+
$this->requireEnv(['FCM_SERVICE_ACCOUNT_JSON', 'FCM_TO']);
1213

1314
$serverKey = \getenv('FCM_SERVICE_ACCOUNT_JSON');
1415

tests/Messaging/Adapter/SMS/Fast2SMSTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class Fast2SMSTest extends Base
1111
/**
1212
* Test Quick SMS route
1313
*/
14-
public function testQuickSMS(): void
14+
public function test_quick_sms(): void
1515
{
16+
$this->requireEnv(['FAST2SMS_API_KEY', 'FAST2SMS_TO']);
17+
1618
$sender = new Fast2SMS(
1719
apiKey: getenv('FAST2SMS_API_KEY'),
1820
useDLT: false
@@ -31,8 +33,10 @@ public function testQuickSMS(): void
3133
/**
3234
* Test DLT route
3335
*/
34-
public function testDLTSMS(): void
36+
public function test_dltsms(): void
3537
{
38+
$this->requireEnv(['FAST2SMS_API_KEY', 'FAST2SMS_SENDER_ID', 'FAST2SMS_MESSAGE_ID', 'FAST2SMS_TO']);
39+
3640
$sender = new Fast2SMS(
3741
apiKey: getenv('FAST2SMS_API_KEY'),
3842
senderId: getenv('FAST2SMS_SENDER_ID'),

tests/Messaging/Adapter/SMS/InforuTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class InforuTest extends Base
1111
/**
1212
* @throws \Exception
1313
*/
14-
public function testSendSMS(): void
14+
public function test_send_sms(): void
1515
{
16+
$this->requireEnv(['INFORU_SENDER_ID', 'INFORU_API_TOKEN']);
17+
1618
$sender = new Inforu(
1719
senderId: \getenv('INFORU_SENDER_ID'),
1820
apiToken: \getenv('INFORU_API_TOKEN'),

tests/Messaging/Adapter/SMS/Msg91Test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
class Msg91Test extends Base
1010
{
11-
public function testSendSMS(): void
11+
public function test_send_sms(): void
1212
{
13+
$this->requireEnv(['MSG_91_SENDER_ID', 'MSG_91_AUTH_KEY', 'MSG_91_TEMPLATE_ID', 'MSG_91_TO']);
14+
1315
$sender = new Msg91(getenv('MSG_91_SENDER_ID'), getenv('MSG_91_AUTH_KEY'), getenv('MSG_91_TEMPLATE_ID'));
1416

1517
$message = new SMS(

0 commit comments

Comments
 (0)