Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions src/Twilio/Base/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function __construct(
$this->edge = $this->getArg(null, self::ENV_EDGE);
$this->logLevel = $this->getArg(null, self::ENV_LOG);
$this->userAgentExtensions = $userAgentExtensions ?: [];

$this->invalidateOAuth();
$this->setAccountSid($accountSid ?: $this->username);

Expand Down Expand Up @@ -161,30 +162,6 @@ public function request(
$authStrategy = $this->credentialProvider->toAuthStrategy();
}

if( ($this->edge === null && $this->region !== null) || ($this->edge !== null && $this->region === null) )
{
trigger_error(' For regional processing, DNS is of format product.city.region.twilio.com; otherwise use product.twilio.com.', E_USER_DEPRECATED);
}
if ($this->edge === null && $this->region !== null) {
$regionMap = [
'au1' => 'sydney',
'br1' => 'sao-paulo',
'de1' => 'frankfurt',
'ie1' => 'dublin',
'jp1' => 'tokyo',
'jp2' => 'osaka',
'sg1' => 'singapore',
'us1' => 'ashburn',
'us2' => 'umatilla'
];
if (array_key_exists($this->region, $regionMap)) {
trigger_error(' Setting default `Edge` for the provided `region`.', E_USER_DEPRECATED);
$this->edge = $regionMap[$this->region];
}
if( $this->edge === null )
$this->edge = '';
}

if (!$authStrategy) {
if (!$username) {
throw new ConfigurationException('username is required');
Expand Down
39 changes: 1 addition & 38 deletions tests/Twilio/Unit/Rest/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public function testRegionInjectedWhenSet(): void {
$network = new Holodeck();
$client = new Client('username', 'password', null, 'ie1', $network);
$client->request('POST', 'https://test.twilio.com/v1/Resources');
// $this->expectException();
$expected = new Request('POST', 'https://test.dublin.ie1.twilio.com/v1/Resources');
$expected = new Request('POST', 'https://test.ie1.twilio.com/v1/Resources');
$this->assertTrue($network->hasRequest($expected));
}

Expand Down Expand Up @@ -283,40 +282,4 @@ public function testUserAgentExtensionsWhenSet(): void {
$this->assertEquals($userAgentExtensions,$expectedExtensions);
}


public function testEdgeIsSetFromRegionWhenEdgeIsNull(): void {
$client = new Client('username', 'password', null, 'au1');
$client->request('GET', 'https://api.twilio.com');
$this->assertEquals('sydney', $client->getEdge());
}

public function testEdgeIsSetFromRegionWhenRegionIsXyz(): void {
// Create a mock of the CurlClient
$mockHttpClient = $this->createMock(CurlClient::class);

// Define the expected behavior
$mockHttpClient->expects($this->once())
->method('request')
->with('GET', 'https://api.xyz.twilio.com', [], [])
->willReturn(new Response(200, 'Mocked response'));
$client = new Client('username', 'password', null, 'xyz');
$client->setHttpClient($mockHttpClient);
$client->request('GET', 'https://api.twilio.com');
$this->assertEquals('',$client->getEdge());
$this->assertEquals('xyz', $client->getRegion());
}

public function testEdgeRemainsWhenBothEdgeAndRegionAreSet(): void {
$client = new Client('username', 'password', null, 'au1');
$client->request('GET', 'https://api.twilio.com');
$client->setEdge('custom-edge');
$this->assertEquals('custom-edge', $client->getEdge());
}

public function testEdgeRemainsWhenBothEdgeAndRegionAreSetInConstructor(): void {
$client = new Client('username', 'password', null, 'au1', null, ['TWILIO_EDGE' => 'custom-edge']);
$this->assertEquals('custom-edge', $client->getEdge());
$this->assertEquals('au1', $client->getRegion());

}
}
Loading