Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Allow objects to be passed as pipes #13024

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Illuminate/Pipeline/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ protected function getSlice()
// the appropriate method and arguments, returning the results back out.
if ($pipe instanceof Closure) {
return call_user_func($pipe, $passable, $stack);
} else {
} elseif (! is_object($pipe)) {
list($name, $parameters) = $this->parsePipeString($pipe);

return call_user_func_array([$this->container->make($name), $this->method],
array_merge([$passable, $stack], $parameters));
$pipe = $this->container->make($name);
$parameters = array_merge([$passable, $stack], $parameters);
} else {
$parameters = [$passable, $stack];
}

return call_user_func_array([$pipe, $this->method], $parameters);
};
};
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Pipeline/PipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public function testPipelineBasicUsage()
unset($_SERVER['__test.pipe.two']);
}

public function testPipelineUsageWithObjects()
{
$result = (new Pipeline(new Illuminate\Container\Container))
->send('foo')
->through([new PipelineTestPipeOne])
->then(function ($piped) {
return $piped;
});

$this->assertEquals('foo', $result);
$this->assertEquals('foo', $_SERVER['__test.pipe.one']);

unset($_SERVER['__test.pipe.one']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to call this in a try, finally, otherwise if the assertion fails, it'll screw up the other tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell there is no exception catching in most of unit tests, moreover the previous one (line 17) will throw uncaught ReflectionException in case class does not exist, so it will be screwed up even without my test 😃

Time: 1.93 seconds, Memory: 64.00Mb

There were 3 errors:

1) PipelineTest::testPipelineBasicUsage
ReflectionException: Class PipelineTestPipeOne does not exist

/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Container/Container.php:738
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Container/Container.php:633
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Pipeline/Pipeline.php:122
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/tests/Pipeline/PipelineTest.php:20

2) PipelineTest::testPipelineUsageWithObjects
Error: Class 'PipelineTestPipeOne' not found

/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/tests/Pipeline/PipelineTest.php:34

3) PipelineTest::testPipelineViaChangesTheMethodBeingCalledOnThePipes
ReflectionException: Class PipelineTestPipeOne does not exist

/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Container/Container.php:738
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Container/Container.php:633
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Pipeline/Pipeline.php:122
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/likewise-open/FRAMGIA/roman.kinyakin/Code/framework/tests/Pipeline/PipelineTest.php:70

--

}

public function testPipelineUsageWithParameters()
{
$parameters = ['one', 'two'];
Expand Down