Completed
Pull Request — develop (#1)
by Yitzchok
07:13 queued 05:37
created

EmojiPrinter::writeProgress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Coderabbi\Phpumoji;
4
5
use PHPUnit\Framework\TestSuite;
6
use PHPUnit\TextUI\ResultPrinter;
7
use PHPUnit\Util\Xml;
8
9
final class EmojiPrinter extends ResultPrinter
10
{
11
    protected $emojis;
12
13
    public function startTestSuite(TestSuite $suite)
14
    {
15
        $config = Xml::loadFile($GLOBALS['__PHPUNIT_CONFIGURATION_FILE'], false, true, true)->documentElement;
16
        $emojiset = $config->hasAttribute('emojiset') ? $config->getAttribute('emojiset') : 'phpumoji';
17
18
        $this->emojis = require(__DIR__ . "/Emojisets/{$emojiset}");
19
20
        if ($this->numTests == -1) {
21
            $this->numTests = count($suite);
22
            $this->numTestsWidth = strlen((string) $this->numTests);
23
            $this->maxColumn = 40 - (2 * $this->numTestsWidth);
24
        }
25
26
        parent::startTestSuite($suite);
27
    }
28
29
    protected function writeProgress($progress)
30
    {
31
        return parent::writeProgress($this->emojify($progress));
32
    }
33
34
    protected function writeProgressWithColor($color, $progress)
35
    {
36
        return $this->writeProgress($progress);
37
    }
38
39
    private function emojify(string $progress) :string
40
    {
41
        return array_values(array_filter($this->emojis, function ($key) use ($progress) {
42
            return strrpos(strtoupper($key), $progress) === 0;
43
        }, ARRAY_FILTER_USE_KEY))[0] ?? $this->emojis['pass'];
44
    }
45
}
46