├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── composer.json ├── lib ├── Handlers │ └── LolHandler.php ├── Lolifier.php ├── Lolifiers │ ├── Blackout.php │ ├── Confuse.php │ ├── GeekTime.php │ ├── Hangman.php │ ├── Hash.php │ ├── LaMerNoire.php │ ├── Mirror.php │ ├── NotGiveAFuck.php │ ├── NullLolifier.php │ ├── NyanCat.php │ ├── Quote.php │ ├── QuoteProvider.php │ ├── QuoteProviders │ │ ├── Collection.php │ │ ├── EmptyQuoteProvider.php │ │ └── Kaamelott │ │ │ ├── Gauvain.php │ │ │ ├── Kadoc.php │ │ │ ├── Karadoc.php │ │ │ ├── Merlin.php │ │ │ ├── Perceval.php │ │ │ └── Yvain.php │ ├── Shuffle.php │ ├── SwearWordsProvider.php │ ├── SwearWordsProviders │ │ └── DefaultProvider.php │ ├── Tourette.php │ ├── Warp.php │ ├── Yell.php │ └── Yolo.php └── Referentials │ └── MonologLevel.php ├── phpunit.xml └── tests ├── Handlers └── LolHandlerTest.php ├── Lolifiers ├── BlackoutTest.php ├── ConfuseTest.php ├── GeekTimeTest.php ├── HangmanTest.php ├── HashTest.php ├── LaMerNoireTest.php ├── MirrorTest.php ├── NotGiveAFuckTest.php ├── NyanCatTest.php ├── QuoteProviders │ └── CollectionTest.php ├── QuoteTest.php ├── ShuffleTest.php ├── TouretteTest.php ├── WarpTest.php ├── YellTest.php └── YoloTest.php └── bootstrap.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse files 2 | .settings/ 3 | .buildpath 4 | .project 5 | 6 | # Composer files 7 | vendor/ 8 | composer.phar 9 | composer.lock 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | 8 | before_script: 9 | - composer install --dev 10 | 11 | script: 12 | - vendor/bin/phpunit 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PHPointless 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Monolol 2 | ======= 3 | 4 | PSR-3 compliant lol-gger 5 | 6 | QA 7 | -- 8 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/dbeb0236-21a3-49be-9ee3-1585be6e1073/big.png)](https://insight.sensiolabs.com/projects/dbeb0236-21a3-49be-9ee3-1585be6e1073) 9 | 10 | [![Build Status](https://travis-ci.org/PHPointless/monolol.svg)](https://travis-ci.org/PHPointless/monolol) 11 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPointless/monolol/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPointless/monolol/?branch=master) 12 | [![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/PHPointless/monolol/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/PHPointless/monolol/?branch=master) 13 | 14 | INSTALLATION 15 | ------------ 16 | Use composer: 17 | ```sh 18 | composer require PHPointless/monolol 19 | ``` 20 | 21 | HOW TO USE IT 22 | ------------- 23 | 24 | Monolol provides a new wrapper handler for Monolog: LolHandler. 25 | LolHandler will apply a Lolifier that will do some stuff on records handled by the wrapped handler. 26 | 27 | For example, we want to randomly shuffle the log message words of all records that will be handled by a Monolog StreamHandler. 28 | Here is code that will do the trick: 29 | 30 | ```php 31 | pushHandler($lolHandler); 44 | 45 | $logger->info('My littlest pony'); 46 | $logger->error('This burger has no cheese'); 47 | ``` 48 | 49 | AVAILABLE LOLIFIERS 50 | ------------------- 51 | - _Blackout_: Forgot half the sentence 52 | - _Shuffle_: Words contained in the record message will be randomly shuffled 53 | - _Confuse_: This lolifier will change randomly the log level of the record 54 | - _GeekTime_: Records will be handled only if it's 1:37pm (13:37) 55 | - _Hangman_: Want to play hangman game while reading your logfiles? 56 | - _Hash_: Messages will be hashed with a randomly chosen algorithm 57 | - _LaMerNoire_: Messages will be replaced by the following string: 'La mer Noire' 58 | - _Mirror_: Messages' content will be reversed (desrever eb lliw tnetnoc egassem sdrocer) 59 | - _NotGiveAFuck_: Messages having loglevel above INFO will be replaced by the following string: "It seems that your application has encountered an issue. But as we don't give a fuck, we will not tell you what the problem is. Have a good day" 60 | - _NyanCat_: Nya nya nya nya nya nya nya nya nya nya nya! 61 | - _Quote_: Messages will be replaced by a quote randomly chosen. Quote Lolifier needs a QuoteProvider. Here's an example of how to use it: 62 | ```php 63 | $quoteProvider = new Lolifiers\QuoteProviders\Kaamelott\Kadoc(); 64 | $lolHandler = new LolHandler($streamHandler, new Lolifiers\Quote($quoteProvider)); 65 | ``` 66 | If you want quotes from more than one provider, you can use QuoteProviders\Collection: 67 | ```php 68 | $quoteProvider = new Lolifiers\QuoteProviders\Collection(); 69 | $quoteProvider->add(new Lolifiers\QuoteProviders\Kaamelott\Kadoc()) 70 | ->add(new Lolifiers\QuoteProviders\Kaamelott\Karadoc()) 71 | ->add(new Lolifiers\QuoteProviders\Kaamelott\Perceval()); 72 | $lolHandler = new LolHandler($streamHandler, new Lolifiers\Quote($quoteProvider)); 73 | ``` 74 | - _Warp_: Handled records will travel through the Warp 75 | - _Yell_: TO READ YOUR LOG FILES IN NOISY ENVIRONMENTS 76 | - _Yolo_: "An error? What are you talking about? There was no error!". All records having loglevel above INFO will not be handled 77 | - _Tourette_: Monolog is suffering from Tourette's syndrome. This lolifier needs a SwearWordsProvider. Here's an example of how to use it: 78 | ```php 79 | $swearWordsProvider = new Lolifiers\SwearWordsProviders\DefaultProvider(); 80 | $lolHandler = new LolHandler($streamHandler, new Lolifiers\Tourette($swearWordsProvider)); 81 | ``` 82 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "phpointless/monolol", 3 | "description" : "PSR-3 compliant lol-gger", 4 | "type" : "library", 5 | "authors" : [{ 6 | "name" : "Romain Renaud", 7 | "email" : "contact@romain-renaud.fr" 8 | }, 9 | { 10 | "name" : "Claude LE BRIS", 11 | "email" : "claude.lebris@gmail.com" 12 | } 13 | ], 14 | "keywords" : [ 15 | "lol", 16 | "lol-gging", 17 | "psr3" 18 | ], 19 | "license" : [ 20 | "MIT" 21 | ], 22 | "require-dev" : { 23 | "phpunit/phpunit" : "~4.5" 24 | }, 25 | "require" : { 26 | "monolog/monolog" : "~1.12" 27 | }, 28 | "autoload" : { 29 | "psr-4" : { 30 | "Monolol\\" : "lib" 31 | } 32 | }, 33 | "support" : { 34 | "issues" : "https://github.com/PHPointless/monolol/issues" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/Handlers/LolHandler.php: -------------------------------------------------------------------------------- 1 | handler = $handler; 21 | $this->lolifier = $lolifier; 22 | $this->bubble = $bubble; 23 | 24 | if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) { 25 | throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object"); 26 | } 27 | } 28 | 29 | public function isHandling(array $record) 30 | { 31 | return $this->lolifier->isHandling($record); 32 | } 33 | 34 | public function handle(array $record) 35 | { 36 | if (! $this->handler instanceof HandlerInterface) { 37 | $this->handler = call_user_func($this->handler, $record, $this); 38 | if (! $this->handler instanceof HandlerInterface) { 39 | throw new \RuntimeException("The factory callable should return a HandlerInterface"); 40 | } 41 | } 42 | 43 | $record = $this->lolifier->lolify($record); 44 | 45 | if ($this->processors) { 46 | foreach ($this->processors as $processor) { 47 | $record = call_user_func($processor, $record); 48 | } 49 | } 50 | 51 | $this->handler->handle($record); 52 | 53 | return false === $this->bubble; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/Lolifier.php: -------------------------------------------------------------------------------- 1 | forgotHalfSentence($record['message']); 19 | 20 | return $record; 21 | } 22 | 23 | private function forgotHalfSentence($message) 24 | { 25 | $nbWords = str_word_count($message); 26 | 27 | if($nbWords > 1) 28 | { 29 | $posHalfSentence = floor(strlen($message) / 2) + 1; 30 | $cut = substr($message, 0, $posHalfSentence); 31 | $cut = strrev(strpbrk(strrev($cut), " \t\n\r\0\x0B")); 32 | $message = $cut . self::MESSAGE; 33 | } 34 | 35 | return $message; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/Lolifiers/Confuse.php: -------------------------------------------------------------------------------- 1 | filterMonologLevels($record); 18 | $randomKey = array_rand($availableLevels); 19 | 20 | $record['level'] = $availableLevels[$randomKey]; 21 | $record['level_name'] = $randomKey; 22 | 23 | return $record; 24 | } 25 | 26 | private function filterMonologLevels(array $record) 27 | { 28 | return array_filter(MonologLevel::getLevels(), function($level) use ($record) { 29 | return $record['level'] !== $level; 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Lolifiers/GeekTime.php: -------------------------------------------------------------------------------- 1 | isGeekTime($dateTime); 14 | } 15 | 16 | public function lolify(array $record) 17 | { 18 | return $record; 19 | } 20 | 21 | private function isGeekTime(\Datetime $dateTime) 22 | { 23 | if($dateTime->format('H:i') == '13:37') 24 | { 25 | return true; 26 | } 27 | 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/Lolifiers/Hangman.php: -------------------------------------------------------------------------------- 1 | hash($record['message']); 17 | 18 | return $record; 19 | } 20 | 21 | private function hash($string) 22 | { 23 | $algorithm = $this->getRandomAlgorithm(); 24 | 25 | return hash($algorithm, $string); 26 | } 27 | 28 | private function getRandomAlgorithm() 29 | { 30 | $algorithms = hash_algos(); 31 | 32 | return $algorithms[array_rand($algorithms)]; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /lib/Lolifiers/LaMerNoire.php: -------------------------------------------------------------------------------- 1 | Logger::INFO) 21 | { 22 | $record['message'] = self::MESSAGE; 23 | } 24 | 25 | return $record; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/Lolifiers/NullLolifier.php: -------------------------------------------------------------------------------- 1 | provider = $provider; 16 | } 17 | 18 | public function isHandling(array $record) 19 | { 20 | return true; 21 | } 22 | 23 | public function lolify(array $record) 24 | { 25 | $quote = $this->getRandomQuote(); 26 | 27 | $record['message'] = $quote; 28 | 29 | return $record; 30 | } 31 | 32 | private function getRandomQuote() 33 | { 34 | $quotes = $this->provider->getQuotes(); 35 | 36 | if(empty($quotes)) 37 | { 38 | return null; 39 | } 40 | 41 | return $quotes[array_rand($quotes)]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/Lolifiers/QuoteProvider.php: -------------------------------------------------------------------------------- 1 | providers = array(); 15 | } 16 | 17 | public function getQuotes() 18 | { 19 | $quotes = array(); 20 | 21 | foreach($this->providers as $provider) 22 | { 23 | $quotes = array_merge($quotes, $provider->getQuotes()); 24 | } 25 | 26 | return $quotes; 27 | } 28 | 29 | public function add(QuoteProvider $provider) 30 | { 31 | if(! in_array($provider, $this->providers)) 32 | { 33 | $this->providers[] = $provider; 34 | } 35 | 36 | return $this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/Lolifiers/QuoteProviders/EmptyQuoteProvider.php: -------------------------------------------------------------------------------- 1 | countDifferentWordsInMessage($record['message']) <= 1) 17 | { 18 | return $record; 19 | } 20 | 21 | $record['message'] = $this->shuffleMessage($record['message']); 22 | 23 | return $record; 24 | } 25 | 26 | private function countDifferentWordsInMessage($message) 27 | { 28 | $messageArray = $this->convertStringToArray($message); 29 | $messageArray = array_unique($messageArray); 30 | 31 | return count($messageArray); 32 | } 33 | 34 | private function convertStringToArray($message) 35 | { 36 | return explode(' ', $message); 37 | } 38 | 39 | private function convertArrayToString(array $array) 40 | { 41 | return implode(' ', $array); 42 | } 43 | 44 | private function shuffleMessage($message) 45 | { 46 | 47 | $messageArray = $this->convertStringToArray($message); 48 | 49 | do 50 | { 51 | $shuffledMessageArray = $this->shuffleArray($messageArray); 52 | } 53 | while($messageArray === $shuffledMessageArray); 54 | 55 | return $this->convertArrayToString($shuffledMessageArray); 56 | } 57 | 58 | private function shuffleArray(array $array) 59 | { 60 | shuffle($array); 61 | 62 | return $array; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/Lolifiers/SwearWordsProvider.php: -------------------------------------------------------------------------------- 1 | swearWordsProvider = $swearWordsProvider; 15 | } 16 | 17 | public function isHandling(array $record) 18 | { 19 | return true; 20 | } 21 | 22 | public function lolify(array $record) 23 | { 24 | $messageArray = explode(' ', $record['message']); 25 | $badWords = $this->swearWordsProvider->getSwearWords(); 26 | 27 | $iterations = rand(1, 3); 28 | for($i = 0; $i < $iterations; $i++) 29 | { 30 | $badWord = $this->chooseBadWordRandomly($badWords); 31 | $this->insertSwearWordIntoMessage($messageArray, $badWord); 32 | } 33 | 34 | $record['message'] = implode(' ', $messageArray); 35 | 36 | return $record; 37 | } 38 | 39 | private function chooseBadWordRandomly(array $badWords) 40 | { 41 | $index = array_rand($badWords); 42 | 43 | return $badWords[$index]; 44 | } 45 | 46 | private function insertSwearWordIntoMessage(array &$messageArray, $badWord) 47 | { 48 | array_splice($messageArray, rand(0, count($messageArray)), 0, $badWord); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/Lolifiers/Warp.php: -------------------------------------------------------------------------------- 1 | travelIntoWarp($record['datetime']); 21 | 22 | return $record; 23 | } 24 | 25 | private function travelIntoWarp(\DateTime $datetime) 26 | { 27 | foreach($this->getMeasuresOfTime() as $measure => $prefix) 28 | { 29 | $interval = rand(self::MIN_INTERVAL, self::MAX_INTERVAL); 30 | 31 | $datetime->add(new \DateInterval($prefix . $interval . $measure)); 32 | } 33 | } 34 | 35 | private function getMeasuresOfTime() 36 | { 37 | return array( 38 | 'S' => 'PT', 39 | 'M' => 'PT', 40 | 'H' => 'PT', 41 | 'D' => 'P', 42 | 'M' => 'P', 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Lolifiers/Yell.php: -------------------------------------------------------------------------------- 1 | acceptedLevels = array( 16 | Logger::DEBUG, 17 | Logger::INFO, 18 | ); 19 | } 20 | 21 | public function isHandling(array $record) 22 | { 23 | return in_array($record['level'], $this->acceptedLevels); 24 | } 25 | 26 | public function lolify(array $record) 27 | { 28 | return $record; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lib/Referentials/MonologLevel.php: -------------------------------------------------------------------------------- 1 | Logger::DEBUG, 13 | 'INFO' => Logger::INFO, 14 | 'NOTICE' => Logger::NOTICE, 15 | 'WARNING' => Logger::WARNING, 16 | 'ERROR' => Logger::ERROR, 17 | 'CRITICAL' => Logger::CRITICAL, 18 | 'ALERT' => Logger::ALERT, 19 | 'EMERGENCY' => Logger::EMERGENCY, 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | tests 7 | 8 | 9 | 10 | 11 | 12 | vendor 13 | 14 | 15 | lib 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/Handlers/LolHandlerTest.php: -------------------------------------------------------------------------------- 1 | testHandler = new TestHandler(); 19 | $this->lolHandler = new LolHandler($this->testHandler, new NullLolifier()); 20 | } 21 | 22 | public function testHandle() 23 | { 24 | $this->lolHandler->handle($this->getRecord(Logger::DEBUG)); 25 | $this->assertTrue($this->testHandler->hasDebugRecords()); 26 | 27 | $this->lolHandler->handle($this->getRecord(Logger::INFO)); 28 | $this->assertTrue($this->testHandler->hasInfoRecords()); 29 | 30 | $this->lolHandler->handle($this->getRecord(Logger::NOTICE)); 31 | $this->assertTrue($this->testHandler->hasNoticeRecords()); 32 | 33 | $this->lolHandler->handle($this->getRecord(Logger::WARNING)); 34 | $this->assertTrue($this->testHandler->hasWarningRecords()); 35 | 36 | $this->lolHandler->handle($this->getRecord(Logger::ERROR)); 37 | $this->assertTrue($this->testHandler->hasErrorRecords()); 38 | 39 | $this->lolHandler->handle($this->getRecord(Logger::CRITICAL)); 40 | $this->assertTrue($this->testHandler->hasCriticalRecords()); 41 | 42 | $this->lolHandler->handle($this->getRecord(Logger::ALERT)); 43 | $this->assertTrue($this->testHandler->hasAlertRecords()); 44 | 45 | $this->lolHandler->handle($this->getRecord(Logger::EMERGENCY)); 46 | $this->assertTrue($this->testHandler->hasEmergencyRecords()); 47 | } 48 | 49 | public function testHandleUsesProcessors() 50 | { 51 | $this->lolHandler->pushProcessor( 52 | function ($record) { 53 | $record['extra']['foo'] = true; 54 | 55 | return $record; 56 | } 57 | ); 58 | 59 | $this->lolHandler->handle($this->getRecord()); 60 | 61 | $records = $this->testHandler->getRecords(); 62 | $this->assertTrue($records[0]['extra']['foo']); 63 | } 64 | 65 | public function testHandleRespectsBubble() 66 | { 67 | $this->lolHandler->setBubble(false); 68 | $this->assertTrue($this->lolHandler->handle($this->getRecord())); 69 | 70 | $this->lolHandler->setBubble(true); 71 | $this->assertFalse($this->lolHandler->handle($this->getRecord())); 72 | } 73 | 74 | public function testHandleWithCallback() 75 | { 76 | $lolHandler = new LolHandler( 77 | function () { 78 | return $this->testHandler; 79 | }, 80 | new NullLolifier 81 | ); 82 | 83 | $lolHandler->handle($this->getRecord(Logger::DEBUG)); 84 | $this->assertTrue($this->testHandler->hasDebugRecords()); 85 | } 86 | 87 | /** 88 | * @expectedException \RuntimeException 89 | */ 90 | public function testHandleWithBadCallbackThrowsException() 91 | { 92 | $lolHandler = new LolHandler( 93 | function () { 94 | return 'foo'; 95 | }, 96 | new NullLolifier() 97 | ); 98 | $lolHandler->handle($this->getRecord(Logger::WARNING)); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /tests/Lolifiers/BlackoutTest.php: -------------------------------------------------------------------------------- 1 | blackout = new Blackout(); 14 | } 15 | 16 | public function testHandling() 17 | { 18 | $this->assertTrue($this->blackout->isHandling(array())); 19 | } 20 | 21 | /** 22 | * @dataProvider blackoutProvider 23 | */ 24 | public function testBlackout($expected, $message) 25 | { 26 | $record = array('message' => $message); 27 | $result = $this->blackout->lolify($record); 28 | 29 | $this->assertSame($expected, $result['message']); 30 | } 31 | 32 | public function blackoutProvider() 33 | { 34 | return [ 35 | ['bazinga', 'bazinga'], 36 | ['I am not crazy, my ... ummm ... wait ... what were we talking about again ?', 'I am not crazy, my mother had me tested.'], 37 | ['Sorry I\'m late. I also got you a balloon, but ... ummm ... wait ... what were we talking about again ?', 'Sorry I\'m late. I also got you a balloon, but it floated away and I chased it for a while.'], 38 | [ 39 | 'Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors ... ummm ... wait ... what were we talking about again ?', 40 | 'Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors.' 41 | ], 42 | [ 43 | 'En hiver, cette place est suffisamment proche du radiateur, du coup elle est bien chaude sans causer pour autant un phénomène de transpiration. Et en été c\'est pratique car elle est dans l\'axe d\'une petite brise provoquée par l\'ouverture de ... ummm ... wait ... what were we talking about again ?', 44 | 'En hiver, cette place est suffisamment proche du radiateur, du coup elle est bien chaude sans causer pour autant un phénomène de transpiration. Et en été c\'est pratique car elle est dans l\'axe d\'une petite brise provoquée par l\'ouverture de nos fenêtres. Elle est en face de la télévision sans être tout à fait à angle droit, ce qui décourage la conversation mais ça ne cause pas d\'erreur de parallaxe. Je pourrais continuer longtemps, mais je crois que je me suis fais comprendre.' 45 | ], 46 | ["I\nam\n... ummm ... wait ... what were we talking about again ?", "I\nam\nnot\ncrazy"], 47 | ["I am not crazy,\nmy ... ummm ... wait ... what were we talking about again ?", "I am not crazy,\nmy mother had me tested."], 48 | ["I\tam\tnot\tcrazy,\nmy\n\r... ummm ... wait ... what were we talking about again ?", "I\tam\tnot\tcrazy,\nmy\n\rmother\thad me tested."], 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Lolifiers/ConfuseTest.php: -------------------------------------------------------------------------------- 1 | confuse = new Confuse(); 15 | } 16 | 17 | public function testHandling() 18 | { 19 | $this->assertTrue($this->confuse->isHandling(array())); 20 | } 21 | 22 | /** 23 | * @dataProvider testLevelConfuseProvider 24 | */ 25 | public function testLevelConfuse($label, $level) 26 | { 27 | $record = array( 28 | 'level' => $level, 29 | 'level_name' => $label, 30 | ); 31 | $confusedRecord = $this->confuse->lolify($record); 32 | 33 | $this->assertNotSame($level, $confusedRecord['level']); 34 | $this->assertNotSame($label, $confusedRecord['level_name']); 35 | 36 | $monologLevels = MonologLevel::getLevels(); 37 | 38 | $this->assertTrue(in_array($confusedRecord['level'], $monologLevels)); 39 | $this->assertTrue(array_key_exists($confusedRecord['level_name'], $monologLevels)); 40 | $this->assertSame($monologLevels[$confusedRecord['level_name']], $confusedRecord['level']); 41 | } 42 | 43 | public function testLevelConfuseProvider() 44 | { 45 | $providedTests = array(); 46 | 47 | foreach(MonologLevel::getLevels() as $label => $level) 48 | { 49 | $providedTests[$label] = array($label, $level); 50 | } 51 | 52 | return $providedTests; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Lolifiers/GeekTimeTest.php: -------------------------------------------------------------------------------- 1 | $message, 'datetime' => $dateTime); 14 | 15 | $lolifier = new GeekTime(); 16 | 17 | $this->assertSame($expected, $lolifier->isHandling($record)); 18 | $this->assertSame($message, $record['message']); 19 | } 20 | 21 | public function providerGeekTime() 22 | { 23 | return array( 24 | array(false, 'Internal Server Error', '1970-01-01 00:00:00'), 25 | array(true, 'Internal Server Error', '1970-01-01 13:37:00'), 26 | array(false, '', '2015-09-12 19:13:37'), 27 | array(true, '', '2015-09-12 13:37:00'), 28 | array(false, '', '2666-12-31 13:00:37'), 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Lolifiers/HangmanTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new Hangman())->isHandling(array())); 10 | } 11 | 12 | /** 13 | * @dataProvider providerTestHangman 14 | */ 15 | public function testHangman($expected, $message) 16 | { 17 | $record = array('message' => $message); 18 | 19 | $lolified = (new Hangman())->lolify($record); 20 | 21 | $this->assertSame($expected, $lolified['message']); 22 | } 23 | 24 | public function providerTestHangman() 25 | { 26 | return array( 27 | array('',''), 28 | array('p___y', 'poney'), 29 | array('l___m i___m', 'lorem ipsum'), 30 | array('I______l s____r e___r!', 'Internal server error!'), 31 | array('Do n_t b_____e c_____e, it m___s y_u c___h','Do not breathe compote, it makes you cough'), 32 | array('E____y #5_9 n_t f___d', 'Entity #589 not found'), 33 | array('b____r-p__y-u_____n', 'burger-pony-unicorn') 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Lolifiers/HashTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new Hash())->isHandling(array())); 12 | } 13 | 14 | public function testHash() 15 | { 16 | $record = array('message' => 'my littlest pony'); 17 | 18 | $lolifier = new Hash(); 19 | $lolified = $lolifier->lolify($record); 20 | 21 | $this->assertNotSame($record, $lolified); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Lolifiers/LaMerNoireTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new LaMerNoire())->isHandling(array())); 10 | } 11 | 12 | /** 13 | * @dataProvider providerTestLaMerNoire 14 | */ 15 | public function testLaMerNoire($expected, $message) 16 | { 17 | $record = array('message' => $message); 18 | 19 | $lolified = (new LaMerNoire())->lolify($record); 20 | 21 | $this->assertSame($expected, $lolified['message']); 22 | } 23 | 24 | public function providerTestLaMerNoire() 25 | { 26 | return array( 27 | array(LaMerNoire::LA_MER_NOIRE, ''), 28 | array(LaMerNoire::LA_MER_NOIRE, 'Pony'), 29 | array(LaMerNoire::LA_MER_NOIRE, 'Unable to find product 1337'), 30 | array(LaMerNoire::LA_MER_NOIRE, 'Internal server error'), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Lolifiers/MirrorTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new Mirror())->isHandling(array())); 10 | } 11 | 12 | /** 13 | * @dataProvider providerTestMirror 14 | */ 15 | public function testMirror($expected, $message) 16 | { 17 | $record = array('message' => $message, 'datetime' => new \DateTime()); 18 | 19 | $lolified = (new Mirror())->lolify($record); 20 | 21 | $this->assertSame($expected, $lolified['message']); 22 | } 23 | 24 | public function providerTestMirror() 25 | { 26 | return array( 27 | array('ynop', 'pony'), 28 | array('muspi merol', 'lorem ipsum'), 29 | array('rorre revres lanretnI', 'Internal server error'), 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Lolifiers/NotGiveAFuckTest.php: -------------------------------------------------------------------------------- 1 | notGiveAFuck = new NotGiveAFuck(); 15 | } 16 | 17 | public function testHandling() 18 | { 19 | $this->assertTrue($this->notGiveAFuck->isHandling(array())); 20 | } 21 | 22 | /** 23 | * @dataProvider testNotGiveAFuckProvider 24 | */ 25 | public function testNotGiveAFuck(array $record, array $expected) 26 | { 27 | $lolifiedRecord = $this->notGiveAFuck->lolify($record); 28 | 29 | $this->assertSame($expected, $lolifiedRecord); 30 | } 31 | 32 | public function testNotGiveAFuckProvider() 33 | { 34 | return array( 35 | "Debug" => array( 36 | array('level' => Logger::DEBUG, 'message' => 'debug message'), 37 | array('level' => Logger::DEBUG, 'message' => 'debug message'), 38 | ), 39 | "Info" => array( 40 | array('level' => Logger::INFO, 'message' => 'info message'), 41 | array('level' => Logger::INFO, 'message' => 'info message'), 42 | ), 43 | "Notice" => array( 44 | array('level' => Logger::NOTICE, 'message' => 'notice message'), 45 | array('level' => Logger::NOTICE, 'message' => NotGiveAFuck::MESSAGE), 46 | ), 47 | "Warning" => array( 48 | array('level' => Logger::WARNING, 'message' => 'warning message'), 49 | array('level' => Logger::WARNING, 'message' => NotGiveAFuck::MESSAGE), 50 | ), 51 | "Error" => array( 52 | array('level' => Logger::ERROR, 'message' => 'error message'), 53 | array('level' => Logger::ERROR, 'message' => NotGiveAFuck::MESSAGE), 54 | ), 55 | "Alert" => array( 56 | array('level' => Logger::ALERT, 'message' => 'alert message'), 57 | array('level' => Logger::ALERT, 'message' => NotGiveAFuck::MESSAGE), 58 | ), 59 | "Critical" => array( 60 | array('level' => Logger::CRITICAL, 'message' => 'critical message'), 61 | array('level' => Logger::CRITICAL, 'message' => NotGiveAFuck::MESSAGE), 62 | ), 63 | "Emergency" => array( 64 | array('level' => Logger::EMERGENCY, 'message' => 'emergency message'), 65 | array('level' => Logger::EMERGENCY, 'message' => NotGiveAFuck::MESSAGE), 66 | ), 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/Lolifiers/NyanCatTest.php: -------------------------------------------------------------------------------- 1 | nyanCat = new NyanCat(); 13 | } 14 | 15 | public function testIsHandling() 16 | { 17 | $this->assertTrue($this->nyanCat->isHandling(array())); 18 | } 19 | 20 | /** 21 | * @dataProvider nyanCatLolifyProvider 22 | */ 23 | public function testLolify($expected, $message) 24 | { 25 | $record = array('message' => $message); 26 | 27 | $lolified = $this->nyanCat->lolify($record); 28 | 29 | $this->assertSame($expected, $lolified['message']); 30 | } 31 | 32 | public function nyanCatLolifyProvider() 33 | { 34 | return array( 35 | array('', ''), 36 | array(' ', ' '), 37 | array('nya nya nya nya', 'I am a cat'), 38 | array('nya nya\'nya nya nya, nya nya, nya.', 'I don\'t care about, you know, punctuation.'), 39 | array('nya nya nya nya', 'Àccéènts arê mÿ frùends'), 40 | array('nya-nya ` nya +nya nya| nya !!! :(', 'I-hate ` all +those weird| symbols !!! :('), 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Lolifiers/QuoteProviders/CollectionTest.php: -------------------------------------------------------------------------------- 1 | add($provider); 18 | } 19 | 20 | $this->assertSame($expected, $providerCollection->getQuotes()); 21 | } 22 | 23 | public function providerTestProviderCollection() 24 | { 25 | $emptyProvider = new QuoteProviders\EmptyQuoteProvider(); 26 | $perceval = new QuoteProviders\Kaamelott\Perceval(); 27 | $perceval2 = new QuoteProviders\Kaamelott\Perceval(); 28 | $karadoc = new QuoteProviders\Kaamelott\Karadoc(); 29 | $merlin = new QuoteProviders\Kaamelott\Merlin(); 30 | $kadoc = new QuoteProviders\Kaamelott\Kadoc(); 31 | 32 | $collectionA = new Collection(); 33 | $collectionA->add($perceval)->add($karadoc); 34 | 35 | $collectionB = new Collection(); 36 | $collectionB->add($merlin)->add($kadoc); 37 | 38 | return array( 39 | 'Empty + Empty' => array(array(), array($emptyProvider, $emptyProvider)), 40 | 'Same class, different instance' => array($perceval->getQuotes(), array($perceval, $perceval2)), 41 | 'Perceval + Empty' => array($perceval->getQuotes(), array($perceval, $emptyProvider)), 42 | 'Empty + Perceval' => array($perceval->getQuotes(), array($emptyProvider, $perceval)), 43 | 'Empty + Karadoc + Empty' => array($karadoc->getQuotes(), array($emptyProvider, $karadoc, $emptyProvider)), 44 | 'Perceval + Karadoc' => array(array_merge($perceval->getQuotes(), $karadoc->getQuotes()), array($perceval, $karadoc)), 45 | 'Perceval + Perceval + Karadoc' => array(array_merge($perceval->getQuotes(), $karadoc->getQuotes()), array($perceval, $perceval, $karadoc)), 46 | 'Collection + empty' => array($collectionA->getQuotes(), array($collectionA, $emptyProvider)), 47 | 'Collection + Kadoc' => array(array_merge($collectionA->getQuotes(), $kadoc->getQuotes()), array($collectionA, $kadoc)), 48 | 'Collection + Collection' => array(array_merge($collectionA->getQuotes(), $collectionB->getQuotes()), array($collectionA, $collectionB)), 49 | ); 50 | } 51 | } -------------------------------------------------------------------------------- /tests/Lolifiers/QuoteTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new Quote(new QuoteProviders\EmptyQuoteProvider()))->isHandling(array())); 15 | } 16 | 17 | /** 18 | * @dataProvider providerTestQuote 19 | */ 20 | public function testQuote(QuoteProvider $provider, $logMessage) 21 | { 22 | $record = array('message' => $logMessage, 'datetime' => new \DateTime()); 23 | 24 | $lolifier = new Quote($provider); 25 | 26 | $lolilfiedRecord = $lolifier->lolify($record); 27 | 28 | $this->assertTrue(in_array($lolilfiedRecord['message'], $provider->getQuotes())); 29 | } 30 | 31 | public function providerTestQuote() 32 | { 33 | return array( 34 | 'Perceval' => array(new QuoteProviders\Kaamelott\Perceval(), 'Internal Burger Error'), 35 | 'Karadoc' => array(new QuoteProviders\Kaamelott\Karadoc(), 'Internal Pony Error'), 36 | 'Merlin' => array(new QuoteProviders\Kaamelott\Merlin(), 'Internal Unicorn Error'), 37 | 'Kadoc' => array(new QuoteProviders\Kaamelott\Kadoc(), 'Internal Rabbit Error'), 38 | ); 39 | } 40 | 41 | public function testEmptyQuotes() 42 | { 43 | $record = array('message' => 'Lorem ipsum dolor sit amet', 'datetime' => new \DateTime()); 44 | 45 | $provider = new QuoteProviders\EmptyQuoteProvider(); 46 | 47 | $lolifier = new Quote($provider); 48 | 49 | $lolilfiedRecord = $lolifier->lolify($record); 50 | 51 | $this->assertSame($lolilfiedRecord['message'], null); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Lolifiers/ShuffleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($shuffle->isHandling(array())); 14 | } 15 | 16 | /** 17 | * @dataProvider providerTestMessageShuffle 18 | */ 19 | public function testMessageShuffle($message) 20 | { 21 | $record = array('message' => $message); 22 | 23 | $shuffle = new Shuffle(); 24 | $shuffledRecord = $shuffle->lolify($record); 25 | 26 | $messageToArray = $this->convertStringToArray($message); 27 | $shuffledMessageToArray = $this->convertStringToArray($shuffledRecord['message']); 28 | 29 | if(count(array_unique($messageToArray)) > 1) 30 | { 31 | $this->assertNotSame($message, $shuffledRecord['message']); 32 | } 33 | 34 | foreach($shuffledMessageToArray as $word) 35 | { 36 | $this->assertTrue(in_array($word, $messageToArray)); 37 | } 38 | } 39 | 40 | private function convertStringToArray($string) 41 | { 42 | return explode(' ', $string); 43 | } 44 | 45 | public function providerTestMessageShuffle() 46 | { 47 | return array( 48 | array(''), 49 | array('pony'), 50 | array('burger burger'), 51 | array('My littlest pony'), 52 | array('Oops, it seems that there was an error!'), 53 | array('42 3945 : unicorn ->kawai'), 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/Lolifiers/TouretteTest.php: -------------------------------------------------------------------------------- 1 | swearWordsProvider = new SwearWordsProviders\DefaultProvider(); 13 | } 14 | 15 | public function testHandling() 16 | { 17 | $this->assertTrue((new Tourette($this->swearWordsProvider))->isHandling(array())); 18 | } 19 | 20 | /** 21 | * @dataProvider providerTestTourette 22 | */ 23 | public function testTourette($message) 24 | { 25 | $record = array('message' => $message); 26 | 27 | $lolified = (new Tourette($this->swearWordsProvider))->lolify($record); 28 | 29 | $this->assertNotSame($message, $lolified['message']); 30 | 31 | $messageArray = explode(' ', $lolified['message']); 32 | $swearWordsFound = array_intersect($this->swearWordsProvider->getSwearWords(), $messageArray); 33 | 34 | $this->assertFalse(empty($swearWordsFound)); 35 | } 36 | 37 | public function providerTestTourette() 38 | { 39 | return array( 40 | array(''), 41 | array('Pony'), 42 | array('Unable to find product 1337'), 43 | array('Internal server error'), 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Lolifiers/WarpTest.php: -------------------------------------------------------------------------------- 1 | warp = new Warp(); 13 | } 14 | 15 | public function testHandling() 16 | { 17 | $this->assertTrue($this->warp->isHandling(array())); 18 | } 19 | 20 | public function testWarpTravel() 21 | { 22 | $dateTime = new \DateTime(); 23 | $record = array('datetime' => clone $dateTime); 24 | $lolifiedRecord = $this->warp->lolify($record); 25 | 26 | $this->assertInstanceOf('DateTime', $lolifiedRecord['datetime']); 27 | $this->assertGreaterThan($dateTime->getTimeStamp(), $lolifiedRecord['datetime']->getTimeStamp()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Lolifiers/YellTest.php: -------------------------------------------------------------------------------- 1 | assertTrue((new Yell())->isHandling(array())); 10 | } 11 | 12 | /** 13 | * @dataProvider providerTestYell 14 | */ 15 | public function testYell($expected, $message) 16 | { 17 | $record = array('message' => $message); 18 | 19 | $lolified = (new Yell())->lolify($record); 20 | 21 | $this->assertSame($expected, $lolified['message']); 22 | } 23 | 24 | public function providerTestYell() 25 | { 26 | return array( 27 | array('PONEY', 'poney'), 28 | array('LOREM IPSUM', 'lorem ipsum'), 29 | array('INTERNAL SERVER ERROR', 'Internal server error'), 30 | array('POURQUOI TU VEUX FAIRE CA', 'POURQUOI TU VEUX FAIRE CA'), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Lolifiers/YoloTest.php: -------------------------------------------------------------------------------- 1 | yolo = new Yolo(); 15 | } 16 | 17 | /** 18 | * @dataProvider testHandlingProvider 19 | */ 20 | public function testHandling($level, $expected) 21 | { 22 | $record = array('level' => $level); 23 | 24 | $this->assertSame($expected, $this->yolo->isHandling($record)); 25 | } 26 | 27 | public function testHandlingProvider() 28 | { 29 | return array( 30 | 'debug' => array(Logger::DEBUG, true), 31 | 'info' => array(Logger::INFO, true), 32 | 'notice' => array(Logger::NOTICE, false), 33 | 'warning' => array(Logger::WARNING, false), 34 | 'error' => array(Logger::ERROR, false), 35 | 'critical' => array(Logger::CRITICAL, false), 36 | 'alert' => array(Logger::ALERT, false), 37 | 'emergency' => array(Logger::EMERGENCY, false), 38 | ); 39 | } 40 | 41 | public function testLolify() 42 | { 43 | $record = array('message' => 'my littlest pony', 'datetime' => new \DateTime()); 44 | 45 | $this->assertSame($record, $this->yolo->lolify($record)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | addPsr4('Monolog\\', __DIR__ . "/../vendor/monolog/monolog/tests/Monolog"); 5 | --------------------------------------------------------------------------------