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

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6083-hydrator-number…
Browse files Browse the repository at this point in the history
…-of-parameters-filter-honored'

Close zendframework/zendframework#6083
  • Loading branch information
Ocramius committed Apr 6, 2014
2 parents 802bf45 + 1e8208b commit 97a0260
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Hydrator/Filter/NumberOfParameterFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NumberOfParameterFilter implements FilterInterface
*/
public function __construct($numberOfParameters = 0)
{
$this->numberOfParameters = 0;
$this->numberOfParameters = (int) $numberOfParameters;
}

/**
Expand All @@ -44,10 +44,6 @@ public function filter($property)
);
}

if ($reflectionMethod->getNumberOfParameters() !== $this->numberOfParameters) {
return false;
}

return true;
return $reflectionMethod->getNumberOfParameters() === $this->numberOfParameters;
}
}
54 changes: 54 additions & 0 deletions test/Hydrator/Filter/NumberOfParameterFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Stdlib\Hydrator\Filter;

use Zend\Stdlib\Hydrator\Filter\NumberOfParameterFilter;

/**
* Unit tests for {@see \Zend\Stdlib\Hydrator\Filter\NumberOfParameterFilter}
*
* @covers \Zend\Stdlib\Hydrator\Filter\NumberOfParameterFilter
*/
class NumberOfParameterFilterTest extends \PHPUnit_Framework_TestCase
{
/**
* @group 6083
*/
public function testArityZero()
{
$filter = new NumberOfParameterFilter();
$this->assertTrue($filter->filter(__CLASS__ . '::methodWithNoParameters'));
$this->assertFalse($filter->filter(__CLASS__ . '::methodWithOptionalParameters'));
}

/**
* @group 6083
*/
public function testArityOne()
{
$filter = new NumberOfParameterFilter(1);
$this->assertFalse($filter->filter(__CLASS__ . '::methodWithNoParameters'));
$this->assertTrue($filter->filter(__CLASS__ . '::methodWithOptionalParameters'));
}

/**
* Test asset method
*/
public function methodWithOptionalParameters($parameter = 'foo')
{
}

/**
* Test asset method
*/
public function methodWithNoParameters()
{
}
}

0 comments on commit 97a0260

Please # to comment.