Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #73 from codisart/add-test-filter
Browse files Browse the repository at this point in the history
Clean some code and add some unit tests.
  • Loading branch information
weierophinney committed Apr 30, 2018
2 parents a6a7b84 + 3f264d1 commit 399809d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/Filter/HasFilter.php
Expand Up @@ -20,9 +20,6 @@ public function filter($property)
$pos = 0;
}

if (substr($property, $pos, 3) === 'has') {
return true;
}
return false;
return substr($property, $pos, 3) === 'has';
}
}
5 changes: 1 addition & 4 deletions src/Filter/IsFilter.php
Expand Up @@ -20,9 +20,6 @@ public function filter($property)
$pos = 0;
}

if (substr($property, $pos, 2) === 'is') {
return true;
}
return false;
return substr($property, $pos, 2) === 'is';
}
}
1 change: 1 addition & 0 deletions src/Filter/MethodMatchFilter.php
Expand Up @@ -41,6 +41,7 @@ public function filter($property)
} else {
$pos = 0;
}

if (substr($property, $pos) === $this->method) {
return ! $this->exclude;
}
Expand Down
12 changes: 6 additions & 6 deletions test/Filter/FilterCompositeTest.php
Expand Up @@ -75,18 +75,18 @@ public function getDataProvider()
'exception' => true
],
[
['foo' => (new HasFilter())],
['bar' => (new GetFilter())],
['foo' => new HasFilter],
['bar' => new GetFilter],
'exception' => false
],
[
[
'foo1' => (new HasFilter()),
'foo2' => (new IsFilter()),
'foo1' => new HasFilter,
'foo2' => new IsFilter,
],
[
'bar1' => (new GetFilter()),
'bar2' => (new NumberOfParameterFilter())
'bar1' => new GetFilter,
'bar2' => new NumberOfParameterFilter,
],
'exception' => false
]
Expand Down
36 changes: 36 additions & 0 deletions test/Filter/MethodMatchFilterTest.php
@@ -0,0 +1,36 @@
<?php
/**
* @see https://github.com/zendframework/zend-hydrator for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-hydrator/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Hydrator\Filter;

use PHPUnit\Framework\TestCase;
use Zend\Hydrator\Filter\MethodMatchFilter;

class MethodMatchFilterTest extends TestCase
{
public function providerFilter()
{
return [
['foo', true,],
['bar', false,],
['class::foo', true,],
['class::bar', false,],
];
}

/**
* @dataProvider providerFilter
*/
public function testFilter($methodName, $expected)
{
$testedInstance = new MethodMatchFilter('foo', false);
self::assertEquals($expected, $testedInstance->filter($methodName));

$testedInstance = new MethodMatchFilter('foo', true);
self::assertEquals(! $expected, $testedInstance->filter($methodName));
}
}

0 comments on commit 399809d

Please sign in to comment.