From ffad1b9c05302fdf2b9a631d3fc770edb4ed4b10 Mon Sep 17 00:00:00 2001 From: Meshach Jackson Date: Thu, 27 Sep 2012 14:02:00 -0700 Subject: [PATCH] adding unit tests --- Codebase.class.php => bin/Codebase.class.php | 3 +- bin/config.php | 10 +++ lib/Enhance-PHP | 1 + tests/codebase.class.test.php | 71 ++++++++++++++++++++ tests/test.php | 4 ++ 5 files changed, 88 insertions(+), 1 deletion(-) rename Codebase.class.php => bin/Codebase.class.php (98%) create mode 100644 bin/config.php create mode 160000 lib/Enhance-PHP create mode 100644 tests/codebase.class.test.php create mode 100644 tests/test.php diff --git a/Codebase.class.php b/bin/Codebase.class.php similarity index 98% rename from Codebase.class.php rename to bin/Codebase.class.php index 08b084f..dbb7a48 100644 --- a/Codebase.class.php +++ b/bin/Codebase.class.php @@ -26,7 +26,8 @@ public function projects() { } public function tickets($permalink) { - $xml = $this->object2array(simplexml_load_string($this->get('/'.$permalink.'/tickets?query=sort:status'),'SimpleXMLElement',LIBXML_NOCDATA)); + $url = '/'.$permalink.'/tickets?query=sort:status'; + $xml = $this->object2array(simplexml_load_string($this->get($url),'SimpleXMLElement',LIBXML_NOCDATA)); return $xml['ticket']; } diff --git a/bin/config.php b/bin/config.php new file mode 100644 index 0000000..d9f9cd6 --- /dev/null +++ b/bin/config.php @@ -0,0 +1,10 @@ + 's', + 'apiuser' => '[YOUR Codebase API USER]', + 'apikey' => '[YOUR Codebase API KEY]', + 'hostname' => '[YOUR Codebase HOSTNAME]', + 'project' => '[YOUR Codebase Test Project]', + 'debugMode' => false + ); \ No newline at end of file diff --git a/lib/Enhance-PHP b/lib/Enhance-PHP new file mode 160000 index 0000000..8368e4a --- /dev/null +++ b/lib/Enhance-PHP @@ -0,0 +1 @@ +Subproject commit 8368e4aed8339679dcb2c90ae4fbd21860db064d diff --git a/tests/codebase.class.test.php b/tests/codebase.class.test.php new file mode 100644 index 0000000..30f2183 --- /dev/null +++ b/tests/codebase.class.test.php @@ -0,0 +1,71 @@ +config->debugMode) { + echo '
';
+				print_r($obj);
+				echo '
'; + } + } + + // Singleton pattern to avoid creating a new + private function getInstance() { + $this->config = (object)$GLOBALS['config']; + if (!isset(self::$instance)) { + self::$instance = new Codebase($this->config->apiuser, $this->config->apikey, $this->config->hostname, $this->config->secure); + self::debug(self::$instance); + } + return self::$instance; + } + + public function setUp() { + $this->cb = $this->getInstance(); + } + + public function Is_Instance_Of_Codebase () { + \Enhance\Assert::isInstanceOfType('Codebase', $this->cb); + } + + public function Authentication_Matches () { + \Enhance\Assert::areIdentical($this->config->apiuser, $this->cb->username); + \Enhance\Assert::areIdentical($this->config->apikey, $this->cb->password); + \Enhance\Assert::areIdentical($this->config->hostname, $this->cb->hostname); + } + + public function has_projects () { + \Enhance\Assert::isNotNull($this->cb->projects()); + } + + public function has_tickets () { + $this->tickets = $this->cb->tickets($this->config->project); + \Enhance\Assert::isNotNull($this->tickets); + } + + public function has_notes () { + $this->tickets = $this->cb->tickets($this->config->project); + \Enhance\Assert::isNotNull($this->cb->notes($this->tickets[0]['ticket-id'], $this->config->project)); + } + + public function project_has_data () { + \Enhance\Assert::isNotNull($this->cb->project($this->config->project)); + } + + public function has_categories () { + \Enhance\Assert::isNotNull($this->cb->categories($this->config->project)); + } + + public function has_statuses () { + \Enhance\Assert::isNotNull($this->cb->statuses($this->config->project)); + } + + public function has_priorities () { + \Enhance\Assert::isNotNull($this->cb->priorities($this->config->project)); + } + } \ No newline at end of file diff --git a/tests/test.php b/tests/test.php new file mode 100644 index 0000000..1288e6a --- /dev/null +++ b/tests/test.php @@ -0,0 +1,4 @@ +