public function testOutputGivesNoSideEffects() { $this->adapter->validateOutput(); ob_start(); $buffer = $this->adapter->output(); $sideEffectsBuffer = ob_get_clean(); $this->assertNotEmpty($buffer); $this->assertEmpty($sideEffectsBuffer); }
public function testAdapterRequiresViewRenderer() { $this->adapter->validateOutput(); $this->getDI()->remove('view'); try { $this->adapter->output(); $this->fail(); } catch (\Exception $e) { $this->assertInstanceOf('\\Vegas\\Mvc\\Exception', $e); } }
public function testOutputWithoutHeaders() { $this->config->setExtraSettings(['skipHeaders' => true]); $buffer = $this->adapter->output(); $sampleCsv = 'zażółć gęślą,jaźń'; $this->assertSame($sampleCsv, $buffer); }
public function testUseObjectDataForOutput() { $object = new \stdClass(); $object->bar = 'zażółć gęślą'; $object->foo = 'jaźń'; $this->config->setHeaders(['foo', 'bar', 'empty']); $this->config->setData([$object]); $buffer = $this->adapter->output(); $prettyPrintXml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <root> <item> <foo>jaźń</foo> <bar>zażółć gęślą</bar> <empty></empty> </item> </root> XML; $this->assertSame($prettyPrintXml, rtrim($buffer, PHP_EOL)); }
/** * Saves export output under specified filepath without downloading. * Proxied via __call() method * @param AdapterInterface $adapter */ protected function save(AdapterInterface $adapter) { $output = $adapter->output(); $filename = $this->config->getFilename() . $adapter->getExtension(); $filepath = implode(DIRECTORY_SEPARATOR, [$this->config->getOutputDir(), $filename]); $file = fopen($filepath, 'wb'); fwrite($file, $output); fclose($file); }