Skip to content

Commit 8dbedbe

Browse files
authored
Merge pull request #102 from Bandwidth/SWI-1859
SWI-1859 Get Tests Running in CI/CD
2 parents db1c916 + 7b48f64 commit 8dbedbe

27 files changed

+158
-59
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test
2+
3+
on:
4+
schedule:
5+
- cron: "0 4 * * *"
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix:
19+
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-22.04]
20+
php-version: [8.0, 8.1, 8.2, 8.3]
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-version }}
29+
30+
- name: Install Packages
31+
run: composer install
32+
33+
- name: Test
34+
run: ./vendor/bin/phpunit tests
35+
36+
- uses: Bandwidth/[email protected]
37+
if: failure() && !github.event.pull_request.draft
38+
with:
39+
job-status: ${{ job.status }}
40+
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
41+
slack-channel: ${{ secrets.SLACK_CHANNEL }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ config.php
66
composer.lock
77
.idea/
88
.DS_Store
9+
.phpunit.result.cache

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ PHP Client library for Bandwidth's Phone Number Dashboard (AKA: Dashboard, Iris)
3030

3131
## Supported PHP Versions
3232

33-
| Version | Support Level |
34-
|:-------------------------------|:-------------------------|
35-
| 5.5 | Unsupported |
36-
| 5.6 | Unsupported |
37-
| 7.0 | Unsupported |
38-
| 7.1 | Unsupported |
39-
| 7.2 | Supported |
40-
| 7.3 | Supported |
33+
| Version | Support Level |
34+
|:--------|:-------------------------|
35+
| 8.0 | Supported |
36+
| 8.1 | Supported |
37+
| 8.2 | Supported |
38+
| 8.3 | Supported |
4139

4240
## Install
4341

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"guzzlehttp/guzzle": "~7.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "~4.7"
17-
},
18-
"config": {
19-
"bin-dir": "bin"
16+
"phpunit/phpunit": "^9"
2017
},
2118
"autoload": {
19+
"psr-4": {
20+
"BandwidthLib\\": "src/"
21+
},
2222
"classmap": [
2323
"src/",
2424
"core/"

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnError="false"
10+
stopOnFailure="false"
11+
verbose="true"
12+
>
13+
<testsuites>
14+
<testsuite name="SDK Test Suite">
15+
<directory suffix="Test.php">./tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/DisconnectsModel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getList($filters = Array())
3333
}
3434

3535
public function disconnect($id, $tndetail = false) {
36-
$d = new Disconnect($this, array("orderId" => $id));
36+
$d = new Disconnect($this, array("OrderId" => $id));
3737
$d->get($tndetail);
3838
return $d;
3939
}
@@ -68,7 +68,7 @@ class Disconnect extends RestEntry {
6868
"CountOfTNs" => [ "type" => "string" ],
6969
"userId" => [ "type" => "string" ],
7070
"lastModifiedDate" => [ "type" => "string" ],
71-
"orderId" => [ "type" => "string" ],
71+
"OrderId" => [ "type" => "string" ],
7272
"OrderType" => [ "type" => "string" ],
7373
"OrderDate" => [ "type" => "string" ],
7474
"OrderStatus" => [ "type" => "string" ],
@@ -114,20 +114,20 @@ public function save() {
114114
$data = parent::post(null, "DisconnectTelephoneNumberOrder", $this->to_array());
115115
$this->OrderStatus = new OrderRequestStatus($data);
116116
if(isset($this->OrderStatus->orderRequest)) {
117-
$this->orderId = $this->OrderStatus->orderRequest->id;
117+
$this->OrderId = $this->OrderStatus->orderRequest->id;
118118
$this->set_data($this->OrderStatus->orderRequest->to_array());
119119
}
120120
}
121121

122122
/**
123123
* Get Entity Id
124124
* @return type
125-
* @throws Exception in case of orderId is null
125+
* @throws Exception in case of OrderId is null
126126
*/
127127
private function get_id() {
128-
if(!isset($this->orderId))
129-
throw new \Exception("You can't use this function without orderId");
130-
return $this->orderId;
128+
if(!isset($this->OrderId))
129+
throw new \Exception("You can't use this function without OrderId");
130+
return $this->OrderId;
131131
}
132132

133133
/**

tests/AccountTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use GuzzleHttp\Psr7\Response;
66
use GuzzleHttp\Middleware;
77

8-
class AccountTest extends PHPUnit_Framework_TestCase {
8+
use PHPUnit\Framework\TestCase;
9+
10+
class AccountTest extends TestCase {
911
public static $container;
1012
public static $account;
1113
public static $index = 0;
1214

13-
public static function setUpBeforeClass() {
15+
public static function setUpBeforeClass(): void {
1416
$mock = new MockHandler([
1517
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>"),
1618
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>"),
@@ -74,6 +76,8 @@ public static function setUpBeforeClass() {
7476

7577
$client = new Iris\Client("test", "test", Array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
7678
self::$account = new Iris\Account(9500249, $client);
79+
80+
return;
7781
}
7882

7983
public function testLineOption() {
@@ -124,6 +128,7 @@ public function testAvailableNumbers2() {
124128
* @expectedExceptionCode 4000
125129
*/
126130
public function testAvailableNumbersError() {
131+
$this->expectException(Iris\ResponseException::class);
127132
$response = self::$account->availableNumbers();
128133

129134
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());

tests/BadCredsTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
use GuzzleHttp\Psr7\Response;
55
use GuzzleHttp\Middleware;
66

7-
class BadCredsTest extends PHPUnit_Framework_TestCase {
7+
use PHPUnit\Framework\TestCase;
8+
9+
class BadCredsTest extends TestCase {
810
public static $container;
911
public static $client;
1012
public static $index = 0;
1113

12-
public static function setUpBeforeClass() {
14+
public static function setUpBeforeClass(): void {
1315
$mock = new MockHandler([
1416
new Response(401, [], ""),
1517
]);
@@ -19,7 +21,7 @@ public static function setUpBeforeClass() {
1921
$handler = HandlerStack::create($mock);
2022
$handler->push($history);
2123

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

2527
/**
@@ -28,6 +30,7 @@ public static function setUpBeforeClass() {
2830
* @expectedExceptionCode 401
2931
*/
3032
public function testAuthFail() {
33+
$this->expectException(Iris\ResponseException::class);
3134
$c = new \Iris\Cities(self::$client);
3235
try {
3336
$cities = $c->getList(["state" => "NC"]);

tests/BaseModelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"]); }}
1+
<?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"]); }}

tests/CoveredRateCentersTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
use GuzzleHttp\Psr7\Response;
55
use GuzzleHttp\Middleware;
66

7-
class CoveredRateCenterTest extends PHPUnit_Framework_TestCase {
7+
use PHPUnit\Framework\TestCase;
8+
9+
class CoveredRateCenterTest extends TestCase {
810
public static $container;
911
public static $rcs;
1012
public static $index = 0;
1113

12-
public static function setUpBeforeClass() {
14+
public static function setUpBeforeClass(): void {
1315
$mock = new MockHandler([
1416
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>"),
1517
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>"),

0 commit comments

Comments
 (0)