<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik {
use Piwik\Tests\Framework\Mock\File;
function filesize($filename)
{
if (File::getFileSize() !== null) {
return File::getFileSize();
}
return \filesize($filename);
}
function file_exists($filename)
{
if (File::getFileExists() !== null) {
return File::getFileExists();
}
return \file_exists($filename);
}
}
namespace Piwik\Tests {
class Test {
public static function tester() { $size = self::getFileSize('test', 'MB');
return $size !== null && $size >= 100;
}
public static function getFileSize($pathToFile, $unit = 'B')
{
$unit = strtoupper($unit);
$units = array('TB' => pow(1024, 4),
'GB' => pow(1024, 3),
'MB' => pow(1024, 2),
'KB' => 1024,
'B' => 1);
if (!array_key_exists($unit, $units)) {
throw new Exception('Invalid unit given');
}
if (!file_exists($pathToFile)) {
return;
}
$filesize = filesize($pathToFile);
$factor = $units[$unit];
$converted = $filesize / $factor;
return $converted;
}
}
}
namespace Piwik\Tests\Framework\Mock {
class File
{
static $filesize = null;
static $fileExists = null;
public static function getFileSize()
{
return self::$filesize;
}
public static function setFileSize($filesize)
{
self::$filesize = $filesize;
}
public static function reset()
{
self::$filesize = null;
self::$fileExists = null;
}
public static function getFileExists()
{
return self::$fileExists;
}
public static function setFileExists($exists)
{
self::$fileExists = $exists;
}
}
}
File::setFileSize(1024 * 1024 * 99);
File::setFileExists(true);
var_dump(\Piwik\Test::tester());
File::setFileSize(1024 * 1024 * 101);
File::setFileExists(true);
var_dump(\Piwik\Test::tester());
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.35
- Fatal error: No code may exist outside of namespace {} in /in/2sBA0 on line 103
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
- Parse error: syntax error, unexpected T_STRING in /in/2sBA0 on line 8
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_STRING in /in/2sBA0 on line 8
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/2sBA0 on line 8
Process exited with code 255.
preferences:
231.96 ms | 1395 KiB | 125 Q