public function testClearErrors() { $io = new BufferedIO(); $io->error('Lorem'); $io->clearErrors(); $io->error('ipsum'); $this->assertSame('ipsum', $io->fetchErrors()); }
public function testRenderWithCauseIfVeryVerbose() { $this->io->setVerbosity(IO::VERY_VERBOSE); $cause = new RuntimeException('The message of the cause.'); $exception = NoSuchCommandException::forCommandName('foobar', 0, $cause); $trace = new ExceptionTrace($exception); $trace->render($this->io); // Prevent trimming of trailing spaces in the box $box1 = ' ' . "\n" . ' [Webmozart\\Console\\Api\\Command\\NoSuchCommandException] ' . "\n" . ' The command "foobar" does not exist. ' . "\n" . ' '; $expected1 = <<<EOF {$box1} Exception trace: () src/Api/Command/NoSuchCommandException.php:?? Webmozart\\Console\\Api\\Command\\NoSuchCommandException::forCommandName() tests/UI/Component/ExceptionTraceTest.php EOF; $box2 = ' ' . "\n" . ' [RuntimeException] ' . "\n" . ' The message of the cause. ' . "\n" . ' '; $expected2 = <<<EOF Caused by: {$box2} Exception trace: () tests/UI/Component/ExceptionTraceTest.php EOF; $actual = $this->io->fetchErrors(); // Normalize line numbers across PHP and HHVM $actual = preg_replace('~(NoSuchCommandException.php:)\\d+~', '$1??', $actual); // Normalize slashes across OS $expected1 = str_replace(array("\n", '/'), array(PHP_EOL, DIRECTORY_SEPARATOR), $expected1); $expected2 = str_replace(array("\n", '/'), array(PHP_EOL, DIRECTORY_SEPARATOR), $expected2); $this->assertStringStartsWith($expected1, $actual); $this->assertContains($expected2, $actual); $this->assertStringEndsWith(PHP_EOL . PHP_EOL, $actual); }