Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Static Protected Attributes
Api Class Reference

Static Public Member Functions

static callWithException (\PHPUnit\Framework\TestCase $testCase, $path, $params=[], $expectedMessage='')
 
static restoreErrorHandler ()
 
static soapAdapterFaultCallback ($exceptionCode, $exceptionMessage)
 
static simpleXmlToArray ($xml, $keyTrimmer=null)
 
static checkEntityFields (\PHPUnit\Framework\TestCase $testCase, array $expectedData, array $actualData, array $fieldsToCompare=[])
 

Static Protected Attributes

static $_previousHandler = null
 

Detailed Description

Definition at line 10 of file Api.php.

Member Function Documentation

◆ callWithException()

static callWithException ( \PHPUnit\Framework\TestCase  $testCase,
  $path,
  $params = [],
  $expectedMessage = '' 
)
static

Call API method via API handler that raises SoapFault exception

Parameters
\PHPUnit\Framework\TestCase$testCaseActive test case
string$path
array$paramsOrder of items matters as they are passed to call_user_func_array
string$expectedMessageexception message
Returns
\SoapFault

Definition at line 74 of file Api.php.

79  {
80  try {
81  self::call($testCase, $path, $params);
83  $testCase->fail('Expected error exception was not raised.');
84  } catch (\SoapFault $exception) {
86  if ($expectedMessage) {
87  $testCase->assertEquals($expectedMessage, $exception->getMessage());
88  }
89  return $exception;
90  }
91  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ checkEntityFields()

static checkEntityFields ( \PHPUnit\Framework\TestCase  $testCase,
array  $expectedData,
array  $actualData,
array  $fieldsToCompare = [] 
)
static

Check specific fields value in some entity data.

Parameters
\PHPUnit\Framework\TestCase$testCase
array$expectedData
array$actualData
array$fieldsToCompareTo be able to compare fields from loaded model with fields from API response this parameter provides fields mapping. Array can store model field name $entityField mapped on field name in API response. $fieldsToCompare format is: $fieldsToCompare = array($modelFieldName => $apiResponseFieldName); Example: $fieldsToCompare = array( 'entity_id' => 'product_id', 'sku', 'attribute_set_id' => 'set', 'type_id' => 'type', 'category_ids', );

Definition at line 190 of file Api.php.

195  {
196  $fieldsToCompare = !empty($fieldsToCompare) ? $fieldsToCompare : array_keys($expectedData);
197  foreach ($fieldsToCompare as $entityField => $field) {
198  $testCase->assertEquals(
199  $expectedData[is_numeric($entityField) ? $field : $entityField],
200  $actualData[$field],
201  sprintf('"%s" filed has invalid value.', $field)
202  );
203  }
204  }

◆ restoreErrorHandler()

static restoreErrorHandler ( )
static

Restore previously used error handler

Definition at line 96 of file Api.php.

97  {
98  set_error_handler(self::$_previousHandler);
99  }

◆ simpleXmlToArray()

static simpleXmlToArray (   $xml,
  $keyTrimmer = null 
)
static

Convert Simple XML to array

Parameters
\SimpleXMLObject$xml
String$keyTrimmer
Returns
object

In XML notation we can't have nodes with digital names in other words fallowing XML will be not valid: <24> Default category </24>

But this one will not cause any problems: <qwe_24> Default category </qwe_24>

So when we want to obtain an array with key 24 we will pass the correct XML from above and $keyTrimmer = 'qwe_'; As a result we will obtain an array with digital key node.

In the other case just don't pass the $keyTrimmer.

Definition at line 135 of file Api.php.

136  {
137  $result = [];
138 
139  $isTrimmed = false;
140  if (null !== $keyTrimmer) {
141  $isTrimmed = true;
142  }
143 
144  if (is_object($xml)) {
145  foreach (get_object_vars($xml->children()) as $key => $node) {
146  $arrKey = $key;
147  if ($isTrimmed) {
148  $arrKey = str_replace($keyTrimmer, '', $key);
149  }
150  if (is_numeric($arrKey)) {
151  $arrKey = 'Obj' . $arrKey;
152  }
153  if (is_object($node)) {
154  $result[$arrKey] = self::simpleXmlToArray($node, $keyTrimmer);
155  } elseif (is_array($node)) {
156  $result[$arrKey] = [];
157  foreach ($node as $nodeValue) {
158  $result[$arrKey][] = self::simpleXmlToArray($nodeValue, $keyTrimmer);
159  }
160  } else {
161  $result[$arrKey] = (string)$node;
162  }
163  }
164  } else {
165  $result = (string)$xml;
166  }
167  return $result;
168  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static simpleXmlToArray($xml, $keyTrimmer=null)
Definition: Api.php:135

◆ soapAdapterFaultCallback()

static soapAdapterFaultCallback (   $exceptionCode,
  $exceptionMessage 
)
static

Throw SoapFault exception. Callback for 'fault' method of API.

Parameters
string$exceptionCode
string$exceptionMessage
Exceptions

Definition at line 108 of file Api.php.

109  {
110  throw new \SoapFault($exceptionCode, $exceptionMessage);
111  }

Field Documentation

◆ $_previousHandler

$_previousHandler = null
staticprotected

Definition at line 17 of file Api.php.


The documentation for this class was generated from the following file: