stepansib / alm-client
HP ALM/QC REST Client for PHP
Installs: 1 309
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: >=7.1
- ext-curl: *
- ext-simplexml: *
- lib-curl: *
- symfony/options-resolver: ^3
Requires (Dev)
- symfony/var-dumper: ^4.2
README
Easily interact with HP ALM using REST API.
Installation
Simply run
composer require stepansib/alm-client
Usage
Setting up ALM/QC connection
The first step is to setup correct connection credentials and instantiate new AlmClient object
$almClient = new AlmClient(array( 'host' => 'http://alm-qc-host:8080', 'domain' => 'DOMAIN_NAME', 'project' => 'PROJECT_NAME', 'username' => 'johndoe', 'password' => 'password123', ));
Authentication
You need to authenticate to start work with ALM
$almClient = new AlmClient($connectionParams); $almClient->getAuthenticator()->login(); // lets check if user authenticated successfully echo $almClient->getAuthenticator()->isAuthenticated() ? "Authenticated" : "Not authenticated";
When you finish your work with ALM/QC use logout method
$almClient->getAuthenticator()->logout();
Get entity by criteria
All entities are returned in AlmEntity objects. You must specify ALM/QC entity type (defect, test, run etc) and array of criterias to filter entites
// you can get the array of entities $defects = $almClient->getManager()->getBy(AlmEntityManager::ENTITY_TYPE_DEFECT, array( 'id' => '>=100', 'status' => 'Open', 'owner' => 'johndoe', )); // or get only first matching entity $entity = $almClient->getManager()->getOneBy(AlmEntityManager::ENTITY_TYPE_DEFECT, array( 'id' => '101' ));
Also you can get entities as ALM/QC XML response by specifying hydration type:
$defects = $almClient->getManager()->getBy(AlmEntityManager::ENTITY_TYPE_DEFECT, array( 'owner' => 'johndoe', ), AlmEntityManager::HYDRATION_NONE); // Lets output the XML returned by ALM/QC echo $defects;
The entity
Entity field values can be accessed in two ways
// through getter method $paramValue = $entity->getParameter('detected-by'); //or directly via magic getter method $paramValue = $entity->detected-by;
To create a new parameter or change the existing parameter use setter method
$entity->setParameter('description', 'my defect description');
To get all parameters in array use
$entityParameters = $entity->getParameters();
To get and change entity type use
$entityType = $entity->getType(); $entity->setType(AlmEntityManager::ENTITY_TYPE_RESOURCE); //This method also called in AlmEntity::__construct
Create a new entity
To create a new entity you have to instantiate an AlmEntity object
$entity = new AlmEntity(AlmEntityManager::ENTITY_TYPE_DEFECT);
Save an entity
To save (persist or update) an entity use the AlmEntityManager::save()
method
$almClient->getManager()->save($entity);
This will work both for new and existing entities. This method returns saved AlmEntity object
Full workflow example
$entity = new AlmEntity(AlmEntityManager::ENTITY_TYPE_DEFECT); // lets fill some entity fields $entity->setParameter('name', 'REST API test defect ' . date('d/m/Y H:i:s')) ->setParameter('detected-by', 'johndoe') ->setParameter('owner', 'johndoe') ->setParameter('creation-time', date('Y-m-d')) ->setParameter('description', 'REST API test defect description'); // and finally save the new defect $entity = $almClient->getManager()->save($entity); echo 'New entity id: ' . $entity->id;
Get entity available fields list (and editable fields list)
Todo: complete this chapter
Get editable fields list
Todo: complete this chapter
Get entity lock state
Todo: complete this chapter