Skip to content

Commit

Permalink
Let PHP take care of all missing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Mar 8, 2018
1 parent c5d0551 commit 01e342f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
12 changes: 0 additions & 12 deletions src/Pipeline/Principal.php
Expand Up @@ -43,18 +43,6 @@ public function __construct(\Traversable $input = null)

public function map(callable $func)
{
// verify that an initial generator does not require any parameters whatsoever
assert($this->pipeline || 0 == call_user_func(function () use ($func) {
if ($func instanceof \Closure || !is_object($func)) {
// even if a closure is a generator, its __invoke method is not;
// therefore we should consider a closure as a function
return (new \ReflectionFunction($func))->getNumberOfRequiredParameters();
}

// objects go by their magic method
return (new \ReflectionMethod($func, '__invoke'))->getNumberOfRequiredParameters();
}), 'Initial callback must not require any parameters.');

if (!$this->pipeline) {
$this->pipeline = call_user_func($func);

Expand Down
19 changes: 3 additions & 16 deletions tests/Pipeline/ErrorsTest.php
Expand Up @@ -17,27 +17,14 @@

namespace Pipeline;

use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;

class ErrorsTest extends TestCase
{
protected function setUp()
public function testInvalidInitialGeneratorWithArguments()
{
if (ini_get('zend.assertions') != 1 || ini_get('assert.exception') != 1) {
$this->markTestSkipped('This test case requires internal assertions to throw up.');
}
}

public function testAssertFalse()
{
$this->expectException(\AssertionError::class);
assert(false);
}

public function testInvalidInitialGenerator()
{
$this->expectException(\AssertionError::class);
$this->expectExceptionMessage('Initial callback must not require any parameters.');
$this->expectException(Warning::class);

$pipeline = new Simple();
$pipeline->map(function ($a) {
Expand Down

0 comments on commit 01e342f

Please sign in to comment.