Skip to content

Commit 96e1004

Browse files
Merge pull request #15 from ElvenSpellmaker/feature/pipesys-examples
Adds examples and sets them up as tests.
2 parents a159449 + b225d15 commit 96e1004

File tree

14 files changed

+233
-7
lines changed

14 files changed

+233
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/vendor/
33
/bin/sca/phpcs.txt
44
/bin/sca/phpmd.html
5+
composer.lock

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
language: php
2+
23
php:
34
- '5.6'
45
- '7.0'
56
- hhvm
67
- nightly
8+
79
install: composer install
10+
11+
matrix:
12+
allow_failures:
13+
- php: hhvm
14+
815
script:
916
- ./vendor/bin/phpcs --standard=phpcs.xml src/
1017
- ./vendor/bin/phpmd src/ text phpmd.xml
18+
- ./bin/runtests.sh

bin/runtests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
BASEDIR=$(dirname $0)
4+
5+
php BASEDIR/../tests/TestRig.php

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
],
1313
"require-dev": {
1414
"ve-interactive/php-sniffer-rules": "dev-master",
15-
"ve-interactive/php-mess-detector": "*"
15+
"ve-interactive/php-mess-detector": "*",
16+
"phpdocumentor/reflection-docblock": "2.0.4"
1617
},
1718
"require": {
1819
"php": ">=5.6.0"

examples/GrepExample.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* @title Basic example to show grepping.
4+
* @command ChattyYes | grep 'Yes\|Chatty' | head
5+
* @expected Yes\nChatty\nYes\nChatty\nYes\nChatty\nYes\nChatty\nYes\nChatty\n
6+
*/
7+
8+
error_reporting(E_ALL);
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
use ElvenSpellmaker\PipeSys as PS;
13+
use ElvenSpellmaker\PipeSys\Command as Command;
14+
15+
$c = new PS\Scheduler(new Command\StandardConnector);
16+
$c->addCommand(new Command\ChattyYes);
17+
$c->addCommand(new Command\Grep('Yes|Chatty'));
18+
$c->addCommand(new Command\Head);
19+
$c->run();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* @title Example to show large head into smaller head.
4+
* @command ChattyYes | head -n 200 | head -n 7
5+
* @expected Yes\nI\nAm\nChatty\nYes\nI\nAm\n
6+
*/
7+
8+
error_reporting(E_ALL);
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
use ElvenSpellmaker\PipeSys as PS;
13+
use ElvenSpellmaker\PipeSys\Command as Command;
14+
15+
$c = new PS\Scheduler(new Command\StandardConnector);
16+
$c->addCommand(new Command\ChattyYes);
17+
$c->addCommand(new Command\Head(200));
18+
$c->addCommand(new Command\Head(7));
19+
$c->run();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* @title Example to show small head into larger head.
4+
* @command ChattyYes | head -n 5 | head
5+
* @expected Yes\nI\nAm\nChatty\nYes\n
6+
*/
7+
8+
error_reporting(E_ALL);
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
use ElvenSpellmaker\PipeSys as PS;
13+
use ElvenSpellmaker\PipeSys\Command as Command;
14+
15+
$c = new PS\Scheduler(new Command\StandardConnector);
16+
$c->addCommand(new Command\ChattyYes);
17+
$c->addCommand(new Command\Head(5));
18+
$c->addCommand(new Command\Head(10));
19+
$c->run();

examples/YesHeadExample.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* @title Basic example to show that `head` terminates `yes`.
4+
* @command yes | head
5+
* @expected y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n
6+
*/
7+
8+
error_reporting(E_ALL);
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
use ElvenSpellmaker\PipeSys as PS;
13+
use ElvenSpellmaker\PipeSys\Command as Command;
14+
15+
$c = new PS\Scheduler(new Command\StandardConnector);
16+
$c->addCommand(new Command\Yes);
17+
$c->addCommand(new Command\Head);
18+
$c->run();

examples/YesYesHeadExample.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* @title Tests two infinite commands and a terminating command.
4+
* @command yes | yes | head
5+
* @expected y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n
6+
*/
7+
8+
error_reporting(E_ALL);
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
use ElvenSpellmaker\PipeSys as PS;
13+
use ElvenSpellmaker\PipeSys\Command as Command;
14+
15+
$c = new PS\Scheduler(new Command\StandardConnector);
16+
$c->addCommand(new Command\Yes);
17+
$c->addCommand(new Command\Yes);
18+
$c->addCommand(new Command\Head);
19+
$c->run();

src/PipeSys/Command/ChattyYes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ChattyYes extends AbstractCommand
2121
public function __construct()
2222
{
2323
$this->chatting = [
24-
'Yes' . PHP_EOL,
25-
'I' . PHP_EOL,
26-
'Am' . PHP_EOL,
27-
'Chatty' . PHP_EOL,
24+
"Yes\n",
25+
"I\n",
26+
"Am\n",
27+
"Chatty\n",
2828
];
2929
}
3030

0 commit comments

Comments
 (0)