-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
610a916
commit 7e06a2e
Showing
18 changed files
with
634 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Constant BrokeYourBike\\\\Twilio\\\\Enums\\\\CallerTypeEnum\\:\\:BUSINESS is unused\\.$#" | ||
count: 1 | ||
path: src/Enums/CallerTypeEnum.php | ||
|
||
- | ||
message: "#^Constant BrokeYourBike\\\\Twilio\\\\Enums\\\\CallerTypeEnum\\:\\:CONSUMER is unused\\.$#" | ||
count: 1 | ||
path: src/Enums/CallerTypeEnum.php | ||
|
||
- | ||
message: "#^Constant BrokeYourBike\\\\Twilio\\\\Enums\\\\CarrierTypeEnum\\:\\:LANDLINE is unused\\.$#" | ||
count: 1 | ||
path: src/Enums/CarrierTypeEnum.php | ||
|
||
- | ||
message: "#^Constant BrokeYourBike\\\\Twilio\\\\Enums\\\\CarrierTypeEnum\\:\\:MOBILE is unused\\.$#" | ||
count: 1 | ||
path: src/Enums/CarrierTypeEnum.php | ||
|
||
- | ||
message: "#^Constant BrokeYourBike\\\\Twilio\\\\Enums\\\\CarrierTypeEnum\\:\\:VOIP is unused\\.$#" | ||
count: 1 | ||
path: src/Enums/CarrierTypeEnum.php | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Twilio\Models; | ||
|
||
use Spatie\DataTransferObject\Attributes\MapFrom; | ||
use BrokeYourBike\Twilio\Models\Carrier; | ||
use BrokeYourBike\DataTransferObject\JsonResponse; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class PhoneNumberWithCarrierResponse extends JsonResponse | ||
{ | ||
public Carrier $carrier; | ||
|
||
#[MapFrom('country_code')] | ||
public string $countryCode; | ||
|
||
#[MapFrom('national_format')] | ||
public string $nationalFormat; | ||
|
||
#[MapFrom('phone_number')] | ||
public string $phoneNumber; | ||
|
||
public string $url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Twilio\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use BrokeYourBike\Twilio\V1\Client; | ||
use BrokeYourBike\Twilio\Interfaces\ConfigInterface; | ||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
use BrokeYourBike\HttpClient\HttpClientTrait; | ||
use BrokeYourBike\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class ClientTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_implemets_http_client_interface(): void | ||
{ | ||
/** @var ConfigInterface */ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
|
||
/** @var \GuzzleHttp\ClientInterface */ | ||
$mockedHttpClient = $this->getMockBuilder(\GuzzleHttp\ClientInterface::class)->getMock(); | ||
|
||
/** @var \Psr\SimpleCache\CacheInterface */ | ||
$mockedCache = $this->getMockBuilder(\Psr\SimpleCache\CacheInterface::class)->getMock(); | ||
|
||
$api = new Client($mockedConfig, $mockedHttpClient, $mockedCache); | ||
|
||
$this->assertInstanceOf(HttpClientInterface::class, $api); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_http_client_trait(): void | ||
{ | ||
$usedTraits = class_uses(Client::class); | ||
|
||
$this->assertArrayHasKey(HttpClientTrait::class, $usedTraits); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_resolve_uri_trait(): void | ||
{ | ||
$usedTraits = class_uses(Client::class); | ||
|
||
$this->assertArrayHasKey(ResolveUriTrait::class, $usedTraits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Twilio\Tests\Enums; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use BrokeYourBike\Twilio\Enums\CallerTypeEnum; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class CallerTypeEnumTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_extends_myclabs_enum(): void | ||
{ | ||
$parent = get_parent_class(CallerTypeEnum::class); | ||
|
||
$this->assertSame(\MyCLabs\Enum\Enum::class, $parent); | ||
} | ||
|
||
/** @test */ | ||
public function it_has_not_duplicate_values() | ||
{ | ||
$allValuesRaw = CallerTypeEnum::toArray(); | ||
$this->assertNotEmpty($allValuesRaw); | ||
|
||
$uniqueValuesraw = array_unique($allValuesRaw, SORT_STRING); | ||
|
||
$this->assertEquals($allValuesRaw, $uniqueValuesraw); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Twilio\Tests\Enums; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use BrokeYourBike\Twilio\Enums\CarrierTypeEnum; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class CarrierTypeEnumTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_extends_myclabs_enum(): void | ||
{ | ||
$parent = get_parent_class(CarrierTypeEnum::class); | ||
|
||
$this->assertSame(\MyCLabs\Enum\Enum::class, $parent); | ||
} | ||
|
||
/** @test */ | ||
public function it_has_not_duplicate_values() | ||
{ | ||
$allValuesRaw = CarrierTypeEnum::toArray(); | ||
$this->assertNotEmpty($allValuesRaw); | ||
|
||
$uniqueValuesraw = array_unique($allValuesRaw, SORT_STRING); | ||
|
||
$this->assertEquals($allValuesRaw, $uniqueValuesraw); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Twilio\Tests; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use BrokeYourBike\Twilio\V1\Client; | ||
use BrokeYourBike\Twilio\Interfaces\ConfigInterface; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class LookupPhoneNumberRawTest extends TestCase | ||
{ | ||
private string $sid = '12345'; | ||
private string $secret = 'super-secure-token'; | ||
private string $phone = '+123456789'; | ||
|
||
/** @test */ | ||
public function it_can_prepare_request(): void | ||
{ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
$mockedConfig->method('getUrl')->willReturn('https://api.example/'); | ||
$mockedConfig->method('getSid')->willReturn($this->sid); | ||
$mockedConfig->method('getSecret')->willReturn($this->secret); | ||
|
||
$mockedResponse = $this->getMockBuilder(ResponseInterface::class)->getMock(); | ||
$mockedResponse->method('getStatusCode')->willReturn(200); | ||
$mockedResponse->method('getBody') | ||
->willReturn('{ | ||
"url":"https://api.example/v1/PhoneNumbers/'. $this->phone .'" | ||
"caller_name":null, | ||
"country_code":"US", | ||
"phone_number":"'. $this->phone .'", | ||
"national_format":"012 345 6789", | ||
"add_ons":null | ||
}'); | ||
|
||
/** @var \Mockery\MockInterface $mockedClient */ | ||
$mockedClient = \Mockery::mock(\GuzzleHttp\Client::class); | ||
$mockedClient->shouldReceive('request')->withArgs([ | ||
'GET', | ||
'https://api.example/v1/PhoneNumbers/+123456789', | ||
[ | ||
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false, | ||
\GuzzleHttp\RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
], | ||
\GuzzleHttp\RequestOptions::AUTH => [ | ||
$this->sid, | ||
$this->secret, | ||
], | ||
\GuzzleHttp\RequestOptions::QUERY => [], | ||
], | ||
])->once()->andReturn($mockedResponse); | ||
|
||
/** | ||
* @var ConfigInterface $mockedConfig | ||
* @var \GuzzleHttp\Client $mockedClient | ||
* */ | ||
$api = new Client($mockedConfig, $mockedClient); | ||
|
||
$requestResult = $api->lookupPhoneNumberRaw($this->phone); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $requestResult); | ||
} | ||
} |
Oops, something went wrong.