Skip to content

Commit

Permalink
Merge pull request #11 from defrag/fix/removing-2-4-deps
Browse files Browse the repository at this point in the history
Removing 2.4 dependency on property accessor
  • Loading branch information
norberttech committed May 22, 2014
2 parents 030b888 + c2a50b8 commit f6d7b7b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
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);
}
}

0 comments on commit f6d7b7b

Please sign in to comment.