Lean Testing PHP SDK
, (*1)
PHP client for Lean Testing API, (*2)
You can sign up for a Lean Testing account at https://leantesting.com., (*3)
Requirements
Installation
The library is installed via Composer. To install, simply add it
to your composer.json file:, (*4)
{
"require": {
"cst/leantesting": "2.*"
}
}
And run composer to update your dependencies:, (*5)
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
Basic Usage
$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
$client->getCurrentToken()
$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 );
$client->user->getInformation()
$client->user->organizations->all()->toArray()
- Retrieve An Existing User Organization
$client->user->organizations->find(31)->data
$client->projects->all()->toArray()
$new_project = $client->projects->create([
'name' => 'Project135',
'organization_id' => 5779
]);
print_r( $new_project->data );
- Retrieve An Existing Project
$client->projects->find(3515)->data
$client->projects->find(3515)->sections->all()->toArray()
$new_section = $client->projects->find(3515)->sections->create([
'name' => 'SectionName'
]);
print_r( $new_section->data );
$client->projects->find(3515)->versions->all()->toArray()
$new_version = $client->projects->find(3515)->versions->create([
'number' => 'v0.3.1104'
]);
print_r( $new_version->data );
$client->projects->find(3515)->testCases->all()->toArray();
$client->projects->find(3515)->testRuns->all()->toArray();
- Retrieve Results For Test Run
$client->projects->find(3515)->testRuns->find(123)->data;
$client->projects->find(3515)->users->all()->toArray();
$client->projects->find(3515)->users->delete(123);
$client->projects->find(3515)->bugTypeScheme->all()->toArray()
$client->projects->find(3515)->bugStatusScheme->all()->toArray()
$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()
$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 );
$client->bugs->find(123)->data
$updated_bug = $client->bugs->update(123, [
'title' => 'Updated title',
'status_id' => 1,
'severity_id' => 2,
'project_version_id' => 123
]);
print_r( $updated_bug->data );
$client->bugs->delete(123)
$client->bugs->find(123)->comments->all()->toArray()
$client->bugs->find(123)->attachments->all()->toArray()
$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
$client->attachments->delete(75198)
$client->platform->types->all()->toArray()
$client->platform->types->find(1)->data
$client->platform->types->find(1)->devices->all()->toArray()
$client->platform->devices->find(11)->data
$client->platform->os->all()->toArray()
$client->platform->os->find(1)->data
$client->platform->os->find(1)->versions->all()->toArray()
$client->platform->browsers->all()->toArray()
- Retrieve Existing Browser
$client->platform->browsers->find(1)->data
$client->platform->browsers->find(1)->versions->all()->toArray()
$client->projects->find(3515)->bugs->all(['limit' => 2, 'page' => 5]).toArray();
$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., (*6)
Development
Install dependencies:, (*7)
``` bash
composer install, (*8)
## Tests
Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:
```bash
./vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details., (*9)