diff --git a/tests/PHPUnit/Fixtures/SqlDump.php b/tests/PHPUnit/Fixtures/SqlDump.php index 589ffd1e0f7..3a732cd0c0a 100644 --- a/tests/PHPUnit/Fixtures/SqlDump.php +++ b/tests/PHPUnit/Fixtures/SqlDump.php @@ -36,20 +36,12 @@ public function setUp() $dumpPath = $this->dumpUrl; } else { $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz'; - $bufferSize = 1024 * 1024; + $bytesRead = $this->downloadDumpInPath($dumpPath); - $dump = fopen($this->dumpUrl, 'rb'); - $outfile = fopen($dumpPath, 'wb'); - $bytesRead = 0; - while (!feof($dump)) { - fwrite($outfile, fread($dump, $bufferSize), $bufferSize); - $bytesRead += $bufferSize; - } - fclose($dump); - fclose($outfile); - - if ($bytesRead <= 40 * 1024 * 1024) { // sanity check - throw new Exception("Could not download sql dump!"); + // sanity check + if ($bytesRead <= 40 * 1024 * 1024) { + $str = "Could not download sql dump! You can manually download %s into %s"; + throw new Exception(sprintf($str, $this->dumpUrl, $dumpPath)); } } @@ -93,4 +85,24 @@ public function tearDown() { // empty } + + /** + * @param $dumpPath + * @return int + */ + protected function downloadDumpInPath($dumpPath) + { + $bufferSize = 1024 * 1024; + + $dump = fopen($this->dumpUrl, 'rb'); + $outfile = fopen($dumpPath, 'wb'); + $bytesRead = 0; + while (!feof($dump)) { + fwrite($outfile, fread($dump, $bufferSize), $bufferSize); + $bytesRead += $bufferSize; + } + fclose($dump); + fclose($outfile); + return $bytesRead; + } } \ No newline at end of file diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index 6735a8d1269..693b76e2804 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -727,6 +727,10 @@ public static function downloadAndUnzip($url, $outputDir, $filename) $dump = fopen($url, 'rb'); $outfile = fopen($outfileName, 'wb'); + if(!$outfile) { + throw new Exception("Failed to create file $outfileName - please check permissions"); + } + while (!feof($dump)) { fwrite($outfile, fread($dump, $bufferSize), $bufferSize); }