public function testGetContents() { $stream = tmpfile(); $streamObj = new Stream($stream); fputs($stream, __CLASS__); $this->assertSame(__CLASS__, $streamObj->getContents()); fputs($stream, ' foo'); $this->assertSame(__CLASS__ . ' foo', $streamObj->getContents()); fclose($stream); }
public function testSetOutputStream() { $firstStream = tmpfile(); $secondStream = tmpfile(); $text = __FILE__; $printer = new Printer($firstStream); $this->assertSame($printer, $printer->setOutputStream($secondStream)); $printer->defaultBox($text); $firstStreamObj = new Stream($firstStream); $secondStreamObj = new Stream($secondStream); $this->assertSame('', $firstStreamObj->getContents()); $this->assertContains($text, $secondStreamObj->getContents()); }
public function testAll() { $stream = tmpfile(); $cli = new Cli($stream); $called = false; $returnedCli = $cli->setWindowWidthGetter(function () use(&$called) { $called = true; return 35; }); $this->assertSame($cli, $returnedCli); $cli->displayException(new \Exception(__FILE__)); $streamObj = new Stream($stream); $output = $streamObj->getContents(); $this->assertTrue($called); $this->assertContains(__FILE__, $output); $this->assertContains(str_pad('', 35, '#'), $output); }
/** * @dataProvider callbacksDataProvider */ public function testCallbacks($preText, $exceptionText, $postText, $break, $stream, $expected) { $self = $this; $fakeException = new FakeException(); $exception = $fakeException->setMessage($exceptionText); $dumper = $this->createDumper(); $handler = new Handler($dumper); /** @var \PHPUnit_Framework_MockObject_MockObject|PreCallbackEvent $preCallback */ $preCallback = $this->getMockForAbstractClass('ErrorDumper\\Handlers\\PreCallbackEvent'); $preCallback->method('__invoke')->willReturnCallback(function ($currentE) use($stream, $exception, $preText, $break, $preCallback, $self) { $self->assertSame($exception, $currentE); fputs($stream, $preText); $break && $preCallback->stopDisplay(); }); $dumper->setOutputStream($stream); $handler->setPreCallback($preCallback); $handler->setPostCallback(function ($currentE) use($stream, $exception, $postText, $self) { $self->assertSame($exception, $currentE); fputs($stream, $postText); }); $handler($exception); $streamObj = new Stream($stream); $this->assertSame($expected, $streamObj->getContents()); }
/** * @param $exception * @param Editors\EditorInterface|null $editor * @param DumpFunctionInterface $varDumper * @return string * @throws Helpers\NotThrowableException */ public static function exportExceptionToLightHtml($exception, Editors\EditorInterface $editor = null, DumpFunctionInterface $varDumper = null) { $exceptions = new Exceptions(); $exceptions->throwIfIsNotThrowable($exception); is_null($editor) && ($editor = new Editors\Nothing()); $tmp = tmpfile(); $dumper = new Dumpers\Html($editor, $tmp); if (is_null($varDumper)) { $varDumper = new LightVarDumper(); } $dumper->setVarDumpFn($varDumper); $dumper->displayException($exception); $stream = new Stream($tmp); $result = $stream->getContents(); fclose($tmp); return $result; }