public function testJsonPathLocation() { $this->assertNotEmpty($this->jsonArray->filterByJsonPath('$..user')); $this->assertNotEmpty($this->jsonArray->filterByJsonPath('$.ticket.user.name')); $this->assertNotEmpty($this->jsonArray->filterByJsonPath('$..user.name')); $this->assertEquals(['Davert'], $this->jsonArray->filterByJsonPath('$.ticket.user.name')); }
public static function fromPhpType($phpValue) { if (is_numeric($phpValue)) { return new JsonNumber($phpValue); } if (is_string($phpValue)) { return new JsonString($phpValue); } if (is_array($phpValue)) { if (0 !== key($phpValue)) { $type = new JsonObject(); foreach ($phpValue as $key => $value) { $type->add($key, self::fromPhpType($value)); } } else { $type = new JsonArray(); foreach ($phpValue as $key => $value) { $type->add(self::fromPhpType($value)); } } return $type; } if (is_null($phpValue)) { return new JsonNull(); } if (is_bool($phpValue)) { return new JsonBoolean($phpValue); } throw new \InvalidArgumentException('Unknown value type'); }
/** * @Issue https://github.com/Codeception/Codeception/issues/2899 */ public function testInvalidXmlTag() { $jsonArray = new JsonArray('{"a":{"foo/bar":1,"":2},"b":{"foo/bar":1,"":2},"baz":2}'); $expectedXml = '<a><invalidTag1>1</invalidTag1><invalidTag2>2</invalidTag2></a><b><invalidTag1>1</invalidTag1><invalidTag2>2</invalidTag2></b><baz>2</baz>'; $this->assertContains($expectedXml, $jsonArray->toXml()->saveXML()); }
public function testContainsArrayComparesArrayWithValueRepeatedMultipleTimesCorrectlyPositiveCase() { $jsonArray = new JsonArray(json_encode(['foo', 'foo', 'bar'])); $expectedArray = ['foo', 'bar', 'foo']; $this->assertTrue($jsonArray->containsArray($expectedArray)); }
/** * Set a value. * * @param string $path The path of the value. * * @param mixed $value The value to set. * * @return JsonFile */ public function set($path, $value) { parent::set($path, $value); $this->save(); return $this; }
/** * Simplified testcase for issue reproduced by testContainsArrayWithUnexpectedLevel */ public function testContainsArrayComparesSequentialArraysHavingDuplicateSubArraysCorrectly() { $jsonArray = new JsonArray('[[1],[1]]'); $expectedArray = [[1], [1]]; $this->assertTrue($jsonArray->containsArray($expectedArray), "- <info>" . var_export($expectedArray, true) . "</info>\n" . "+ " . var_export($jsonArray->toArray(), true)); }
public function generateJsonConfiguration($records) { //$this->setDoc($doc = new DOMDocument()); $json = new JsonObject(); $json->withValue('record_finder', 'record_finder'); $json->withValue('title', $this->getTitle()); $collectionSearchFields = new SearchableReadonlyCollection(); $collectionSearchFields->addAll($this->searchFields); $json->withObject('search_fields', $this->searchFields()); $collectionTitles = new SearchableReadonlyCollection(); $collectionTitles->addAll($this->titleFields); $json->withObject('record_title', $collectionTitles); $collectionDescriptions = new SearchableReadonlyCollection(); $collectionDescriptions->addAll($this->descriptionFields); $json->withObject('record_description', $collectionDescriptions); $mapper = new AsyncSearchRecordMapper(); foreach ($this->searchFields as $searchField) { $mapper->addField($searchField); } foreach ($this->titleFields as $titleField) { $mapper->addField($titleField); } foreach ($this->descriptionFields as $descriptionField) { $mapper->addField($descriptionField); } $jsonArray = new JsonArray(); if ($records != null) { foreach ($records as $record) { $jsonObject = $mapper->generateJson($record); $jsonArray->addObject($jsonObject); } } $json->addArray('records', $jsonArray); return $json; }
/** * Create document from array * * @param mixed[] $data * @param string|object $className * @param AnnotatedInterface $instance * @return AnnotatedInterface * @throws TransformatorException */ public static function toModel($data, $className = null, AnnotatedInterface $instance = null) { return JsonArray::toModel(json_decode($data, true), $className, $instance); }