|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @title Tests two infintie commands sandwiched by a terminating command. |
| 5 | + * @command yes | head | yes |
| 6 | + * @expected y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n |
| 7 | + */ |
| 8 | + |
| 9 | +error_reporting(E_ALL); |
| 10 | + |
| 11 | +include __DIR__ . '/../vendor/autoload.php'; |
| 12 | + |
| 13 | +use ElvenSpellmaker\PipeSys as PS; |
| 14 | +use ElvenSpellmaker\PipeSys\Command as Command; |
| 15 | + |
| 16 | +$c = new PS\Scheduler(new Command\StandardConnector); |
| 17 | +$c->addCommand(new Command\Yes); |
| 18 | +$c->addCommand(new Command\Head(1)); |
| 19 | +$c->addCommand(new Command\Yes); |
| 20 | + |
| 21 | +$output = ''; |
| 22 | + |
| 23 | +if ($count = count($c->run(3)) !== 3) |
| 24 | +{ |
| 25 | + $output .= "Expecting 3 elements, received $count\n"; |
| 26 | +} |
| 27 | + |
| 28 | +$expected = [ |
| 29 | + 0 => 'ElvenSpellmaker\PipeSys\Command\Yes', |
| 30 | + 2 => 'ElvenSpellmaker\PipeSys\Command\Yes', |
| 31 | +]; |
| 32 | +$received = array_map('get_class', $c->run(1)); |
| 33 | + |
| 34 | +if ($received !== $expected) |
| 35 | +{ |
| 36 | + echo '<pre>'; |
| 37 | + var_dump($expected, $received); |
| 38 | + exit; |
| 39 | + |
| 40 | + $output .= "Expecting the head to be missing!\n"; |
| 41 | +} |
| 42 | + |
| 43 | +$expected = [2 => 'ElvenSpellmaker\PipeSys\Command\Yes']; |
| 44 | +$received = array_map('get_class', $c->run(1)); |
| 45 | + |
| 46 | +if ($received !== $expected) |
| 47 | +{ |
| 48 | + $output .= "Expecting the last yes to be present only!\n"; |
| 49 | +} |
| 50 | + |
| 51 | +if (! count($c->run(5))) |
| 52 | +{ |
| 53 | + $output .= "Command has terminated sometime before 10 runs!\n"; |
| 54 | +} |
| 55 | + |
| 56 | +echo $output; |
0 commit comments