├── phpspec.yml.dist ├── screenshots └── formatters │ ├── cat.gif │ ├── crab.gif │ └── dino.gif ├── composer.json ├── src └── PhpSpec │ └── NyanFormattersExtension │ ├── Formatter │ ├── CrabFormatter.php │ ├── DinoFormatter.php │ └── NyanFormatter.php │ └── Extension.php ├── LICENSE └── README.md /phpspec.yml.dist: -------------------------------------------------------------------------------- 1 | extensions: 2 | PhpSpec\NyanFormattersExtension\Extension: ~ 3 | -------------------------------------------------------------------------------- /screenshots/formatters/cat.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpspec/nyan-formatters/HEAD/screenshots/formatters/cat.gif -------------------------------------------------------------------------------- /screenshots/formatters/crab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpspec/nyan-formatters/HEAD/screenshots/formatters/crab.gif -------------------------------------------------------------------------------- /screenshots/formatters/dino.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpspec/nyan-formatters/HEAD/screenshots/formatters/dino.gif -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpspec/nyan-formatters", 3 | "description": "PHPSpec Nyan Formatter Extension", 4 | "type": "extension", 5 | "keywords": ["phpspec", "nyan"], 6 | "homepage": "https://github.com/phpspec/nyan-formatters", 7 | "license": "MIT", 8 | "require": { 9 | "php": ">=5.3.3", 10 | "phpspec/phpspec": "~3.0|~4.0|~5.0|~6.0", 11 | "whatthejeff/nyancat-scoreboard": "~1.1" 12 | }, 13 | "autoload": { 14 | "psr-0": { 15 | "PhpSpec\\NyanFormattersExtension": "src/" 16 | } 17 | }, 18 | "authors": [ 19 | { 20 | "name": "Matthew Davis", 21 | "email": "matt@mattdavis.co.uk" 22 | }, 23 | { 24 | "name": "Jeff Welch", 25 | "email": "whatthejeff@gmail.com" 26 | } 27 | ], 28 | "extra": { 29 | "branch-alias": { 30 | "dev-master": "1.0.x-dev" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PhpSpec/NyanFormattersExtension/Formatter/CrabFormatter.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class CrabFormatter extends NyanFormatter 13 | { 14 | protected $states = 15 | array( 16 | array( 17 | '| | ', 18 | ' \/ Y', 19 | ' | /%-%\ |', 20 | ' \| |/ ', 21 | ' _\___/_ ', 22 | ' / / \ \ ' 23 | ), 24 | array( 25 | ' /\ ', 26 | ' \/ Y', 27 | ' | /%-%\ |', 28 | ' \| |/ ', 29 | ' _\___/_ ', 30 | ' / / \ \ ' 31 | ), 32 | array( 33 | ' /\ ', 34 | ' \/ |', 35 | ' | /%-%\ |', 36 | ' \| |/ ', 37 | ' _\___/_ ', 38 | ' / / \ \ ' 39 | ), 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2014 Matthew Davis 2 | Jeff Welch 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/PhpSpec/NyanFormattersExtension/Formatter/DinoFormatter.php: -------------------------------------------------------------------------------- 1 | 12 | * @author Matthew Davis 13 | */ 14 | class DinoFormatter extends NyanFormatter 15 | { 16 | protected $states = 17 | array( 18 | array( 19 | ' ___ ', 20 | ' / %_) ', 21 | ' _.----./ / ', 22 | ' / / ', 23 | ' __/ ( | ( | ', 24 | "/__.-'|_|--|_| " 25 | ), 26 | array( 27 | ' ___ ', 28 | ' / %_)', 29 | ' _.----._/ / ', 30 | ' / / ', 31 | ' __/ ( | ( | ', 32 | "/__.-|_|--|_| " 33 | ), 34 | array( 35 | ' ___ ', 36 | ' / %_) ', 37 | ' _.----._/ / ', 38 | ' / / ', 39 | ' _/ ( / / / ', 40 | "/_/-|_/--|_/ " 41 | ) 42 | ); 43 | } 44 | -------------------------------------------------------------------------------- /src/PhpSpec/NyanFormattersExtension/Extension.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class Extension implements PhpSpecExtension 16 | { 17 | /** 18 | * {@inheritdoc} 19 | */ 20 | public function load(ServiceContainer $container, array $params) 21 | { 22 | $this->addFormatter($container, 'cat', 'PhpSpec\NyanFormattersExtension\Formatter\NyanFormatter'); 23 | $this->addFormatter($container, 'dino', 'PhpSpec\NyanFormattersExtension\Formatter\DinoFormatter'); 24 | $this->addFormatter($container, 'crab', 'PhpSpec\NyanFormattersExtension\Formatter\CrabFormatter'); 25 | } 26 | 27 | /** 28 | * Add a formatter to the service container 29 | * 30 | * @param ServiceContainer $container 31 | * @param string $name 32 | * @param string $class 33 | */ 34 | protected function addFormatter(ServiceContainer $container, $name, $class) 35 | { 36 | $container->define('formatter.formatters.nyan.' . $name, function ($c) use ($class) { 37 | /** @var ServiceContainer $c */ 38 | return new $class( 39 | $c->get('formatter.presenter'), 40 | $c->get('console.io'), 41 | $c->get('event_dispatcher.listeners.stats') 42 | ); 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHPSpec Nyan Formatters Extension 2 | This PHPSpec extension provides Nyan formatters for PHPSpec. 3 | 4 | ## Requirements 5 | 6 | This extension requires: 7 | 8 | * PHP 5.3.3 or later. 9 | * A terminal emulator with support for ANSI escape sequences, including color 10 | and cursor control. 11 | 12 | **NOTE:** By default, the Windows console does not support ANSI escape 13 | sequences. If you'd like to use this extension on Windows, you may want 14 | to try one of the following solutions: 15 | 16 | * [ANSICON](https://github.com/adoxa/ansicon) 17 | * [ConEmu](https://github.com/Maximus5/ConEmu) 18 | 19 | 20 | ## Installation 21 | To install this, make sure you are using the latest release of PHPSpec, and then add the following to your 22 | `composer.json`: 23 | 24 | ```json 25 | "require-dev": { 26 | ..., 27 | "phpspec/nyan-formatters": "2.*" 28 | } 29 | ``` 30 | 31 | Install or update your dependencies, and then in a `phpspec.yml` file in the root of your project, add the following: 32 | 33 | ```yaml 34 | extensions: 35 | PhpSpec\NyanFormattersExtension\Extension: ~ 36 | ``` 37 | 38 | Then, you can add a `--format` switch to your `phpspec` command with one of the following values: 39 | 40 | - `nyan.cat` - Gives the standard Nyan Cat formatter 41 | 42 | ![nyan cat formatter preview](screenshots/formatters/cat.gif) 43 | 44 | - `nyan.dino` - Gives a dinosaur formatter - Rawwr! 45 | 46 | ![nyan dino formatter preview](screenshots/formatters/dino.gif) 47 | 48 | - `nyan.crab` - Gives a crab formatter 49 | 50 | ![nyan crab formatter preview](screenshots/formatters/crab.gif) 51 | 52 | If you want to use one of the formatters all the time, you can enforce a default by adding a `formatter.name` option in 53 | the `phpspec.yml` file as follows: 54 | 55 | ```yaml 56 | formatter.name: nyan.dino 57 | ``` 58 | 59 | ## Authors 60 | This project was written by: 61 | 62 | - [Matthew Davis](https://twitter.com/mdavis1982) 63 | - [Jeff Welch](https://twitter.com/whatthejeff) 64 | 65 | ## Contributions 66 | This project wouldn't have been possible without the help and support of the following people: 67 | 68 | - [Marcello Duarte](https://twitter.com/_md) 69 | - [Jakub Zalas](https://twitter.com/jakub_zalas) 70 | - [Christophe Coevoet](https://twitter.com/stof70) 71 | - [Ciaran McNulty](https://twitter.com/ciaranmcnulty) 72 | - [Wouter J](https://github.com/wouterj) 73 | -------------------------------------------------------------------------------- /src/PhpSpec/NyanFormattersExtension/Formatter/NyanFormatter.php: -------------------------------------------------------------------------------- 1 | 22 | * @author Matthew Davis 23 | */ 24 | class NyanFormatter extends ConsoleFormatter 25 | { 26 | /** 27 | * The number of examples 28 | * 29 | * @var integer 30 | */ 31 | private $examplesCount = 0; 32 | 33 | /** 34 | * The Nyan scoreboard 35 | * 36 | * @var ScoreBoard 37 | */ 38 | private $scoreboard; 39 | 40 | /** 41 | * The states for the scoreboard (character definition) 42 | * 43 | * @var null|array 44 | */ 45 | protected $states = null; 46 | 47 | /** 48 | * Actions to perform before the test suite 49 | * 50 | * @param SuiteEvent $event 51 | */ 52 | public function beforeSuite(SuiteEvent $event) 53 | { 54 | $io = $this->getIO(); 55 | if (!$io->isDecorated()) { 56 | return parent::beforeSuite($event); 57 | } 58 | 59 | $this->examplesCount = count($event->getSuite()); 60 | $length = strlen((string) $this->examplesCount) + 1; 61 | 62 | $this->scoreboard = new Scoreboard( 63 | new Cat($this->states), 64 | new Rainbow( 65 | FabFactory::getFab( 66 | empty($_SERVER['TERM']) ? 'unknown' : $_SERVER['TERM'] 67 | ), 68 | array('-', '_'), 69 | 39 - $length 70 | ), 71 | array( 72 | new Team('pass', 'green', '^'), 73 | new Team('pending', 'yellow', '-'), 74 | new Team('fail', 'red', 'o'), 75 | new Team('broken', 'magenta', 'o'), 76 | ), 77 | 5, 78 | array($this->getIO(), 'write') 79 | ); 80 | } 81 | 82 | /** 83 | * Actions to perform after each example 84 | * 85 | * @param ExampleEvent $event 86 | */ 87 | public function afterExample(ExampleEvent $event) 88 | { 89 | $io = $this->getIO(); 90 | if (!$io->isDecorated()) { 91 | return parent::afterExample($event); 92 | } 93 | 94 | $eventsCount = $this->getStatisticsCollector()->getEventsCount(); 95 | if ($eventsCount === 1) { 96 | $io->writeln(); 97 | 98 | if ($io->isDecorated()) { 99 | $this->scoreboard->start(); 100 | } 101 | } 102 | 103 | switch ($event->getResult()) { 104 | case ExampleEvent::PASSED: 105 | $this->scoreboard->score('pass'); 106 | break; 107 | case ExampleEvent::PENDING: 108 | $this->scoreboard->score('pending'); 109 | break; 110 | case ExampleEvent::FAILED: 111 | $this->scoreboard->score('fail'); 112 | break; 113 | case ExampleEvent::BROKEN: 114 | $this->scoreboard->score('broken'); 115 | break; 116 | } 117 | } 118 | 119 | /** 120 | * Actions to perform after the test suite 121 | * 122 | * @param SuiteEvent $event 123 | */ 124 | public function afterSuite(SuiteEvent $event) 125 | { 126 | $io = $this->getIO(); 127 | if (!$io->isDecorated()) { 128 | return parent::afterSuite($event); 129 | } 130 | 131 | $this->scoreboard->stop(); 132 | $io->writeln(); 133 | 134 | $stats = $this->getStatisticsCollector(); 135 | 136 | foreach (array( 137 | 'failed' => $stats->getFailedEvents(), 138 | 'broken' => $stats->getBrokenEvents(), 139 | 'pending' => $stats->getPendingEvents() 140 | ) as $events) { 141 | if (!count($events)) { 142 | continue; 143 | } 144 | 145 | foreach ($events as $failEvent) { 146 | $this->printException($failEvent); 147 | } 148 | } 149 | 150 | $counts = array(); 151 | foreach ($stats->getCountsHash() as $type => $count) { 152 | if ($count) { 153 | $counts[] = sprintf('<%s>%d %s', $type, $count, $type, $type); 154 | } 155 | } 156 | 157 | $count = $stats->getEventsCount(); 158 | $plural = $count !== 1 ? 's' : ''; 159 | $io->write(sprintf("%d example%s ", $count, $plural)); 160 | if (count($counts)) { 161 | $io->write(sprintf("(%s)", implode(', ', $counts))); 162 | } 163 | 164 | $io->writeln(sprintf("\n%sms", round($event->getTime() * 1000))); 165 | } 166 | } 167 | --------------------------------------------------------------------------------