/** * @Then /^The package can be downloaded to system\'s tmp dir$/ */ public function thePackageCanBeDownloadedToSystemSTmpDir() { $this->dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-doc-parser-test'; @mkdir($this->dir); $file = $this->dir . DIRECTORY_SEPARATOR . $this->package->getOrigFilename(); $this->package->download($file); }
/** * @Then /^download manual from "([^"]*)" package from "([^"]*)"$/ */ public function downloadManualFromPackageFrom($lang, $mirror) { $this->package = new Package($lang, $mirror); $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-doc-parser-test'; @mkdir($dir); $file = $dir . DIRECTORY_SEPARATOR . $this->package->getOrigFilename(); $this->package->download($file); $testUnpackDir = $this->package->unpack(array_map(function ($item) { return $item['source-filename']; }, $this->testFiles)); $this->unpackedFilesDir = $this->package->getUnpackedDir(); assertEquals($testUnpackDir, $this->unpackedFilesDir); assertCount(count($this->testFiles), glob($this->unpackedFilesDir . DIRECTORY_SEPARATOR . '*.html')); }
private function downloadPackage(Package $package) { $url = $package->getUrl(); preg_match('/\\/(php_manual.*)\\//U', $url, $matches); $filePath = $this->getTmpDir() . DIRECTORY_SEPARATOR . $matches[1]; @mkdir(dirname($filePath), 0777, true); $bar = $this->createProgressBar(); $bar->setMessage('Downloading <comment>' . $package->getUrl() . '</comment> to <comment>' . $filePath . '</comment>'); $bar->start(); $package->download($filePath, function ($r, $downloadSize, $downloaded) use($bar) { if ($downloadSize > 0) { $bar->setProgress(round($downloaded / $downloadSize * 100)); } }); $bar->finish(); $this->output->writeln(''); if (0 == filesize($filePath)) { $this->output->writeln('<error>Download failed. Please, check selected mirror site.</error>'); } }