Skip to content

Commit 4cb4568

Browse files
committed
Removing 2.4 dependency on property accessor
1 parent 030b888 commit 4cb4568

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ private function iterateMatch(array $value, array $pattern)
8686
*/
8787
private function hasValue($array, $path)
8888
{
89-
try {
90-
$this->getPropertyAccessor()->getValue($array, $path);
91-
} catch (NoSuchIndexException $e) {
92-
return false;
93-
}
94-
95-
return true;
89+
return null !== $this->getPropertyAccessor()->getValue($array, $path);
9690
}
9791

9892
/**
@@ -115,7 +109,6 @@ private function getPropertyAccessor()
115109
}
116110

117111
$accessorBuilder = PropertyAccess::createPropertyAccessorBuilder();
118-
$accessorBuilder->enableExceptionOnInvalidIndex();
119112
$this->accessor = $accessorBuilder->getPropertyAccessor();
120113

121114
return $this->accessor;

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

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)