/** * Stop profiler */ public function stop() { $this->_endTime = microtime(true); $this->tick(); if (Sys::isFunc('unregister_tick_function')) { unregister_tick_function(array($this, 'tick')); } }
public function testNestedIndexCoverage() { $uniq = uniqid(); $result = httpRequest('http://localhost:8888/folder/not-index.php', array('test' => $uniq)); isSame('folder/not-index: ' . $uniq, $result->getBody()); isSame(200, $result->getCode()); if (Sys::hasXdebug() && !Sys::isPHP7()) { isDir(PROJECT_BUILD . '/coverage_cov'); isDir(PROJECT_BUILD . '/coverage_html'); isDir(PROJECT_BUILD . '/coverage_xml'); } }
public function testJBDumpForWeb() { if (!class_exists('\\JBZoo\\Utils\\Sys')) { throw new Exception('jbzoo/utils required for Tools unit-tests'); } if (Sys::isPhp53() || Sys::isPhp7() || Env::isHHVM()) { skip('PHP 5.3.x/7.0/hhvm doen\'t support built-in web-server'); } $uniq = uniqid(); $result = httpRequest('http://localhost:8889/', array('test' => 'jbdump', 'test-var' => $uniq)); isSame(200, $result->getCode()); isContain('#jbdump', $result->getBody()); isContain('Dump die', $result->getBody()); isContain($uniq, $result->getBody()); }
public function testGetRemote() { $_SERVER['REMOTE_ADDR'] = '192.168.0.1'; $_SERVER['HTTP_CLIENT_IP'] = '192.168.0.2'; $_SERVER['HTTP_X_REAL_IP'] = '192.168.0.3'; $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.4'; is('192.168.0.1', Sys::IP()); // Check deprecated method is('192.168.0.1', IP::getRemote()); is('192.168.0.2', IP::getRemote(true)); unset($_SERVER['HTTP_CLIENT_IP']); is('192.168.0.3', IP::getRemote(true)); unset($_SERVER['HTTP_X_REAL_IP']); is('192.168.0.4', IP::getRemote(true)); unset($_SERVER['HTTP_X_FORWARDED_FOR']); is('192.168.0.1', IP::getRemote(true)); }
/** * @param array $options * @return Data * @throws Exception * @SuppressWarnings(PHPMD.Superglobals) */ protected function _prepareOptions(array $options) { // Default data for current system $this->_default['root_url'] = Url::root(); $this->_default['root_path'] = Sys::getDocRoot(); $options = array_merge($this->_default, $options); // Check cache directory $cachePath = FS::clean($options['cache_path']); if (!$cachePath) { throw new Exception('Option "cache_path" is empty!'); } if (!FS::isDir($cachePath)) { mkdir($cachePath, 0755, true); } $options['cache_path'] = FS::real($cachePath); $options['root_url'] = rtrim($options['root_url'], '/'); $options['root_path'] = FS::real($options['root_path']); $options['driver'] = ucfirst(strtolower(trim($options['driver']))); // Check mixin paths $lessFile = (array) $options['autoload']; foreach ($lessFile as $key => $mixin) { $lessFile[$key] = FS::real($mixin); } $options['autoload'] = array_filter($lessFile); // Check imported paths $importPaths = []; foreach ((array) $options['import_paths'] as $path => $uri) { if ($cleanPath = FS::real($path)) { $importPaths[$cleanPath] = $uri; } } $importPaths[$options['root_path']] = $options['root_url']; // Forced add root path in the end of list! $options['import_paths'] = array_filter($importPaths); return new Data($options); }
/** * @return int */ protected function _setEnv() { // set limits & reporting if ($this->_isDebug()) { error_reporting(-1); } else { error_reporting(E_ERROR | E_WARNING); } $memory = $this->_globConfig->get('memory', '1024M'); $time = (int) $this->_globConfig->get('time', 1800); Sys::iniSet('display_errors', 1); Sys::setTime($time); Sys::setMemory($memory); }
public function testPredefinedRoot() { $_SERVER['HTTP_HOST'] = 'test.dev'; $_SERVER['SERVER_PORT'] = 80; $_SERVER['REQUEST_URI'] = '/page'; // defult $sysRoot = Sys::getDocRoot(); $path = new Path(); $this->_is($sysRoot, $path->getRoot()); // custom $path = new Path(PROJECT_ROOT); $this->_is(PROJECT_ROOT, $path->getRoot()); $this->_is(PROJECT_ROOT, $path->get('root:')); $this->_is(PROJECT_SRC, $path->get('root:src')); isSame('src', $path->rel('root:src')); isSame('/src', $path->url('root:src', false)); isSame('http://test.dev/src', $path->url('root:src', true)); }
/** * Path constructor. * @param string $root */ public function __construct($root = null) { $root = $root ?: Sys::getDocRoot(); $this->setRoot($root); }
/** * @return bool */ protected function _isPHP53() { return Sys::isPHP53(); }
/** * @return array */ protected function _getExif() { $result = array(); if ($this->_filename && Sys::isFunc('exif_read_data') && Helper::isJpeg($this->_mime)) { $result = exif_read_data($this->_filename); } return $result; }
/** * @covers JBZoo\Utils\Sys::getVendorUrl * @uses JBZoo\Utils\Sys::isHHVM */ public function testVendorUrlCanBeRetrieved() { $this->assertInternalType('string', Sys::getVendorUrl()); }
public function testGetHome() { // Test for OS Default. isTrue(is_writable(Sys::getHome())); $oldServer = $_SERVER; unset($_SERVER); // Test for UNIX. $_SERVER['HOME'] = '/home/unknown'; is($_SERVER['HOME'], Sys::getHome(), 'Could not get the user\'s home directory in UNIX.'); unset($_SERVER); // Test for Windows. $expected = 'X:\\Users\\ThisUser'; $_SERVER['HOMEDRIVE'] = 'X:'; $_SERVER['HOMEPATH'] = '\\Users\\ThisUser'; is($expected, Sys::getHome(), 'Could not get the user\'s home directory in Windows.'); // In case the tests are not being run in isolation. $_SERVER = $oldServer; }
if (is_dir($path)) { $realIndex = $path . '/index.php'; } elseif (is_file($path)) { if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') { return false; } $realIndex = $path; } } // Try to find and load composer autoloader $vendorPaths = [realpath(__DIR__ . '/vendor/autoload.php'), realpath(__DIR__ . '/../vendor/autoload.php'), realpath(__DIR__ . '/../../vendor/autoload.php'), realpath(__DIR__ . '/../../../vendor/autoload.php'), realpath(__DIR__ . '/../../../../vendor/autoload.php'), realpath(__DIR__ . '/../../../../../vendor/autoload.php'), realpath('./vendor/autoload.php')]; foreach ($vendorPaths as $vendorPath) { if ($vendorPath && file_exists($vendorPath)) { require_once $vendorPath; break; } } // Parse additional options $cliOptions = new Getopt([[null, 'index', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-src', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-xml', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-cov', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-html', Getopt::OPTIONAL_ARGUMENT]]); $cliOptions->parse(getenv('PHPUNINT_ARGUMENTS')); $realIndex = isset($realIndex) ? $realIndex : realpath($cliOptions->getOption('index')); if (class_exists('\\JBZoo\\PHPUnit\\CovCatcher') && !(Sys::isPHP7() && Sys::hasXdebug())) { $testname = (new Data($_REQUEST))->get('testname'); $coverHash = md5(implode('||', [serialize($_REQUEST), serialize($_SERVER), PHP_VERSION])); $coverHash = $testname ? $testname . '-' . $coverHash : $testname; $covCatcher = new CovCatcher($coverHash, ['src' => $cliOptions->getOption('cov-src'), 'xml' => $cliOptions->getOption('cov-xml'), 'cov' => $cliOptions->getOption('cov-cov'), 'html' => $cliOptions->getOption('cov-html')]); $result = $covCatcher->includeFile($realIndex); } else { $result = (require_once $realIndex); } return $result;