VoiceTest.php 2.34 KB
Newer Older
Juliper committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<?php

use \Mockery as m;
require_once 'Twilio.php';

class VoiceTest extends PHPUnit_Framework_TestCase {

    function testGetCountries() {
        $data = array(
            'meta' => array(
                'key' => 'countries',
                'next_page_url' => null
            ),
            'countries' => array(
                array('iso_country' => 'US')
            )
        );
        $http = m::mock(new Services_Twilio_TinyHttp);
        $http->shouldReceive('get')->once()->with(
            '/v1/Voice/Countries?Page=0&PageSize=50'
        )->andReturn(array(200, array('Content-Type' => 'application/json'),
                                 json_encode($data)));

        $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1',
                                                     $http, 1);
        $countries = $pricingClient->voiceCountries->getPage();
        $this->assertNotNull($countries);

        $countryList = $countries->getItems();
        $country = $countryList[0];
        $this->assertNotNull($country);
        $this->assertEquals($country->iso_country, 'US');
    }

    function testGetCountry() {
        $http = m::mock(new Services_Twilio_TinyHttp);
        $http->shouldReceive('get')->once()->with('/v1/Voice/Countries/EE')
            ->andReturn(array(200, array('Content-Type' => 'application/json'),
                        json_encode(array('country' => 'Estonia'))));
        $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1', $http, 1);

        $country = $pricingClient->voiceCountries->get('EE');
        $this->assertNotNull($country);
        $this->assertEquals($country->iso_country, 'EE');
        $this->assertEquals($country->country, 'Estonia');
    }

    function testGetNumber() {
        $http = m::mock(new Services_Twilio_TinyHttp);
        $http->shouldReceive('get')->once()->with(
            '/v1/Voice/Numbers/+14155551234'
        )->andReturn(array(200, array('Content-Type' => 'application/json'),
                             json_encode(array('iso_country' => 'US'))));

        $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1', $http, 1);

        $number = $pricingClient->voiceNumbers->get('+14155551234');
        $this->assertNotNull($number);
        $this->assertEquals($number->number, '+14155551234');
        $this->assertEquals($number->iso_country, 'US');
    }

}