Skip to content

Commit f58a733

Browse files
authored
[10.x] Add Conditionable to Pipeline (#49429)
* [10.x] Add Conditionable to Pipeline * fix test
1 parent 3e6b81e commit f58a733

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Illuminate/Pipeline/Pipeline.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
use Closure;
66
use Illuminate\Contracts\Container\Container;
77
use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract;
8+
use Illuminate\Support\Traits\Conditionable;
89
use RuntimeException;
910
use Throwable;
1011

1112
class Pipeline implements PipelineContract
1213
{
14+
use Conditionable;
15+
1316
/**
1417
* The container implementation.
1518
*

tests/Pipeline/PipelineTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,36 @@ public function testPipelineThenReturnMethodRunsPipelineThenReturnsPassable()
243243

244244
unset($_SERVER['__test.pipe.one']);
245245
}
246+
247+
public function testPipelineConditionable()
248+
{
249+
$result = (new Pipeline(new Container))
250+
->send('foo')
251+
->when(true, function (Pipeline $pipeline) {
252+
$pipeline->pipe([PipelineTestPipeOne::class]);
253+
})
254+
->then(function ($piped) {
255+
return $piped;
256+
});
257+
258+
$this->assertSame('foo', $result);
259+
$this->assertSame('foo', $_SERVER['__test.pipe.one']);
260+
unset($_SERVER['__test.pipe.one']);
261+
262+
$_SERVER['__test.pipe.one'] = null;
263+
$result = (new Pipeline(new Container))
264+
->send('foo')
265+
->when(false, function (Pipeline $pipeline) {
266+
$pipeline->pipe([PipelineTestPipeOne::class]);
267+
})
268+
->then(function ($piped) {
269+
return $piped;
270+
});
271+
272+
$this->assertSame('foo', $result);
273+
$this->assertNull($_SERVER['__test.pipe.one']);
274+
unset($_SERVER['__test.pipe.one']);
275+
}
246276
}
247277

248278
class PipelineTestPipeOne

0 commit comments

Comments
 (0)