PHP Class Scalr\Tests\Functional\Api\ApiTestCase

Since: 5.4 (12.03.2015)
Author: Vlad Dobrovolskiy ([email protected])
Inheritance: extends Scalr\Tests\TestCase
Show file Open project: scalr/scalr Class Usage Examples

Protected Properties

Property Type Description
$apiController Scalr\Api\Rest\Controller\ApiController For the purpose of data conversion
$apiKeyEntity Scalr\Model\Entity\Account\User\ApiKeyEntity Api key entity
$apiVersion string API version
$env Scalr\Model\Entity\Account\Environment Scalr_Environment instance
$governance Scalr_Governance Scalr Governance
$governanceConfiguration array Governance configuration
$loggerConfiguration array List of logger what we should be excluded from debug output key is logger name and value is logger level
$testData array Ids of data generated during the test Destructor clean up data by these ids
$testEnvId integer ID of the user's environment
$testUserId integer ID of the user which is used in the functional test
$user Scalr\Model\Entity\Account\User Test User

Public Methods

Method Description
__construct ( $name = null, $data = [], $dataName = null )
assertDescribeResponseNotEmpty ( Scalr\Tests\Functional\Api\ApiTestResponse $response ) Asserts describe response has all properties
assertErrorMessageContains ( Scalr\Tests\Functional\Api\ApiTestResponse $response, integer $expectedStatus, string $expectedError = null, string $expectedMessage = null ) Asserts api error response
assertErrorMessageErrorEquals ( string $expectedError, Scalr\Tests\Functional\Api\ApiTestResponse $response ) Asserts error message error
assertErrorMessageStatusEquals ( integer $expectedStatus, Scalr\Tests\Functional\Api\ApiTestResponse $response ) Asserts error message status
assertErrorMessageTextEquals ( string $expectedMessage, Scalr\Tests\Functional\Api\ApiTestResponse $response ) Asserts error message text
assertFetchResponseNotEmpty ( Scalr\Tests\Functional\Api\ApiTestResponse $response ) Asserts fetch response has all properties
assertImageObjectNotEmpty ( object $data ) Asserts if images's object has all properties
assertObjectEqualsEntity ( $object, AbstractEntity | array $entity, string $adapter = null ) Asserts that object equals entity
assertVariableObjectNotEmpty ( object $data ) Asserts if variable's object has all properties
createEntity ( AbstractEntity $entity, array $data, array $requiredData = null ) : AbstractEntity Creates and save entity to DB, keeps entity to delete after test
getAccountApiUrl ( string $uriPart ) : string Gets Account API url
getAdapter ( string $name, ApiController $controller = null ) : ApiEntityAdapter Gets API entity adapter
getGovernance ( ) : Scalr_Governance Gets governance object
getUserApiUrl ( string $uriPart, integer $envId = null ) : string Gets User API url
isRecursivelyEmpty ( mixed $data ) : boolean Recursively checks that data is empty
printResponseError ( Scalr\Tests\Functional\Api\ApiTestResponse $response ) : string Makes string representation of error
request ( string $uri, string $method = Request::METHOD_GET, array $params = [], array $body = [], array $headers = [] ) : Scalr\Tests\Functional\Api\ApiTestResponse Calls api controllers' actions
restoreGovernanceConfiguration ( ) Restores a previously saved governance configuration
setUpBeforeClass ( ) Setups test user, environment and API key
setupGovernanceConfiguration ( array $governanceConfiguration, boolean $savePrevious = true ) Setup governance configuration
tearDownAfterClass ( ) Removes API key and Entities generated for test
toDelete ( string $class, array $identifier, array $initProperties = null ) Registers specified Entity for removal

Protected Methods

Method Description
changeLoggerConfiguration ( ) Change logger level and save current level
getEnvironment ( ) : Environment Gets a test environment instance
getNewImageId ( Scalr_Environment $env, string $cloudLocation ) : null | string Gets unused image id from the cloud
getUser ( ) : User Gets an test User instance
setUp ( )

Private Methods

Method Description
getTestEnvProperties ( ) : array Gets test properties for applicatiob environment

Method Details

__construct() public method

public __construct ( $name = null, $data = [], $dataName = null )

assertDescribeResponseNotEmpty() public method

Asserts describe response has all properties
public assertDescribeResponseNotEmpty ( Scalr\Tests\Functional\Api\ApiTestResponse $response )
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response

assertErrorMessageContains() public method

Asserts api error response
public assertErrorMessageContains ( Scalr\Tests\Functional\Api\ApiTestResponse $response, integer $expectedStatus, string $expectedError = null, string $expectedMessage = null )
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response
$expectedStatus integer Expected Status
$expectedError string optional Expected error
$expectedMessage string optional Expected message

assertErrorMessageErrorEquals() public method

Asserts error message error
public assertErrorMessageErrorEquals ( string $expectedError, Scalr\Tests\Functional\Api\ApiTestResponse $response )
$expectedError string Expected error
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response

assertErrorMessageStatusEquals() public method

Asserts error message status
public assertErrorMessageStatusEquals ( integer $expectedStatus, Scalr\Tests\Functional\Api\ApiTestResponse $response )
$expectedStatus integer Expected Status
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response

assertErrorMessageTextEquals() public method

Asserts error message text
public assertErrorMessageTextEquals ( string $expectedMessage, Scalr\Tests\Functional\Api\ApiTestResponse $response )
$expectedMessage string Expected message
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response

assertFetchResponseNotEmpty() public method

Asserts fetch response has all properties
public assertFetchResponseNotEmpty ( Scalr\Tests\Functional\Api\ApiTestResponse $response )
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response

