Skip to content

Commit

Permalink
Merge pull request #102 from Bandwidth/SWI-1859
Browse files Browse the repository at this point in the history
SWI-1859 Get Tests Running in CI/CD
  • Loading branch information
ajrice6713 authored Jul 19, 2024
2 parents db1c916 + 7b48f64 commit 8dbedbe
Show file tree
Hide file tree
Showing 27 changed files with 158 additions and 59 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test

on:
schedule:
- cron: "0 4 * * *"
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-22.04]
php-version: [8.0, 8.1, 8.2, 8.3]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install Packages
run: composer install

- name: Test
run: ./vendor/bin/phpunit tests

- uses: Bandwidth/build-notify-slack-action@v1.0.0
if: failure() && !github.event.pull_request.draft
with:
job-status: ${{ job.status }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ secrets.SLACK_CHANNEL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ config.php
composer.lock
.idea/
.DS_Store
.phpunit.result.cache
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ PHP Client library for Bandwidth's Phone Number Dashboard (AKA: Dashboard, Iris)

## Supported PHP Versions

| Version | Support Level |
|:-------------------------------|:-------------------------|
| 5.5 | Unsupported |
| 5.6 | Unsupported |
| 7.0 | Unsupported |
| 7.1 | Unsupported |
| 7.2 | Supported |
| 7.3 | Supported |
| Version | Support Level |
|:--------|:-------------------------|
| 8.0 | Supported |
| 8.1 | Supported |
| 8.2 | Supported |
| 8.3 | Supported |

## Install

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"guzzlehttp/guzzle": "~7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.7"
},
"config": {
"bin-dir": "bin"
"phpunit/phpunit": "^9"
},
"autoload": {
"psr-4": {
"BandwidthLib\\": "src/"
},
"classmap": [
"src/",
"core/"
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="SDK Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 7 additions & 7 deletions src/DisconnectsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getList($filters = Array())
}

public function disconnect($id, $tndetail = false) {
$d = new Disconnect($this, array("orderId" => $id));
$d = new Disconnect($this, array("OrderId" => $id));
$d->get($tndetail);
return $d;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ class Disconnect extends RestEntry {
"CountOfTNs" => [ "type" => "string" ],
"userId" => [ "type" => "string" ],
"lastModifiedDate" => [ "type" => "string" ],
"orderId" => [ "type" => "string" ],
"OrderId" => [ "type" => "string" ],
"OrderType" => [ "type" => "string" ],
"OrderDate" => [ "type" => "string" ],
"OrderStatus" => [ "type" => "string" ],
Expand Down Expand Up @@ -114,20 +114,20 @@ public function save() {
$data = parent::post(null, "DisconnectTelephoneNumberOrder", $this->to_array());
$this->OrderStatus = new OrderRequestStatus($data);
if(isset($this->OrderStatus->orderRequest)) {
$this->orderId = $this->OrderStatus->orderRequest->id;
$this->OrderId = $this->OrderStatus->orderRequest->id;
$this->set_data($this->OrderStatus->orderRequest->to_array());
}
}

/**
* Get Entity Id
* @return type
* @throws Exception in case of orderId is null
* @throws Exception in case of OrderId is null
*/
private function get_id() {
if(!isset($this->orderId))
throw new \Exception("You can't use this function without orderId");
return $this->orderId;
if(!isset($this->OrderId))
throw new \Exception("You can't use this function without OrderId");
return $this->OrderId;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Middleware;

class AccountTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class AccountTest extends TestCase {
public static $container;
public static $account;
public static $index = 0;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
$mock = new MockHandler([
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <LineOptionOrderResponse><LineOptions> <CompletedNumbers><TelephoneNumber>2013223685</TelephoneNumber> </CompletedNumbers><Errors><Error><TelephoneNumber>5209072452</TelephoneNumber> <ErrorCode>5071</ErrorCode><Description>Telephone number is not available on the system.</Description></Error> <Error><TelephoneNumber>5209072451</TelephoneNumber> <ErrorCode>13518</ErrorCode><Description>CNAM for telephone number is applied at the Location level and it is notapplicable at the TN level.</Description> </Error></Errors> </LineOptions></LineOptionOrderResponse>"),
new Response(200, [], "<?xml version=\"1.0\"?> <SearchResult><ResultCount>1</ResultCount> <TelephoneNumberDetailList><TelephoneNumberDetail> <City>KNIGHTDALE</City> <LATA>426</LATA> <RateCenter>KNIGHTDALE</RateCenter> <State>NC</State> <FullNumber>9192956932</FullNumber> <Tier>0</Tier><VendorId>49</VendorId> <VendorName>Bandwidth CLEC</VendorName></TelephoneNumberDetail> </TelephoneNumberDetailList></SearchResult>"),
Expand Down Expand Up @@ -74,6 +76,8 @@ public static function setUpBeforeClass() {

$client = new Iris\Client("test", "test", Array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
self::$account = new Iris\Account(9500249, $client);

return;
}

public function testLineOption() {
Expand Down Expand Up @@ -124,6 +128,7 @@ public function testAvailableNumbers2() {
* @expectedExceptionCode 4000
*/
public function testAvailableNumbersError() {
$this->expectException(Iris\ResponseException::class);
$response = self::$account->availableNumbers();

$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
Expand Down
9 changes: 6 additions & 3 deletions tests/BadCredsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Middleware;

class BadCredsTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class BadCredsTest extends TestCase {
public static $container;
public static $client;
public static $index = 0;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
$mock = new MockHandler([
new Response(401, [], ""),
]);
Expand All @@ -19,7 +21,7 @@ public static function setUpBeforeClass() {
$handler = HandlerStack::create($mock);
$handler->push($history);

self::$client = new Iris\Client("test", "test", Array('url' => 'https://test.dashboard.bandwidth.com/', 'handler' => $handler));
self::$client = new Iris\Client("test", "test", Array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
}

/**
Expand All @@ -28,6 +30,7 @@ public static function setUpBeforeClass() {
* @expectedExceptionCode 401
*/
public function testAuthFail() {
$this->expectException(Iris\ResponseException::class);
$c = new \Iris\Cities(self::$client);
try {
$cities = $c->getList(["state" => "NC"]);
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseModelTest.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?phpclass Model { use \Iris\BaseModel; protected $fields = array( "Id" => array("type" => "string"), "Status" => array("type" => "\Iris\Status") ); public function __construct($data) { $this->set_data($data); }}class ArrModel { use \Iris\BaseModel; protected $fields = array( "Item" => array("type" => "ItemModel") ); public function __construct($data) { $this->set_data($data); }}class ItemModel { use \Iris\BaseModel; protected $fields = array( "Phone" => array("type" => "string") ); public function __construct($data) { $this->set_data($data); }}class BaseModelTest extends PHPUnit_Framework_TestCase { public function setUp() { } public function testContent() { $this->model = new Model(array("Id" => "123", "Status" => array("Code" => "0", "Description" => "Empty"))); $this->assertEquals("123", $this->model->Id); $this->assertEquals("0", $this->model->Status->Code); $this->model->set_data(array("Id" => "222", "Status" => array("Code" => "200", "Description" => "Hello"))); $this->assertEquals("222", $this->model->Id); $this->assertEquals("200", $this->model->Status->Code); } public function testArray() { $this->arrModel = new ArrModel(["Item" => [ ["Phone" => "1"], ["Phone" => "2"] ]]); $this->assertEquals("1", $this->arrModel->Item[0]->Phone); $arr = $this->arrModel->to_array(); $this->assertEquals("1", $arr["Item"][0]["Phone"]); }}
<?phpuse PHPUnit\Framework\TestCase;class Model { use \Iris\BaseModel; protected $fields = array( "Id" => array("type" => "string"), "Status" => array("type" => "\Iris\Status") ); public function __construct($data) { $this->set_data($data); }}class ArrModel { use \Iris\BaseModel; protected $fields = array( "Item" => array("type" => "ItemModel") ); public function __construct($data) { $this->set_data($data); }}class ItemModel { use \Iris\BaseModel; protected $fields = array( "Phone" => array("type" => "string") ); public function __construct($data) { $this->set_data($data); }}class BaseModelTest extends TestCase { public function setUp(): void { } public function testContent() { $this->model = new Model(array("Id" => "123", "Status" => array("Code" => "0", "Description" => "Empty"))); $this->assertEquals("123", $this->model->Id); $this->assertEquals("0", $this->model->Status->Code); $this->model->set_data(array("Id" => "222", "Status" => array("Code" => "200", "Description" => "Hello"))); $this->assertEquals("222", $this->model->Id); $this->assertEquals("200", $this->model->Status->Code); } public function testArray() { $this->arrModel = new ArrModel(["Item" => [ ["Phone" => "1"], ["Phone" => "2"] ]]); $this->assertEquals("1", $this->arrModel->Item[0]->Phone); $arr = $this->arrModel->to_array(); $this->assertEquals("1", $arr["Item"][0]["Phone"]); }}
Expand Down
6 changes: 4 additions & 2 deletions tests/CoveredRateCentersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Middleware;

class CoveredRateCenterTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class CoveredRateCenterTest extends TestCase {
public static $container;
public static $rcs;
public static $index = 0;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
$mock = new MockHandler([
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <CoveredRateCenters><TotalCount>18</TotalCount> <Links><first>Link=&lt;https://dashboard.bandwidth.com/api/coveredRateCenters?npa=310&amp;size=10&amp;e mbed=Cities&amp;embed=ZipCodes&amp;embed=NpaNxxX&amp;page=1&gt;;rel=\"first\";</first><next>Link=&lt;https://dashboard.bandwidth.com/api/coveredRateCenters?npa=310&amp;size=10&amp;e mbed=Cities&amp;embed=ZipCodes&amp;embed=NpaNxxX&amp; page=5&gt;;rel=\"next\";</next></Links> <CoveredRateCenter><Name>AVALON</Name><Abbreviation>AVALON</Abbreviation> <State>CA</State><Lata>730</Lata> <AvailableNumberCount>1</AvailableNumberCount> <ZipCodes><ZipCode>90731</ZipCode> </ZipCodes><Cities><City>SAN PEDRO</City> </Cities><Tiers> <Tier>0</Tier></Tiers> <NpaNxxXs><NpaNxxX>3105100</NpaNxxX> <NpaNxxX>3105101</NpaNxxX> <NpaNxxX>3109498</NpaNxxX> <NpaNxxX>3109499</NpaNxxX> <NpaNxxX>4242260</NpaNxxX></NpaNxxXs><Id>1</Id> </CoveredRateCenter> <CoveredRateCenter><Name>BEVERLY HILLS</Name> <Abbreviation>BEVERLYHLS</Abbreviation> <State>CA</State><Lata>730</Lata><AvailableNumberCount>25</AvailableNumberCount> <ZipCodes><ZipCode>90013</ZipCode> <ZipCode>90014</ZipCode> <ZipCode>90015</ZipCode><ZipCode>91504</ZipCode><ZipCode>91505</ZipCode> </ZipCodes><Cities><City>BEVERLY HILLS</City> <City>BURBANK</City> <City>GARDENA</City> <City>LOS ANGELES</City> <City>SHERMAN OAKS</City> <City>SUN VALLEY</City> <City>VAN NUYS</City></Cities> <Tiers><Tier>0</Tier> </Tiers><NpaNxxXs> <NpaNxxX>3102010</NpaNxxX><NpaNxxX>3102011</NpaNxxX><NpaNxxX>3102012</NpaNxxX><NpaNxxX>4247777</NpaNxxX> <NpaNxxX>4247778</NpaNxxX> <NpaNxxX>4247779</NpaNxxX></NpaNxxXs><Id>3</Id> </CoveredRateCenter></CoveredRateCenters>"),
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <CoveredRateCenters><CoveredRateCenter><Name>AVALON</Name><Abbreviation>AVALON</Abbreviation> <State>CA</State><Lata>730</Lata> <AvailableNumberCount>1</AvailableNumberCount> <ZipCodes><ZipCode>90731</ZipCode> </ZipCodes><Cities><City>SAN PEDRO</City> </Cities><Tiers> <Tier>0</Tier></Tiers> <NpaNxxXs><NpaNxxX>3105100</NpaNxxX> <NpaNxxX>3105101</NpaNxxX> <NpaNxxX>3109498</NpaNxxX> <NpaNxxX>3109499</NpaNxxX> <NpaNxxX>4242260</NpaNxxX></NpaNxxXs><Id>1</Id> </CoveredRateCenter></CoveredRateCenters>"),
Expand Down
Loading

0 comments on commit 8dbedbe

Please sign in to comment.