Skip to content

Commit f7d072d

Browse files
committed
Merge pull request #1 from meshachjackson/master
Adding tests
2 parents 33eafb1 + ffad1b9 commit f7d072d

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

Codebase.class.php renamed to bin/Codebase.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function projects() {
2626
}
2727

2828
public function tickets($permalink) {
29-
$xml = $this->object2array(simplexml_load_string($this->get('/'.$permalink.'/tickets?query=sort:status'),'SimpleXMLElement',LIBXML_NOCDATA));
29+
$url = '/'.$permalink.'/tickets?query=sort:status';
30+
$xml = $this->object2array(simplexml_load_string($this->get($url),'SimpleXMLElement',LIBXML_NOCDATA));
3031
return $xml['ticket'];
3132
}
3233

bin/config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$GLOBALS['config'] = array(
4+
'secure' => 's',
5+
'apiuser' => '[YOUR Codebase API USER]',
6+
'apikey' => '[YOUR Codebase API KEY]',
7+
'hostname' => '[YOUR Codebase HOSTNAME]',
8+
'project' => '[YOUR Codebase Test Project]',
9+
'debugMode' => false
10+
);

lib/Enhance-PHP

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 8368e4aed8339679dcb2c90ae4fbd21860db064d

tests/codebase.class.test.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
require_once("../bin/Codebase.class.php");
4+
require_once("../bin/config.php");
5+
6+
class Authentication_test extends \Enhance\TestFixture {
7+
8+
public static $instance = NULL;
9+
10+
private function debug($obj) {
11+
if ($this->config->debugMode) {
12+
echo '<pre>';
13+
print_r($obj);
14+
echo '</pre>';
15+
}
16+
}
17+
18+
// Singleton pattern to avoid creating a new
19+
private function getInstance() {
20+
$this->config = (object)$GLOBALS['config'];
21+
if (!isset(self::$instance)) {
22+
self::$instance = new Codebase($this->config->apiuser, $this->config->apikey, $this->config->hostname, $this->config->secure);
23+
self::debug(self::$instance);
24+
}
25+
return self::$instance;
26+
}
27+
28+
public function setUp() {
29+
$this->cb = $this->getInstance();
30+
}
31+
32+
public function Is_Instance_Of_Codebase () {
33+
\Enhance\Assert::isInstanceOfType('Codebase', $this->cb);
34+
}
35+
36+
public function Authentication_Matches () {
37+
\Enhance\Assert::areIdentical($this->config->apiuser, $this->cb->username);
38+
\Enhance\Assert::areIdentical($this->config->apikey, $this->cb->password);
39+
\Enhance\Assert::areIdentical($this->config->hostname, $this->cb->hostname);
40+
}
41+
42+
public function has_projects () {
43+
\Enhance\Assert::isNotNull($this->cb->projects());
44+
}
45+
46+
public function has_tickets () {
47+
$this->tickets = $this->cb->tickets($this->config->project);
48+
\Enhance\Assert::isNotNull($this->tickets);
49+
}
50+
51+
public function has_notes () {
52+
$this->tickets = $this->cb->tickets($this->config->project);
53+
\Enhance\Assert::isNotNull($this->cb->notes($this->tickets[0]['ticket-id'], $this->config->project));
54+
}
55+
56+
public function project_has_data () {
57+
\Enhance\Assert::isNotNull($this->cb->project($this->config->project));
58+
}
59+
60+
public function has_categories () {
61+
\Enhance\Assert::isNotNull($this->cb->categories($this->config->project));
62+
}
63+
64+
public function has_statuses () {
65+
\Enhance\Assert::isNotNull($this->cb->statuses($this->config->project));
66+
}
67+
68+
public function has_priorities () {
69+
\Enhance\Assert::isNotNull($this->cb->priorities($this->config->project));
70+
}
71+
}

tests/test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
require "../lib/Enhance-PHP/EnhanceTestFramework.php";
3+
\Enhance\Core::discoverTests('.');
4+
\Enhance\Core::runTests();

0 commit comments

Comments
 (0)