123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace League\CLImate\Tests\Decorator\Parser;
- use League\CLImate\Decorator\Parser\Ansi;
- use League\CLImate\Decorator\Parser\NonAnsi;
- use League\CLImate\Decorator\Parser\ParserFactory;
- use League\CLImate\Decorator\Style;
- use League\CLImate\Decorator\Tags;
- use League\CLImate\TerminalObject\Basic\BasicTerminalObject;
- use League\CLImate\TerminalObject\Router\BasicRouter;
- use League\CLImate\Tests\TestBase;
- use League\CLImate\Util\System\Linux;
- use League\CLImate\Util\System\Windows;
- use League\CLImate\Util\UtilFactory;
- use Mockery;
- class AnsiTest extends TestBase
- {
- /**
- * @test
- * @doesNotPerformAssertions
- */
- public function it_can_output_with_ansi()
- {
- $router = new BasicRouter();
- $router->output($this->output);
- $style = new Style();
- $parser = new Ansi($style->current(), new Tags($style->all()));
- $obj = Mockery::mock(BasicTerminalObject::class);
- $obj->shouldReceive('result')->once()->andReturn("<green>I am green</green>");
- $obj->shouldReceive('sameLine')->once()->andReturn(false);
- $obj->shouldReceive('getParser')->once()->andReturn($parser);
- $this->shouldWrite("\e[m\e[32mI am green\e[0m\e[0m");
- $this->shouldHavePersisted();
- $router->execute($obj);
- }
- /**
- * @test
- * @doesNotPerformAssertions
- */
- public function it_can_output_without_ansi()
- {
- $router = new BasicRouter();
- $router->output($this->output);
- $style = new Style();
- $parser = new NonAnsi($style->current(), new Tags($style->all()));
- $obj = Mockery::mock(BasicTerminalObject::class);
- $obj->shouldReceive('result')->once()->andReturn("<green>I am not green</green>");
- $obj->shouldReceive('sameLine')->once()->andReturn(false);
- $obj->shouldReceive('getParser')->once()->andReturn($parser);
- $this->shouldWrite("I am not green");
- $this->shouldHavePersisted();
- $router->execute($obj);
- }
- /** @test */
- public function it_will_recognize_non_ansi_systems()
- {
- $system = Mockery::mock(Windows::class);
- $system->shouldReceive('hasAnsiSupport')->andReturn(false);
- $parser = ParserFactory::getInstance($system, [], new Tags([]));
- $this->assertInstanceOf(NonAnsi::class, $parser);
- }
- /**
- * @test
- * @doesNotPerformAssertions
- */
- public function it_will_force_ansi_on_a_non_ansi_system()
- {
- $system = new Windows();
- $util = new UtilFactory($system);
- $this->cli->setUtil($util);
- $this->cli->forceAnsiOn();
- $this->shouldWrite("\e[m\e[32mI am green\e[0m\e[0m");
- $this->shouldHavePersisted();
- $this->cli->out("<green>I am green</green>");
- }
- /**
- * @test
- * @doesNotPerformAssertions
- */
- public function it_will_force_ansi_off_on_an_ansi_system()
- {
- $system = new Linux();
- $util = new UtilFactory($system);
- $this->cli->setUtil($util);
- $this->cli->forceAnsiOff();
- $this->shouldWrite("I am green");
- $this->shouldHavePersisted();
- $this->cli->out("<green>I am green</green>");
- }
- /**
- * Ensure we can check if stdout is defined safely.
- * https://github.com/thephpleague/climate/issues/185
- */
- public function test6()
- {
- $system = new Linux();
- $util = new UtilFactory($system);
- $this->cli->setUtil($util);
- $this->output->shouldReceive('write')->times(1);
- $this->shouldHavePersisted();
- $this->cli->out("<green>I am green</green>");
- self::assertTrue(true);
- }
- }
|