stepansib/alm-client

HP ALM/QC REST Client for PHP

v0.5.4 2019-05-07 14:03 UTC

This package is auto-updated.

Last update: 2021-09-07 19:02:29 UTC


README

SensioLabs Insight Codacy branch Packagist Coveralls

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