Skip to content

Commit a852c71

Browse files
Merge pull request #3 from michael-rubel/feature/pipeline-helper
Add `pipeline` helper
2 parents d265158 + f322c3c commit a852c71

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"autoload": {
3333
"psr-4": {
3434
"MichaelRubel\\EnhancedPipeline\\": "src"
35-
}
35+
},
36+
"files": [
37+
"src/Helpers/helpers.php"
38+
]
3639
},
3740
"autoload-dev": {
3841
"psr-4": {

src/Helpers/helpers.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use MichaelRubel\EnhancedPipeline\Pipeline;
6+
7+
if (! function_exists('pipeline')) {
8+
/**
9+
* @param mixed $passable
10+
* @param array|mixed $pipes
11+
*
12+
* @return Pipeline
13+
*/
14+
function pipeline($passable, $pipes): Pipeline
15+
{
16+
return app(Pipeline::class)
17+
->send($passable)
18+
->through($pipes);
19+
}
20+
}

tests/PipelineTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ public function rollsTheDatabaseTransactionBackOnFailureWhenOnFailureMethodUsed(
145145
$database->shouldHaveReceived('beginTransaction')->once();
146146
$database->shouldHaveReceived('rollBack')->once();
147147
}
148+
149+
/** @test */
150+
public function testPipelineHelper()
151+
{
152+
$test = pipeline('test', fn ($data, $next) => $next($data))
153+
->thenReturn();
154+
155+
$this->assertSame('test', $test);
156+
}
148157
}
149158

150159
class PipelineWithException

0 commit comments

Comments
 (0)