From 53592fc72a40413e0c54a368e4089869c82d4a93 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 5 Oct 2017 14:17:08 +0200 Subject: [PATCH] add unit tests --- .travis.yml | 11 ++++++ README.md | 17 ++++++++ src/TestingBot/TestingBotAPI.php | 21 +++++++--- tests/TestingBotTest.php | 66 ++++++++++++++++++++++++++++++++ tests/test.php | 9 ----- 5 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 .travis.yml create mode 100644 tests/TestingBotTest.php delete mode 100644 tests/test.php diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..27bd6e6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: php +php: +- '5.6' +- '7.1' +notifications: + email: false +install: +- composer self-update +- composer update --prefer-dist +script: +- phpunit tests/ \ No newline at end of file diff --git a/README.md b/README.md index 12c84a2..077a3b6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/testingbot/testingbot-php.svg?branch=master)](https://travis-ci.org/testingbot/testingbot-php) + Testingbot-PHP ======= @@ -34,6 +36,14 @@ To start, create a new `TestingBot\TestingBotAPI` object and pass in the key and Now you can use the various methods we've made available to interact with the API: +### getBrowsers +Gets a list of browsers you can test on + +```php + $api->getBrowsers(); +``` + + ### getUserInfo Gets your user information @@ -103,4 +113,11 @@ Gets a list of active tunnels for your account. ```php $api->getTunnels(); +``` + +### getAuthenticationHash +Calculates the hash necessary to share tests with other people + +```php + $api->getAuthenticationHash($identifier); ``` \ No newline at end of file diff --git a/src/TestingBot/TestingBotAPI.php b/src/TestingBot/TestingBotAPI.php index 65b6a13..9ac579a 100644 --- a/src/TestingBot/TestingBotAPI.php +++ b/src/TestingBot/TestingBotAPI.php @@ -112,7 +112,7 @@ public function getBuild($buildID) public function getTunnels() { - return $this->_doRequest("tunnels/", "GET"); + return $this->_doRequest("tunnel/list", "GET"); } public function getUserInfo() @@ -120,6 +120,11 @@ public function getUserInfo() return $this->_doRequest("user", "GET"); } + public function getBrowsers() + { + return $this->_doRequest("browsers", "GET"); + } + public function updateUserInfo(array $details) { $data = array(); @@ -132,6 +137,15 @@ public function updateUserInfo(array $details) return $this->_doRequest("user", "PUT", $data); } + public function getAuthenticationHash($identifier = null) { + if (!is_null($identifier)) + { + return md5($this->_key . ":" . $this->_secret . ":" . $identifier); + } + + return md5($this->_key . ":" . $this->_secret); + } + private function _doRequest($path, $method = 'POST', array $data = array()) { $curl = curl_init(); @@ -153,11 +167,6 @@ private function _doRequest($path, $method = 'POST', array $data = array()) private function _parseResult($response) { $result = json_decode($response, true); - if (empty($result)) - { - throw new \Exception("An API error occurred: " . print_r($response, true)); - } - return $result; } } diff --git a/tests/TestingBotTest.php b/tests/TestingBotTest.php new file mode 100644 index 0000000..2f703a2 --- /dev/null +++ b/tests/TestingBotTest.php @@ -0,0 +1,66 @@ +api = new TestingBot\TestingBotAPI($key, $secret); + } + + public function testGetSingleTest() { + $sessionID = "6344353dcee24694bf39d5ee5e6e5b11"; + $test = $this->api->getJob($sessionID); + $this->assertEquals($test['session_id'], $sessionID); + } + + public function testGetUnknownTest() { + $sessionID = "unknown"; + $test = $this->api->getJob($sessionID); + $this->assertArrayHasKey('error', $test); + } + + public function testDeleteUnknownTest() { + $sessionID = "unknown"; + $test = $this->api->deleteJob($sessionID); + $this->assertArrayHasKey('error', $test); + } + + public function testGetTests() { + $tests = $this->api->getJobs(0, 10); + $this->assertCount(10, $tests['data']); + } + + public function testGetUser() { + $user = $this->api->getUserInfo(); + $this->assertEquals("bot", $user['last_name']); + } + + public function testUnauthorizedCall() { + try { + $api = new TestingBot\TestingBotAPI('', ''); + $user = $api->getUserInfo(); + $this->assertEquals(true, false); + } catch (Exception $e) { + $this->assertEquals(true, true); + } + } + + public function testGetTunnels() { + $tunnels = $this->api->getTunnels(); + $this->assertCount(0, $tunnels); + } + + public function testGetBrowsers() { + $browsers = $this->api->getBrowsers(); + $this->assertEquals(sizeof($browsers) > 0, true); + } + + public function testCalculateAuthentication() { + $this->assertEquals($this->api->getAuthenticationHash("test"), "344ebf07233168c4882adf953a8a8c9b"); + } + } \ No newline at end of file diff --git a/tests/test.php b/tests/test.php deleted file mode 100644 index eb1af16..0000000 --- a/tests/test.php +++ /dev/null @@ -1,9 +0,0 @@ -getJob('{session}', array('skip_fields' => 'logs')));