Sanpi\Behatch\Json\JsonInspector::evaluate PHP Méthode

evaluate() public méthode

public evaluate ( Json $json, $expression )
$json Json
    public function evaluate(Json $json, $expression)
    {
        if ($this->evaluationMode === 'javascript') {
            $expression = str_replace('->', '.', $expression);
        }
        try {
            return $json->read($expression, $this->accessor);
        } catch (\Exception $e) {
            throw new \Exception("Failed to evaluate expression '{$expression}'");
        }
    }

Usage Example

Exemple #1
0
 /**
  * @Given /^the JSON node "([^"]*)" of the objects of the JSON node "([^"]*)" should contains "([^"]*)"$/
  * 
  * @param string $node
  * @param string $collection
  * @param string $arrayValue
  */
 public function theJSONNodeOfTheObjectsOfTheJSONNodeShouldContains($node, $collection, $arrayValue)
 {
     $accessor = PropertyAccess::createPropertyAccessor();
     $json = $this->getSession()->getPage()->getContent();
     $collection = $this->inspector->evaluate(new Json($json), $collection);
     foreach ($collection as $element) {
         in_array($arrayValue, $accessor->getValue($element, $node));
     }
 }
All Usage Examples Of Sanpi\Behatch\Json\JsonInspector::evaluate