Easily interact with HP ALM using REST API.
Simply run
composer require stepansib/alm-client
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',
));
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();
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;
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
To create a new entity you have to instantiate an AlmEntity object
$entity = new AlmEntity(AlmEntityManager::ENTITY_TYPE_DEFECT);
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;
Todo: complete this chapter
Todo: complete this chapter
Todo: complete this chapter