-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from darkwood-fr/lambda-rail
✨ Add Lambda Rail
- Loading branch information
Showing
10 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/.phpunit.result.cache | ||
/.php-cs-fixer.cache | ||
/.php_cs.cache | ||
/build/ | ||
/composer.lock | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RFBP\Rail; | ||
|
||
use Closure; | ||
use loophp\combinator\Combinators; | ||
use RFBP\DriverInterface; | ||
use RFBP\IpStrategyInterface; | ||
|
||
class LambdaRail extends RailDecorator | ||
{ | ||
public function __construct(Closure $job, ?IpStrategyInterface $ipStrategy = null, ?DriverInterface $driver = null) | ||
{ | ||
parent::__construct(new Rail(Combinators::Y()($job), $ipStrategy, $driver)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RFBP\Test\Rail; | ||
|
||
use ArrayObject; | ||
use Closure; | ||
use RFBP\DriverInterface; | ||
use RFBP\Ip; | ||
use RFBP\IpStrategyInterface; | ||
use RFBP\Rail\LambdaRail; | ||
use Throwable; | ||
|
||
class LambdaRailTest extends AbstractRailTest | ||
{ | ||
/** | ||
* @dataProvider jobProvider | ||
*/ | ||
public function testJob(DriverInterface $driver, IpStrategyInterface $ipStrategy, Closure $job, int $resultNumber, ?Throwable $resultException): void | ||
{ | ||
$ip = new Ip(new ArrayObject(['number' => 6])); | ||
$lambdaRail = new LambdaRail($job, $ipStrategy, $driver); | ||
$lambdaRail->pipe(function (Ip $ip, ?Throwable $exception) use ($driver, $resultNumber, $resultException) { | ||
$driver->stop(); | ||
self::assertSame(ArrayObject::class, $ip->getData()::class); | ||
self::assertSame($resultNumber, $ip->getData()['number']); | ||
self::assertSame($resultException, $exception); | ||
}); | ||
($lambdaRail)($ip); | ||
|
||
$driver->run(); | ||
} | ||
|
||
/** | ||
* @return array<array> | ||
*/ | ||
public function jobProvider(): array | ||
{ | ||
return $this->matrix([ | ||
'job' => [static function (callable $function): Closure { | ||
return static function (ArrayObject $data) use ($function) { | ||
if($data['number'] > 1) { | ||
$calcData = new ArrayObject(['number' => $data['number'] - 1]); | ||
$function($calcData); | ||
$data['number'] = $data['number'] * $calcData['number']; | ||
} else { | ||
$data['number'] = 1; | ||
} | ||
}; | ||
}, 720, null], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters