Skip to content

Adding tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Codebase.class.php → bin/Codebase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
10 changes: 10 additions & 0 deletions bin/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$GLOBALS['config'] = array(
'secure' => 's',
'apiuser' => '[YOUR Codebase API USER]',
'apikey' => '[YOUR Codebase API KEY]',
'hostname' => '[YOUR Codebase HOSTNAME]',
'project' => '[YOUR Codebase Test Project]',
'debugMode' => false
);
1 change: 1 addition & 0 deletions lib/Enhance-PHP
Submodule Enhance-PHP added at 8368e4
71 changes: 71 additions & 0 deletions tests/codebase.class.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

require_once("../bin/Codebase.class.php");
require_once("../bin/config.php");

class Authentication_test extends \Enhance\TestFixture {

public static $instance = NULL;

private function debug($obj) {
if ($this->config->debugMode) {
echo '<pre>';
print_r($obj);
echo '</pre>';
}
}

// 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));
}
}
4 changes: 4 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require "../lib/Enhance-PHP/EnhanceTestFramework.php";
\Enhance\Core::discoverTests('.');
\Enhance\Core::runTests();