cst/leantesting

v2.0.1 2017-02-23 21:01 UTC

README

Latest Stable Version License

PHP client for Lean Testing API

You can sign up for a Lean Testing account at https://leantesting.com.

Requirements

  • PHP 5.4 or greater

Installation

The library is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "cst/leantesting": "2.*"
    }
}

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Basic Usage

  • Instantiate the client
$client = new LeanTesting\API\Client\Client();
$client->attachToken('<your token>');

// Listing projects
$projects = $client->projects->all();

// Fetching project bugs
$bugs = $client->projects->find(123)->bugs->all();

Methods

  • Get Current Token
$client->getCurrentToken()
  • Attach New Token
$client->attachToken('<token>');
  • Generate Authorization URL
$generated_URL = $client->auth->generateAuthLink(
	'DHxaSvtpl91Xos4vb7d0GKkXRu0GJxd5Rdha2HHx', // client id
  'https://www.example.com/appurl/',
	'write', // scope
	'a3ahdh2iqhdasdasfdjahf26' // random string
);
print_r( $generated_URL );
  • Exchange authorization code for an access token
$token = $client->auth->exchangeAuthCode(
	'DHxaSvtpl91Xos4vb7d0GKkXRu0GJxd5Rdha2asdasdx', // client id
	'DpOZxNbeL1arVbjUINoA9pOhgS8FNQsOkpE4CtXU', // client secret
	'authorization_code',
	'JKHanMA897A7KA9ajqmxly', // auth code
	'https://www.example.com/appurl/'
);
print_r( $token );
  • Get User Information
$client->user->getInformation()
  • Get User Organizations
$client->user->organizations->all()->toArray()
  • Retrieve An Existing User Organization
$client->user->organizations->find(31)->data
  • List All Projects
$client->projects->all()->toArray()
  • Create A New Project
$new_project = $client->projects->create([
	'name' => 'Project135',
	'organization_id' => 5779
]);
print_r( $new_project->data );
  • Retrieve An Existing Project
$client->projects->find(3515)->data
  • List Project Sections
$client->projects->find(3515)->sections->all()->toArray()
  • Adding A Project Section
$new_section = $client->projects->find(3515)->sections->create([
	'name' => 'SectionName'
]);
print_r( $new_section->data );
  • List Project Versions
$client->projects->find(3515)->versions->all()->toArray()
  • Adding A Project Version
$new_version = $client->projects->find(3515)->versions->create([
	'number' => 'v0.3.1104'
]);
print_r( $new_version->data );
  • List Project Test Cases
$client->projects->find(3515)->testCases->all()->toArray();
  • List Project Test Runs
$client->projects->find(3515)->testRuns->all()->toArray();
  • Retrieve Results For Test Run
$client->projects->find(3515)->testRuns->find(123)->data;
  • List Project Users
$client->projects->find(3515)->users->all()->toArray();
  • Remove A Project User
$client->projects->find(3515)->users->delete(123);
  • List Bug Type Scheme
$client->projects->find(3515)->bugTypeScheme->all()->toArray()
  • List Bug Status Scheme
$client->projects->find(3515)->bugStatusScheme->all()->toArray()
  • List Bug Severity Scheme
$client->projects->find(3515)->bugSeverityScheme->all()->toArray()
  • List Bug Reproducibility Scheme
$client->projects->find(3515)->bugReproducibilityScheme->all()->toArray()
  • List All Bugs In A Project
$client->projects->find(3515)->bugs->all()->toArray()
  • Create A New Bug
$new_bug = $client->projects->find(3515)->bugs->create([
	'title' => 'Something bad happened...',
	'status_id' => 1,
	'severity_id' => 2,
	'project_version_id' => 123
]);
print_r( $new_bug->data );
  • Retrieve Existing Bug
$client->bugs->find(123)->data
  • Update A Bug
$updated_bug = $client->bugs->update(123, [
	'title' => 'Updated title',
	'status_id' => 1,
	'severity_id' => 2,
	'project_version_id' => 123
]);
print_r( $updated_bug->data );
  • Delete A Bug
$client->bugs->delete(123)
  • List Bug Comments
$client->bugs->find(123)->comments->all()->toArray()
  • List Bug Attachments
$client->bugs->find(123)->attachments->all()->toArray()
  • Upload An Attachment
$file_path = '/place/Downloads/Images/1370240743_2294218.jpg';
$new_attachment = $client->bugs->find(123)->attachments->upload($file_path);
print_r( $new_attachment->data )
  • Retrieve An Existing Attachment
$client->attachments->find(21515)->data
  • Delete An Attachment
$client->attachments->delete(75198)
  • List Platform Types
$client->platform->types->all()->toArray()
  • Retrieve Platform Type
$client->platform->types->find(1)->data
  • List Platform Devices
$client->platform->types->find(1)->devices->all()->toArray()
  • Retrieve Existing Device
$client->platform->devices->find(11)->data
  • List OS
$client->platform->os->all()->toArray()
  • Retrieve Existing OS
$client->platform->os->find(1)->data
  • List OS Versions
$client->platform->os->find(1)->versions->all()->toArray()
  • List Browsers
$client->platform->browsers->all()->toArray()
  • Retrieve Existing Browser
$client->platform->browsers->find(1)->data
  • List Browser Versions
$client->platform->browsers->find(1)->versions->all()->toArray()
  • Using Filters
$client->projects->find(3515)->bugs->all(['limit' => 2, 'page' => 5]).toArray();
  • Entity List Functions
$browsers = $client->platform->browsers->all()
echo $browsers->total()
echo $browsers->totalPages()
echo $browsers->count()
echo $browsers->toArray()
  • Entity List Iterator When used in foreach() loops, entity lists will automatically rewind, regardless of page filter. After ending the loop, the entity list will NOT revert to first page or the initial instancing page filter setting in order not to cause useless API request calls.
$comments = $client->bugs->find(123)->comments->all(['limit' => 1]);
foreach ($comments as $page) {
	print_r( $page );
}
  • Entity List Manual Iteration
$comments = $client->bugs->find(123)->comments->all(['limit' => 1]);
echo $comments->toArray();

// Will return false if unable to move forwards
$comments->next();      echo $comments->toArray();

// Will return false if already on last page
$comments->last();      echo $comments->toArray();

// Will return false if unable to move backwards
$comments->previous();  echo $comments->toArray();

// Will return false if already on first page
$comments->first();     echo $comments->toArray();

Security

Need to report a security vulnerability? Send us an email to support@crowdsourcedtesting.com or go directly to our security bug bounty site https://hackerone.com/leantesting.

Development

Install dependencies:

composer install

Tests

Install dependencies as mentioned above (which will resolve PHPUnit), then you can run the test suite:

./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.