diff options
Diffstat (limited to 'test/unit/ClientTest.php')
-rw-r--r-- | test/unit/ClientTest.php | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/test/unit/ClientTest.php b/test/unit/ClientTest.php index 51cfd76..18cab59 100644 --- a/test/unit/ClientTest.php +++ b/test/unit/ClientTest.php @@ -1,76 +1,64 @@ <?php -class MockClient extends SendGrid\Client -{ - public - $request_body, - $request_headers, - $url; - - public function makeRequest($method, $url, $request_body = null, $request_headers = null) - { - $this->request_body = $request_body; - $this->request_headers = $request_headers; - $this->url = $url; - return $this; - } -} -class ClientTest_Client extends PHPUnit_Framework_TestCase +namespace SendGrid\Test; + +class ClientTest extends \PHPUnit_Framework_TestCase { - protected - $client, - $host, - $headers; + /** @var MockClient */ + private $client; + /** @var string */ + private $host; + /** @var array */ + private $headers; protected function setUp() { $this->host = 'https://localhost:4010'; - $this->headers = array( + $this->headers = [ 'Content-Type: application/json', 'Authorization: Bearer SG.XXXX' - ); + ]; $this->client = new MockClient($this->host, $this->headers, '/v3', null); } - public function testInitialization() + public function testConstructor() { - $this->assertEquals($this->client->host, $this->host); - $this->assertEquals($this->client->request_headers, $this->headers); - $this->assertEquals($this->client->version, '/v3'); - $this->assertEquals($this->client->url_path, []); - $this->assertEquals($this->client->methods, ['delete', 'get', 'patch', 'post', 'put']); + $this->assertAttributeEquals($this->host, 'host', $this->client); + $this->assertAttributeEquals($this->headers, 'headers', $this->client); + $this->assertAttributeEquals('/v3', 'version', $this->client); + $this->assertAttributeEquals([], 'path', $this->client); + $this->assertAttributeEquals(['delete', 'get', 'patch', 'post', 'put'], 'methods', $this->client); } public function test_() { $client = $this->client->_('test'); - $this->assertEquals($client->url_path, array('test')); + $this->assertAttributeEquals(['test'], 'path', $client); } public function test__call() { $client = $this->client->get(); - $this->assertEquals($client->url, 'https://localhost:4010/v3/'); + $this->assertAttributeEquals('https://localhost:4010/v3/', 'url', $client); - $query_params = array('limit' => 100, 'offset' => 0); - $client = $this->client->get(null, $query_params); - $this->assertEquals($client->url, 'https://localhost:4010/v3/?limit=100&offset=0'); + $queryParams = ['limit' => 100, 'offset' => 0]; + $client = $this->client->get(null, $queryParams); + $this->assertAttributeEquals('https://localhost:4010/v3/?limit=100&offset=0', 'url', $client); - $request_body = array('name' => 'A New Hope'); - $client = $this->client->get($request_body); - $this->assertEquals($client->request_body, $request_body); + $requestBody = ['name' => 'A New Hope']; + $client = $this->client->get($requestBody); + $this->assertAttributeEquals($requestBody, 'requestBody', $client); - $request_headers = array('X-Mock: 200'); - $client = $this->client->get(null, null, $request_headers); - $this->assertEquals($client->request_headers, $request_headers); + $requestHeaders = ['X-Mock: 200']; + $client = $this->client->get(null, null, $requestHeaders); + $this->assertAttributeEquals($requestHeaders, 'requestHeaders', $client); $client = $this->client->version('/v4'); - $this->assertEquals($client->version, '/v4'); + $this->assertAttributeEquals('/v4', 'version', $client); $client = $this->client->path_to_endpoint(); - $this->assertEquals($client->url_path, array('path_to_endpoint')); + $this->assertAttributeEquals(['path_to_endpoint'], 'path', $client); $client = $client->one_more_segment(); - $this->assertEquals($client->url_path, array('path_to_endpoint', 'one_more_segment')); + $this->assertAttributeEquals(['path_to_endpoint', 'one_more_segment'], 'path', $client); } -} -?>
\ No newline at end of file +}
\ No newline at end of file |