public function testCanCatchError()
 {
     $fogbugz = new FogBugz($this->user, $this->pass, $this->url);
     // swap out or connection object
     $fogbugz->curl = $this->getMock('FogBugzCurl');
     // set the xml we would expect to see on a login
     $fogbugz->curl->expects($this->any())->method('fetch')->will($this->returnValue(file_get_contents(__DIR__ . '/data/error.xml')));
     try {
         $fogbugz->startWork(array("ixBug" => 213));
     } catch (FogBugzAPIError $expected) {
         $this->assertEquals(3, $expected->getCode(), "Error code was not processed correctly");
         $this->assertEquals("Not logged on", $expected->getMessage(), "Error message was not processed correctly");
         return;
     }
     $this->fail("An exception was not raised");
 }
$github_repo_name = 'http://github.com/ArthurD/PHP-FogBugz-API-Wrapper';
// We're setting this because the 'Service Hooks' apply to ALL repos, but in our case we only want to use this hook for 1 Repo...
// Modify the above as needed, the logic that references it is around line #37...
// Quick function to convert Git Committer Names to FogBugz User IDs.  Modify as needed.
function getIDfromUsername($username)
{
    if (stripos($username, 'Arthur') !== false) {
        return 2;
    } else {
        return null;
    }
}
// The Commit Data (GitHub Payload)
$commit_data = json_decode($_POST['payload']);
// Initiliaze Our FogBugz Class
$fb = new FogBugz($fogbugz_url, $fogbugz_username, $fogbugz_password);
// Is this a commit to the Repo that we care about?
if ((string) $commit_data->repository->url != $github_repo_url) {
    die('Error - Invalid Repo!');
}
// Get Commit Data
foreach ($commit_data->commits as $commit) {
    // Commit Data
    $data['committer_name'] = (string) $commit->author->name;
    $data['committer_email'] = (string) $commit->author->email;
    $data['commit_url'] = (string) $commit->url;
    $data['commit_id'] = (string) $commit->id;
    $data['commit_message'] = (string) $commit->message;
    //// The next three blocks compile the Modified/Added/Removed files into a single string that is seperated by line breaks (\n)
    foreach ($commit->added as $filename) {
        $data['commit_files'] .= "[a] " . $filename . "\n";
 * Demonstration of FogBugz API
 *
 * Run this as:
 *   php sample.php --user username@example.com --pass password --url http://example.fogbugz.com
 *
 */
error_reporting(E_ALL | E_STRICT);
require_once __DIR__ . '/lib/api.php';
// collect the user and password from the command line
$options = (object) getopt('', array('user:'******'pass:'******'url:'));
if (empty($options->user) || empty($options->pass) || empty($options->url)) {
    exit("This script needs a user, password and url " . "set via --user [user] --pass [password] --url [url]\n");
}
// init our fogbugz api with the user and pass from the command line,
// and the url from the var above
$fogbugz = new FogBugz($options->user, $options->pass, $options->url);
// fogbugz will throw exceptions, so we catch them here
try {
    $fogbugz->logon();
    // You can call any FogBugz API method directly by using it's
    // name as a method name on the $fogbugz object.
    // It will turn the method name in to the command,
    // ?cmd={method_name} and it will add the array to the
    // get request automatically
    $xml = $fogbugz->listFilters();
    // this returns a SimpleXMLElement object, so
    // remember to treat it as such
    print "Fogbugz filter list for current user:\n";
    foreach ($xml->filters->children() as $filter) {
        print sprintf("[%s] %s\n", $filter['type'], (string) $filter);
    }
// Settings & Dependencies
require 'lib/fogbugz-api.php';
// Require the FogBugz API Class
require 'lib/curl.php';
// Require the CURL Class
// Location of a file in which we want CURL to store the Cookie after successful login (MUST be writeable)
define('COOKIEFILE', 'lib/cookie.txt');
// Your FogBugz Username, Password, and API URL
$fogbugz_url = 'http://YOURURL.fogbugz.com/api.asp';
$fogbugz_username = '******';
$fogbugz_password = '******';
///////////
// Add a New FogBugz Case via the API
///////////
// Create FogBugz Object
$fb = new FogBugz($fogbugz_url, $fogbugz_username, $fogbugz_password);
$title = "Test New Ticket via API";
// New Case Title (string)
$project = "PAS v3";
// Project (string)
$area = "Other";
// Area (string)
$category = "Task";
// Category (string)
$priority_id = 6;
// Priority ID (integer)
$assignedTo_id = 2;
// User ID of the user to Assign this case to (integer)
// The BODY of the new FogBugz Case.  HTML is *not* accepted and all linebreaks (\n) are shown as such when viewed in a browser
$body = "Just testing out the functionality \n\n hello world!\n'yes!'";
// Send Request to Create the FogBugz Case
<?php

require_once '../../../third_party/fogbugz-php-api/lib/api.php';
$email = '*****@*****.**';
$password = '******';
$url = 'https://testlink.fogbugz.com';
$fogbugz = new FogBugz($email, $password, $url);
// fogbugz will throw exceptions, so we catch them here
try {
    $fogbugz->logon();
    // You can call any FogBugz API method directly by using it's
    // name as a method name on the $fogbugz object.
    // It will turn the method name in to the command,
    // ?cmd={method_name} and it will add the array to the
    // get request automatically
    /*
    $xml = $fogbugz->listProjects();
    foreach ($xml->projects->children() as $item) 
    {
    	print "<b>Project:" . (string)$item->sProject;
    	print "</b><br>";
    	var_dump($item);
    	print "<br>======================<br>";
    }
    */
    // Go for an issue
    $xml = $fogbugz->search(array('q' => 3, 'cols' => 'sTitle,sStatus'));
    //$xml = $fogbugz->search(array('q' => 3));
    echo (string) $xml->description . '<br>';
    echo (int) $xml->cases['count'] . '<br>';
    // var_dump($xml->cases);