Skip to content

Commit f6d7b7b

Browse files
committed
Merge pull request #11 from defrag/fix/removing-2-4-deps
Removing 2.4 dependency on property accessor
2 parents 030b888 + c2a50b8 commit f6d7b7b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Diff for: src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Coduo\PHPMatcher\Matcher;
44

55
use Symfony\Component\PropertyAccess\PropertyAccess;
6-
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
76
use Symfony\Component\PropertyAccess\PropertyAccessor;
87

98
class ArrayMatcher extends Matcher
@@ -86,13 +85,7 @@ private function iterateMatch(array $value, array $pattern)
8685
*/
8786
private function hasValue($array, $path)
8887
{
89-
try {
90-
$this->getPropertyAccessor()->getValue($array, $path);
91-
} catch (NoSuchIndexException $e) {
92-
return false;
93-
}
94-
95-
return true;
88+
return null !== $this->getPropertyAccessor()->getValue($array, $path);
9689
}
9790

9891
/**
@@ -115,7 +108,6 @@ private function getPropertyAccessor()
115108
}
116109

117110
$accessorBuilder = PropertyAccess::createPropertyAccessorBuilder();
118-
$accessorBuilder->enableExceptionOnInvalidIndex();
119111
$this->accessor = $accessorBuilder->getPropertyAccessor();
120112

121113
return $this->accessor;

Diff for: src/Coduo/PHPMatcher/Matcher/CaptureMatcher.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class CaptureMatcher extends Matcher implements \ArrayAccess
1414
public function match($value, $pattern)
1515
{
1616
$this->captures[$this->extractPattern($pattern)] = $value;
17-
1817
return true;
1918
}
2019

Diff for: tests/Coduo/PHPMatcher/MatcherTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Coduo\PHPMatcher\Tests;
33

44
use Coduo\PHPMatcher\Matcher\ArrayMatcher;
5+
use Coduo\PHPMatcher\Matcher\CaptureMatcher;
56
use Coduo\PHPMatcher\Matcher\ChainMatcher;
67
use Coduo\PHPMatcher\Matcher\ExpressionMatcher;
78
use Coduo\PHPMatcher\Matcher\JsonMatcher;
@@ -16,10 +17,16 @@ class MatcherTest extends \PHPUnit_Framework_TestCase
1617

1718
protected $arrayValue;
1819

20+
protected $captureMatcher;
21+
1922
public function setUp()
2023
{
24+
$this->captureMatcher = new CaptureMatcher();
25+
2126
$scalarMatchers = new ChainMatcher(array(
2227
new ExpressionMatcher(),
28+
$this->captureMatcher,
29+
new CaptureMatcher(),
2330
new TypeMatcher(),
2431
new ScalarMatcher(),
2532
new WildcardMatcher()
@@ -168,4 +175,13 @@ public function test_matcher_with_json()
168175
$this->assertTrue($this->matcher->match($json, $jsonPattern));
169176
$this->assertTrue(match($json, $jsonPattern));
170177
}
178+
179+
public function test_matcher_with_captures()
180+
{
181+
$this->assertTrue($this->matcher->match(
182+
array('foo' => 'bar', 'user' => array('id' => 5)),
183+
array('foo' => 'bar', 'user' => array('id' => ':uid:'))
184+
));
185+
$this->assertEquals($this->captureMatcher['uid'], 5);
186+
}
171187
}

0 commit comments

Comments
 (0)