Skip to content

Commit 53592fc

Browse files
committed
add unit tests
1 parent 8edb066 commit 53592fc

File tree

5 files changed

+109
-15
lines changed

5 files changed

+109
-15
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
php:
3+
- '5.6'
4+
- '7.1'
5+
notifications:
6+
email: false
7+
install:
8+
- composer self-update
9+
- composer update --prefer-dist
10+
script:
11+
- phpunit tests/

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://travis-ci.org/testingbot/testingbot-php.svg?branch=master)](https://travis-ci.org/testingbot/testingbot-php)
2+
13
Testingbot-PHP
24
=======
35

@@ -34,6 +36,14 @@ To start, create a new `TestingBot\TestingBotAPI` object and pass in the key and
3436

3537
Now you can use the various methods we've made available to interact with the API:
3638

39+
### getBrowsers
40+
Gets a list of browsers you can test on
41+
42+
```php
43+
$api->getBrowsers();
44+
```
45+
46+
3747
### getUserInfo
3848
Gets your user information
3949

@@ -103,4 +113,11 @@ Gets a list of active tunnels for your account.
103113

104114
```php
105115
$api->getTunnels();
116+
```
117+
118+
### getAuthenticationHash
119+
Calculates the hash necessary to share tests with other people
120+
121+
```php
122+
$api->getAuthenticationHash($identifier);
106123
```

src/TestingBot/TestingBotAPI.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,19 @@ public function getBuild($buildID)
112112

113113
public function getTunnels()
114114
{
115-
return $this->_doRequest("tunnels/", "GET");
115+
return $this->_doRequest("tunnel/list", "GET");
116116
}
117117

118118
public function getUserInfo()
119119
{
120120
return $this->_doRequest("user", "GET");
121121
}
122122

123+
public function getBrowsers()
124+
{
125+
return $this->_doRequest("browsers", "GET");
126+
}
127+
123128
public function updateUserInfo(array $details)
124129
{
125130
$data = array();
@@ -132,6 +137,15 @@ public function updateUserInfo(array $details)
132137
return $this->_doRequest("user", "PUT", $data);
133138
}
134139

140+
public function getAuthenticationHash($identifier = null) {
141+
if (!is_null($identifier))
142+
{
143+
return md5($this->_key . ":" . $this->_secret . ":" . $identifier);
144+
}
145+
146+
return md5($this->_key . ":" . $this->_secret);
147+
}
148+
135149
private function _doRequest($path, $method = 'POST', array $data = array())
136150
{
137151
$curl = curl_init();
@@ -153,11 +167,6 @@ private function _doRequest($path, $method = 'POST', array $data = array())
153167
private function _parseResult($response)
154168
{
155169
$result = json_decode($response, true);
156-
if (empty($result))
157-
{
158-
throw new \Exception("An API error occurred: " . print_r($response, true));
159-
}
160-
161170
return $result;
162171
}
163172
}

tests/TestingBotTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
require_once('src/TestingBot/TestingBotAPI.php');
4+
5+
class TestingBotTest extends PHPUnit_Framework_TestCase {
6+
private $api;
7+
8+
public function setup() {
9+
$key = getenv("TB_KEY");
10+
$secret = getenv("TB_SECRET");
11+
12+
$this->api = new TestingBot\TestingBotAPI($key, $secret);
13+
}
14+
15+
public function testGetSingleTest() {
16+
$sessionID = "6344353dcee24694bf39d5ee5e6e5b11";
17+
$test = $this->api->getJob($sessionID);
18+
$this->assertEquals($test['session_id'], $sessionID);
19+
}
20+
21+
public function testGetUnknownTest() {
22+
$sessionID = "unknown";
23+
$test = $this->api->getJob($sessionID);
24+
$this->assertArrayHasKey('error', $test);
25+
}
26+
27+
public function testDeleteUnknownTest() {
28+
$sessionID = "unknown";
29+
$test = $this->api->deleteJob($sessionID);
30+
$this->assertArrayHasKey('error', $test);
31+
}
32+
33+
public function testGetTests() {
34+
$tests = $this->api->getJobs(0, 10);
35+
$this->assertCount(10, $tests['data']);
36+
}
37+
38+
public function testGetUser() {
39+
$user = $this->api->getUserInfo();
40+
$this->assertEquals("bot", $user['last_name']);
41+
}
42+
43+
public function testUnauthorizedCall() {
44+
try {
45+
$api = new TestingBot\TestingBotAPI('', '');
46+
$user = $api->getUserInfo();
47+
$this->assertEquals(true, false);
48+
} catch (Exception $e) {
49+
$this->assertEquals(true, true);
50+
}
51+
}
52+
53+
public function testGetTunnels() {
54+
$tunnels = $this->api->getTunnels();
55+
$this->assertCount(0, $tunnels);
56+
}
57+
58+
public function testGetBrowsers() {
59+
$browsers = $this->api->getBrowsers();
60+
$this->assertEquals(sizeof($browsers) > 0, true);
61+
}
62+
63+
public function testCalculateAuthentication() {
64+
$this->assertEquals($this->api->getAuthenticationHash("test"), "344ebf07233168c4882adf953a8a8c9b");
65+
}
66+
}

tests/test.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)