<?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);
}
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.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- bool(false)
bool(true)
- Output for 5.2.3 - 5.2.17
- Parse error: syntax error, unexpected T_STRING in /in/RrWln on line 8
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
- <br />
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>/in/RrWln</b> on line <b>8</b><br />
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
- <br />
<b>Parse error</b>: parse error, unexpected T_STRING in <b>/in/RrWln</b> on line <b>8</b><br />
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- <br />
<b>Parse error</b>: parse error in <b>/in/RrWln</b> on line <b>8</b><br />
Process exited with code 255.
preferences:
287.03 ms | 401 KiB | 469 Q