assertImageObjectNotEmpty() public method

Asserts if images's object has all properties
public assertImageObjectNotEmpty ( object $data )
$data object Single image's item

assertObjectEqualsEntity() public method

Asserts that object equals entity
public assertObjectEqualsEntity ( $object, AbstractEntity | array $entity, string $adapter = null )
$object
$entity Scalr\Model\AbstractEntity | array
$adapter string optional Entity adapter name

assertVariableObjectNotEmpty() public method

Asserts if variable's object has all properties
public assertVariableObjectNotEmpty ( object $data )
$data object Single image's item

changeLoggerConfiguration() protected static method

Change logger level and save current level
protected static changeLoggerConfiguration ( )

createEntity() public static method

Creates and save entity to DB, keeps entity to delete after test
public static createEntity ( AbstractEntity $entity, array $data, array $requiredData = null ) : AbstractEntity
$entity Scalr\Model\AbstractEntity Entity instance
$data array Properties to initialize
$requiredData array The list of names properties which should be save and initialize after delete
return Scalr\Model\AbstractEntity

getAccountApiUrl() public static method

Gets Account API url
public static getAccountApiUrl ( string $uriPart ) : string
$uriPart string Part of the api uri
return string Returns User API url

getAdapter() public method

Gets API entity adapter
public getAdapter ( string $name, ApiController $controller = null ) : ApiEntityAdapter
$name string Adapter name
$controller Scalr\Api\Rest\Controller\ApiController optional API Controller
return Scalr\Api\DataType\ApiEntityAdapter

getEnvironment() protected method

Gets a test environment instance
protected getEnvironment ( ) : Environment
return Scalr\Model\Entity\Account\Environment Returns environment instance

getGovernance() public method

Gets governance object
public getGovernance ( ) : Scalr_Governance
return Scalr_Governance

getNewImageId() protected method

Gets unused image id from the cloud
protected getNewImageId ( Scalr_Environment $env, string $cloudLocation ) : null | string
$env Scalr_Environment Scalr environment
$cloudLocation string Region
return null | string

getUser() protected method

Gets an test User instance
protected getUser ( ) : User
return Scalr\Model\Entity\Account\User Returns user instance

getUserApiUrl() public static method

Gets User API url
public static getUserApiUrl ( string $uriPart, integer $envId = null ) : string
$uriPart string Part of the api uri
$envId integer optional Identifier of the Environment. If it is not specified method uses default test Environment.
return string Returns User API url

isRecursivelyEmpty() public static method

Recursively checks that data is empty
public static isRecursivelyEmpty ( mixed $data ) : boolean
$data mixed Data to check
return boolean Returns true if $data are empty or $data is object/array, all child elements of which recursively empty, false otherwise

printResponseError() public method

Makes string representation of error
public printResponseError ( Scalr\Tests\Functional\Api\ApiTestResponse $response ) : string
$response Scalr\Tests\Functional\Api\ApiTestResponse Response envelope
return string

request() public method

Calls api controllers' actions
public request ( string $uri, string $method = Request::METHOD_GET, array $params = [], array $body = [], array $headers = [] ) : Scalr\Tests\Functional\Api\ApiTestResponse
$uri string Request uri
$method string Http action
$params array optional Array of GET values
$body array optional POST fields => values
$headers array optional Custom headers
return Scalr\Tests\Functional\Api\ApiTestResponse Returns API test response

restoreGovernanceConfiguration() public method

Restores a previously saved governance configuration

setUp() protected method

protected setUp ( )

setUpBeforeClass() public static method

Setups test user, environment and API key
public static setUpBeforeClass ( )

setupGovernanceConfiguration() public method

Setup governance configuration
public setupGovernanceConfiguration ( array $governanceConfiguration, boolean $savePrevious = true )
$governanceConfiguration array Governance configuration
$savePrevious boolean optional If true, current governance configuration be saved before setting up a new

tearDownAfterClass() public static method

Removes API key and Entities generated for test
public static tearDownAfterClass ( )

toDelete() public static method

Registers specified Entity for removal
public static toDelete ( string $class, array $identifier, array $initProperties = null )
$class string The name of the class
$identifier array The PrimaryKey value of the Entity
$initProperties array The properties value what use in delete action

Property Details

$apiController protected static property

For the purpose of data conversion
protected static ApiController,Scalr\Api\Rest\Controller $apiController
return Scalr\Api\Rest\Controller\ApiController

$apiKeyEntity protected static property

Api key entity
protected static ApiKeyEntity,Scalr\Model\Entity\Account\User $apiKeyEntity
return Scalr\Model\Entity\Account\User\ApiKeyEntity

$apiVersion protected static property

API version
protected static string $apiVersion
return string

$env protected static property

Scalr_Environment instance
protected static Environment,Scalr\Model\Entity\Account $env
return Scalr\Model\Entity\Account\Environment

$governance protected property

Scalr Governance
protected Scalr_Governance $governance
return Scalr_Governance

$governanceConfiguration protected property

Governance configuration
protected array $governanceConfiguration
return array

$loggerConfiguration protected static property

List of logger what we should be excluded from debug output key is logger name and value is logger level
protected static array $loggerConfiguration
return array

$testData protected static property

Ids of data generated during the test Destructor clean up data by these ids
protected static array $testData
return array

$testEnvId protected static property

ID of the user's environment
protected static int $testEnvId
return integer

$testUserId protected static property

ID of the user which is used in the functional test
protected static int $testUserId
return integer

$user protected static property

Test User
protected static User,Scalr\Model\Entity\Account $user
return Scalr\Model\Entity\Account\User