Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ matrix:
env: DEPENDENCIES='low'
- php: 7.2
- php: 7.3
- php: 7.4

before_install:
- composer self-update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PHPMatcher::error() : ?string;
It was built to simplify API's functional testing.

* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - [5.0 (master) README](https://github.com/coduo/php-matcher/tree/master/README.md) PHP >= 7.2
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=4.0)](https://travis-ci.org/coduo/php-matcher) - [4.0 (master) README](https://github.com/coduo/php-matcher/tree/4.0/README.md) PHP >= 7.2
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=4.0)](https://travis-ci.org/coduo/php-matcher) - [4.0.* README](https://github.com/coduo/php-matcher/tree/4.0/README.md) PHP >= 7.2
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.2)](https://travis-ci.org/coduo/php-matcher) - [3.2.* README](https://github.com/coduo/php-matcher/tree/3.2/README.md) PHP >= 7.0
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.1)](https://travis-ci.org/coduo/php-matcher) - [3.1.* README](https://github.com/coduo/php-matcher/tree/3.1/README.md) PHP >= 7.0

Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"ext-filter": "*",
"ext-json": "*",
"coduo/php-to-string": "^3",
"symfony/property-access": "^2.3|^3.0|^4.0|^5.0",
"symfony/expression-language": "^2.3|^3.0|^4.0|^5.0",
"doctrine/lexer": "^1.0",
"openlss/lib-array2xml": "^1.0"
Expand Down
40 changes: 7 additions & 33 deletions src/Matcher/ArrayMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Coduo\PHPMatcher\Exception\Exception;
use Coduo\PHPMatcher\Parser;
use Coduo\ToString\StringConverter;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyAccess\PropertyPath;

final class ArrayMatcher extends Matcher
{
Expand Down Expand Up @@ -187,25 +184,9 @@ private function valueMatchPattern($value, $pattern) : bool

private function valueExist(string $path, array $haystack) : bool
{
$propertyPath = new PropertyPath($path);
$length = $propertyPath->getLength();
$valueExist = true;
for ($i = 0; $i < $length; ++$i) {
$property = $propertyPath->getElement($i);
$isIndex = $propertyPath->isIndex($i);
$propertyExist = $this->arrayPropertyExists($property, $haystack);

if ($isIndex && !$propertyExist) {
$valueExist = false;
break;
}
}

unset($propertyPath);
return $valueExist;
return $this->arrayPropertyExists($this->getKeyFromAccessPath($path), $haystack);
}


private function arrayPropertyExists(string $property, array $objectOrArray) : bool
{
return ($objectOrArray instanceof \ArrayAccess && isset($objectOrArray[$property])) ||
Expand All @@ -214,19 +195,7 @@ private function arrayPropertyExists(string $property, array $objectOrArray) : b

private function getValueByPath(array $array, string $path)
{
return $this->getPropertyAccessor()->getValue($array, $path);
}

private function getPropertyAccessor() : PropertyAccessorInterface
{
if (isset($this->accessor)) {
return $this->accessor;
}

$accessorBuilder = PropertyAccess::createPropertyAccessorBuilder();
$this->accessor = $accessorBuilder->getPropertyAccessor();

return $this->accessor;
return $array[$this->getKeyFromAccessPath($path)];
}

private function setMissingElementInError(string $place, string $path)
Expand All @@ -239,6 +208,11 @@ private function formatAccessPath($key) : string
return \sprintf('[%s]', $key);
}

private function getKeyFromAccessPath(string $path) : string
{
return \substr($path, 1, -1);
}

private function formatFullPath(string $parentPath, string $path) : string
{
return \sprintf('%s%s', $parentPath, $path);
Expand Down
1 change: 1 addition & 0 deletions tests/Matcher/ArrayMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public static function positiveMatchData()
],
$simpleArrPattern,
],
[['foo[key]' => 'value'], ['foo[key]' => '@string@']]
];
}

Expand Down