diff --git a/README.md b/README.md index 167e0a8..3e88bd2 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ skipped = ghost pass = monkey ``` -Note that the values in the emojiset are snale-cased emoji short codes *without the opening and closing colons*; most existing short codes are supported, a list of supported shortcodes will be added soon. +Note that the values in the emojiset are snake-cased emoji short codes *without the opening and closing colons*; most existing short codes are supported, a list of supported shortcodes will be added soon. You may choose to override one or more of the packaged emojisets (as in the case of "phumoji", above, which overrides the default emojiset), or you may define your own (as in the case of "weird", above). diff --git a/src/EmojiPrinter.php b/src/EmojiPrinter.php index c6bc333..8efd57f 100644 --- a/src/EmojiPrinter.php +++ b/src/EmojiPrinter.php @@ -1,7 +1,8 @@ -documentElement; - - $emojiset = $phpunit->hasAttribute('emojiset') ? $phpunit->getAttribute('emojiset') : 'phpumoji'; - - $emojifile = array_merge(parse_ini_file(__DIR__ . '/../config/.emojifile', true), file_exists(substr($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], 0, strrpos($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], '/')) . '/.emojifile') ? - parse_ini_file(substr($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], 0, strrpos($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], '/')) . '/.emojifile', true) : []); - - $this->emojis = $emojifile[$emojiset] ?? $emojifile['phpumoji']; + $this->emojis = $this->emojis( + $this->emojifile($this->projectroot()), + $this->emojiset($this->phpunitxml()) + ); if ($this->numTests == -1) { $this->numTests = count($suite); @@ -33,7 +35,7 @@ public function startTestSuite(TestSuite $suite) protected function writeProgress($progress) { - return parent::writeProgress($this->emojify($progress)); + return parent::writeProgress($this->emojify($progress) . self::SPACER); } protected function writeProgressWithColor($color, $progress) @@ -41,10 +43,50 @@ protected function writeProgressWithColor($color, $progress) return $this->writeProgress($progress); } - private function emojify(string $progress) :string + private function projectroot(): string + { + return substr($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], 0, strrpos( + $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], '/') + ); + } + + private function emojifile(string $projectroot): array + { + return array_merge( + $this->parse(self::CONFIG . self::EMOJIFILE), + $this->parse($projectroot . self::EMOJIFILE) + ); + } + + private function phpunitxml(): DOMElement + { + return Xml::loadFile($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], false, true, true)->documentElement; + } + + private function parse(string $filepath): array + { + return file_exists($filepath) ? parse_ini_file($filepath, true) : []; + } + + private function emojiset(DOMElement $phpunitxml): string + { + return $phpunitxml->hasAttribute('emojiset') ? $phpunitxml->getAttribute('emojiset') : self::EMOJISET; + } + + private function emojis(array $emojifile, string $emojiset): array + { + return $emojifile[$emojiset] ?? $emojifile[self::EMOJISET]; + } + + private function emojify(string $result): string + { + return LitEmoji::encodeUnicode(":{$this->shortcode($result)}:"); + } + + private function shortcode(string $character): string { - return LitEmoji::encodeUnicode(':' . (array_values(array_filter($this->emojis, function ($key) use ($progress) { - return strrpos(strtoupper($key), $progress) === 0; - }, ARRAY_FILTER_USE_KEY))[0] ?? $this->emojis['pass']) . ': ') ; + return array_values(array_filter($this->emojis, function($emojikey) use ($character) { + return strrpos(strtoupper($emojikey), $character) === 0; + }, ARRAY_FILTER_USE_KEY))[0] ?? $this->emojis['pass']; } }