/** * @param $url * @param array $arguments * @param string $uniqueId * * @throws \Exception * * @return string */ public function rasterizeUrl($url, $arguments = array(), $uniqueId = "") { if ($uniqueId === "") { $uniqueId = uniqid("rasterize-"); } if ($this->stopwatch instanceof Stopwatch) { if ($this->stopwatch->isStarted($uniqueId)) { $this->stopwatch->lap($uniqueId); } else { $this->stopwatch->start($uniqueId); } } $process = $this->configHelper->buildProcess($url, $uniqueId, $arguments); $exitCode = $process->run(); if ($exitCode != 0) { throw new \Exception(sprintf("Rasterize script failed.\nCommandLine: %s\nExitCode: %d\nErrorOutput: %s", $process->getCommandLine(), $process->getExitCode(), $process->getErrorOutput())); } if ($this->stopwatch instanceof Stopwatch) { $this->stopwatch->stop($uniqueId); } $output = $this->configHelper->getOutputFilePath($uniqueId); $content = file_get_contents($output); unlink($output); return $content; }
/** * @test */ public function arePhantomjsOptionsHandled() { $url = $this->configHelper->getOutputFileUrl('e4e5k2'); $this->configHelper->setConfig(array_merge_recursive($this->config, array('phantomjs' => array('options' => array('--ignore-ssl-errors' => true))))); $process = $this->configHelper->buildProcess($url, 'e4e5k2'); $this->assertContains(ProcessUtils::escapeArgument(sprintf('%s=%s', '--ignore-ssl-errors', 'true')), $process->getCommandLine()); $this->configHelper->setConfig(array_merge_recursive($this->config, array('phantomjs' => array('options' => array('--ignore-ssl-errors=true'))))); $process = $this->configHelper->buildProcess($url, 'e4e5k2'); $command = $process->getCommandLine(); $this->assertContains(ProcessUtils::escapeArgument('--ignore-ssl-errors=true'), $process->getCommandLine()); $this->assertNotContains('0', $command); }