Skip to content

Removing 2.4 dependency on property accessor #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2014
Merged
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
10 changes: 1 addition & 9 deletions src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Coduo\PHPMatcher\Matcher;

use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
use Symfony\Component\PropertyAccess\PropertyAccessor;

class ArrayMatcher extends Matcher
Expand Down Expand Up @@ -86,13 +85,7 @@ private function iterateMatch(array $value, array $pattern)
*/
private function hasValue($array, $path)
{
try {
$this->getPropertyAccessor()->getValue($array, $path);
} catch (NoSuchIndexException $e) {
return false;
}

return true;
return null !== $this->getPropertyAccessor()->getValue($array, $path);
}

/**
Expand All @@ -115,7 +108,6 @@ private function getPropertyAccessor()
}

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

return $this->accessor;
Expand Down
1 change: 0 additions & 1 deletion src/Coduo/PHPMatcher/Matcher/CaptureMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CaptureMatcher extends Matcher implements \ArrayAccess
public function match($value, $pattern)
{
$this->captures[$this->extractPattern($pattern)] = $value;

return true;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Coduo/PHPMatcher/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Coduo\PHPMatcher\Tests;

use Coduo\PHPMatcher\Matcher\ArrayMatcher;
use Coduo\PHPMatcher\Matcher\CaptureMatcher;
use Coduo\PHPMatcher\Matcher\ChainMatcher;
use Coduo\PHPMatcher\Matcher\ExpressionMatcher;
use Coduo\PHPMatcher\Matcher\JsonMatcher;
Expand All @@ -16,10 +17,16 @@ class MatcherTest extends \PHPUnit_Framework_TestCase

protected $arrayValue;

protected $captureMatcher;

public function setUp()
{
$this->captureMatcher = new CaptureMatcher();

$scalarMatchers = new ChainMatcher(array(
new ExpressionMatcher(),
$this->captureMatcher,
new CaptureMatcher(),
new TypeMatcher(),
new ScalarMatcher(),
new WildcardMatcher()
Expand Down Expand Up @@ -168,4 +175,13 @@ public function test_matcher_with_json()
$this->assertTrue($this->matcher->match($json, $jsonPattern));
$this->assertTrue(match($json, $jsonPattern));
}

public function test_matcher_with_captures()
{
$this->assertTrue($this->matcher->match(
array('foo' => 'bar', 'user' => array('id' => 5)),
array('foo' => 'bar', 'user' => array('id' => ':uid:'))
));
$this->assertEquals($this->captureMatcher['uid'], 5);
}
}