Skip to content

Commit e6828ef

Browse files
fink3ltheofidry
authored andcommitted
Add filter prepend method (#132)
1 parent 3e01bda commit e6828ef

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/DeepCopy/DeepCopy.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public function addFilter(Filter $filter, Matcher $matcher)
9999
];
100100
}
101101

102+
public function prependFilter(Filter $filter, Matcher $matcher)
103+
{
104+
array_unshift($this->filters, [
105+
'matcher' => $matcher,
106+
'filter' => $filter,
107+
]);
108+
}
109+
102110
public function addTypeFilter(TypeFilter $filter, TypeMatcher $matcher)
103111
{
104112
$this->typeFilters[] = [

tests/DeepCopyTest/DeepCopyTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@ public function test_matchers_can_access_to_parent_private_properties()
424424
$this->assertNull($copy->getFoo());
425425
}
426426

427+
public function test_it_can_prepend_filter()
428+
{
429+
$object = new f008\A('bar');
430+
$deepCopy = new DeepCopy();
431+
$deepCopy->addFilter(new KeepFilter(), new PropertyNameMatcher('foo'));
432+
$deepCopy->prependFilter(new SetNullFilter(), new PropertyNameMatcher('foo'));
433+
$copy = $deepCopy->copy($object);
434+
$this->assertNull($copy->getFoo());
435+
}
436+
427437
private function assertEqualButNotSame($expected, $val)
428438
{
429439
$this->assertEquals($expected, $val);

0 commit comments

Comments
 (0)