PHP Classes

File: tests/Highlights/ConsoleHighlightTest.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Var-Dump   tests/Highlights/ConsoleHighlightTest.php   Download  
File: tests/Highlights/ConsoleHighlightTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Var-Dump
Show the value of a variable in colored way
Author: By
Last change:
Date: 1 month ago
Size: 2,755 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Tests\Highlights;

use
Chevere\Parameter\Interfaces\TypeInterface;
use
Chevere\Tests\Traits\StripANSIColorsTrait;
use
Chevere\VarDump\Highlights\ConsoleHighlight;
use
Chevere\VarDump\Interfaces\HighlightInterface;
use
Chevere\VarDump\Interfaces\VarDumperInterface;
use
Colors\Color;
use
OutOfRangeException;
use
PHPUnit\Framework\TestCase;

final class
ConsoleHighlightTest extends TestCase
{
    use
StripANSIColorsTrait;

    public function
testInvalidArgumentConstruct(): void
   
{
       
$this->expectException(OutOfRangeException::class);
        new
ConsoleHighlight('invalid-argument');
    }

    public function
testConstruct(): void
   
{
       
$dump = 'string';
       
$open = '[38;5;';
       
$close = '';
       
$expect = [
           
TypeInterface::STRING => '%c0%m' . $dump,
           
TypeInterface::FLOAT => '%c0%m' . $dump,
           
TypeInterface::INT => '%c0%m' . $dump,
           
TypeInterface::BOOL => '%c0%m' . $dump,
           
TypeInterface::NULL => '%c0%m' . $dump,
           
TypeInterface::OBJECT => '%c0%m' . $dump,
           
TypeInterface::ARRAY => '%c0%m' . $dump,
           
TypeInterface::RESOURCE => '%c0%m' . $dump,
           
VarDumperInterface::FILE => '%c0%m' . $dump,
           
VarDumperInterface::CLASS_REG => '%c0%m' . $dump,
           
VarDumperInterface::OPERATOR => '%c0%m' . $dump,
           
VarDumperInterface::FUNCTION => '%c0%m' . $dump,
           
VarDumperInterface::MODIFIER => '%c0%m' . $dump,
           
VarDumperInterface::VARIABLE => '%c0%m' . $dump,
           
VarDumperInterface::EMPHASIS => '%c1%m' . $open . '%c0%m' . $dump . $close,
        ];
       
$palette = ConsoleHighlight::palette();
        foreach (
$expect as $k => &$v) {
           
$paletteColor = $palette[$k];
            if (!
is_array($paletteColor)) {
               
$paletteColor = [$paletteColor];
            }
            foreach (
$paletteColor as $pos => $colorCode) {
               
$v = str_replace("%c{$pos}%", $colorCode, $v);
            }
           
$v = $open . $v . $close;
        }
       
$color = new Color();
        foreach (
HighlightInterface::KEYS as $key) {
           
$highlight = new ConsoleHighlight($key);
           
$string = $highlight->highlight($dump);
           
$expected = $expect[$key];
            if (
$color->isSupported() === false) {
               
$expected = $this->stripANSIColors($expected);
            }
           
$this->assertSame($expected, $string);
        }
    }
}