/** * @return Soap|\SoapClient */ protected function _getClient() { $host = Env::get('WEB_HOST', '127.0.0.1', Env::VAR_STRING); $port = Env::get('WEB_PORT', '8081', Env::VAR_STRING); $loc = Url::create(['host' => $host, 'port' => $port, 'path' => 'wsSSMaker.asmx']); /** @var Soap $client */ $client = new \SoapClient($loc . '?WSDL', ['trace' => true, 'location' => $loc]); return $client; }
/** * @param $testName * @param $request * @return Data */ public function request($testName, $request) { $cms = Cms::getInstance(); $host = Env::get('TEST_HOST', '127.0.0.1'); $port = Env::get('TEST_PORT'); $url = Url::create(['host' => $host, 'port' => $port]); $result = httpRequest($url, array_merge(['jbzoo-phpunit' => 1, 'jbzoo-phpunit-test' => $this->getTestName($testName), 'jbzoo-phpunit-type' => strtolower($cms['type'])], $request), 'GET', ['allow_redirects' => false, 'exceptions' => false, 'timeout' => 60, 'verify' => false]); if (!$result->getCode()) { var_dump($result); } return $result; }
/** * JBZooPHPUnit_Coverage constructor. * @SuppressWarnings(PHPMD.Superglobals) */ public function __construct() { if (Env::hasXdebug() && isset($_REQUEST['jbzoo-phpunit'])) { $cmsType = $_REQUEST['jbzoo-phpunit-type']; $testName = $_REQUEST['jbzoo-phpunit-test']; $this->_covRoot = realpath(__DIR__ . '/../..'); $this->_covDir = realpath($this->_covRoot . '/src'); $this->_covHash = implode('_', [md5(serialize($_REQUEST)), mt_rand(0, 100000000)]); $this->_covResult = realpath($this->_covRoot . '/build/coverage_cov') . '/' . $cmsType . '-' . $testName . '.cov'; $covFilter = new PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_covDir); $this->_coverage = new PHP_CodeCoverage(null, $covFilter); } }
/** * @return Driver */ protected function _getClient() { if (class_exists('\\GuzzleHttp\\Client') && (version_compare(Env::getVersion(), '5.3', '>') || Env::isHHVM())) { if (method_exists('\\GuzzleHttp\\Client', 'request')) { $client = new Guzzle6(); } elseif (method_exists('\\GuzzleHttp\\Client', 'createRequest')) { $client = new Guzzle5(); } } if (!isset($client)) { // Fallback driver $client = new Rmccue(); } return $client; }
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()); }
/** * CovCatcher constructor. * @param string $testName * @param array $options * @throws Exception */ public function __construct($testName = null, array $options = array()) { if (!class_exists('\\JBZoo\\Data\\Data')) { throw new Exception('jbzoo/data required for CovCatcher'); } if (!class_exists('\\JBZoo\\Utils\\Env')) { throw new Exception('jbzoo/utils required for CovCatcher'); } $this->_initConfig($options); $this->_hash = $this->_getPrefix($testName) . '_' . md5(serialize($this->_config->getArrayCopy()) . '|' . $testName); if (Env::hasXdebug()) { $covFilter = new \PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_config->get('src')); $this->_coverage = new \PHP_CodeCoverage(null, $covFilter); } }
public function testInclude() { $catcher = new CovCatcher(null, array('src' => PROJECT_TESTS . '/fixtures/includes', 'xml' => true, 'cov' => true, 'html' => true)); ob_start(); $return = $catcher->includeFile(PROJECT_TESTS . '/fixtures/includes/cov-catcher.php'); $echo = ob_get_contents(); ob_end_clean(); isSame(5, $return); isSame('Some text message', $echo); unset($catcher); // call destructor if (Env::hasXdebug()) { isDir(PROJECT_BUILD . '/coverage_cov'); isDir(PROJECT_BUILD . '/coverage_html'); isDir(PROJECT_BUILD . '/coverage_xml'); } }
public function testGet() { $array = $this->_data; $data = new Data($this->_data); $arrobj = new \ArrayObject($this->_data); $arrobjExt = new \ArrayObjectExt($this->_data); if (Env::isHHVM()) { $data->setFlags(0); } Benchmark::compare(array('Array::clean' => function () use($array) { return $array['prop']; }, 'Array::@' => function () use($array) { return @$array['prop']; }, 'Array::isset' => function () use($array) { return isset($array['prop']) ? $array['prop'] : null; }, 'Array::array_key_exists' => function () use($array) { return array_key_exists('prop', $array) ? $array['prop'] : null; }, 'ArrayObject::array' => function () use($arrobj) { return $arrobj['prop']; }, 'ArrayObject::offsetGet' => function () use($arrobj) { return $arrobj->offsetGet('prop'); }, 'ArrayObjectExt::array' => function () use($arrobjExt) { return $arrobjExt['prop']; }, 'ArrayObjectExt::offsetGet' => function () use($arrobjExt) { return $arrobjExt->offsetGet('prop'); }, 'Data::get' => function () use($data) { return $data->get('prop'); }, 'Data::arrow' => function () use($data) { return $data->prop; }, 'Data::array' => function () use($data) { return $data['prop']; }, 'Data::find' => function () use($data) { return $data->find('prop'); }, 'Data::offsetGet' => function () use($data) { return $data->offsetGet('prop'); }), array('name' => 'Get defined var', 'count' => 10000)); }
public function testGet() { putenv('FOO= 123 '); isSame('123', Env::get('FOO')); isSame(null, Env::get('UNDEFINED_VAR')); isSame(42, Env::get('UNDEFINED_VAR', 42)); isSame(42, Env::get('UNDEFINED_VAR', 42, Env::VAR_STRING)); }
/** * Progress wrapper (if use stepmode). * * @param string $name * @param int $total * @param int $stepSize * @param \Closure $onStart * @param \Closure $onStepMode * @param \Closure $onFinish */ protected function _progressWrap($name, $total, $stepSize, $onStart, $onStepMode, $onFinish) { $_this = $this; $step = $this->_getOpt('step'); $profile = $this->_getOpt('profile'); $stepMode = $this->_getOpt('stepmode'); $isFinished = false; if ($stepMode) { if ($step >= 0) { $onStepMode($step); } else { $this->_progressBar($name, $total, $stepSize, function ($currentStep) use($profile, $total, $_this, $name) { $phpBin = Env::getBinary(); $binPath = './' . FS::getRelative($_SERVER['SCRIPT_FILENAME'], JPATH_ROOT, '/'); $options = array('profile' => $profile, 'step' => (int) $currentStep, 'stepmode' => '', 'q' => ''); $command = $phpBin . ' ' . $binPath . ' ' . $name; $result = Cli::exec($command, $options, JPATH_ROOT, false); if (0 && $this->_isDebug()) { $_this->_($result); } return $currentStep <= $total; }); $isFinished = true; } } else { $isFinished = $onStart(); } $onFinish($isFinished); }
/** * Returns true if STDOUT supports colorization. * * This code has been copied and adapted from * Symfony\Component\Console\Output\OutputStream. * * @return bool * @codeCoverageIgnore */ public static function hasColorSupport() { if (DIRECTORY_SEPARATOR == '\\') { $winColor = Env::get('ANSICON', Env::VAR_BOOL) || 'ON' === Env::get('ConEmuANSI') || 'xterm' === Env::get('TERM'); return $winColor; } if (!defined('STDOUT')) { return false; } return self::isInteractive(STDOUT); }
* @link https://github.com/JBZoo/SSmaker-Server */ use JBZoo\Utils\Env; use JBZoo\Utils\Url; use Slim\Http\Request; use Slim\Http\Response; $_SERVER['SCRIPT_NAME'] = '/index.php'; // #F**K!!! https://bugs.php.net/bug.php?id=61286 if (!isset($app)) { // For PHPUnit reports return; } /** @var \Slim\App $app */ $app->any('/wsSSMaker.asmx', function (Request $req, Response $resp) { $serverHost = Env::get('WEB_HOST', $_SERVER['HTTP_HOST'], Env::VAR_STRING); $serverPort = Env::get('WEB_PORT', $_SERVER['SERVER_PORT'], Env::VAR_STRING); $cleanHost = str_replace(':' . $serverPort, '', $serverHost); $location = Url::create(['host' => $cleanHost, 'port' => $serverPort, 'path' => '/wsSSMaker.asmx']); $wsdlFile = __DIR__ . '/ssmaker.wsdl'; if ($req->getParam('WSDL') === '') { /** @var Response $resp */ $resp = $resp->withHeader('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT'); $resp = $resp->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); $resp = $resp->withHeader('Cache-Control', 'no-cache, must-revalidate, max-age=0'); $resp = $resp->withHeader('Pragma', 'no-cache'); $resp = $resp->withHeader('Content-type', 'application/wsdl+xm'); $resp->getBody()->write(file_get_contents($wsdlFile)); return $resp; } else { $server = new SoapServer($wsdlFile, ['location' => $location]); $server->setClass('JBZoo\\SSmakerServer\\Soap');
/** * Execute method of command * * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function execute(InputInterface $input, OutputInterface $output) { $this->_executePrepare($input, $output); $this->_init(); // Prepare if ((int) $this->_config->get('reindex', 0)) { $this->_('Database ReIndex = true', 'info'); $_GET['controller'] = $_REQUEST['controller'] = 'cli-import'; // emulate browser and admin CP } else { $this->_('Database ReIndex = false', 'info'); $_GET['controller'] = $_REQUEST['controller'] = 'jbimport'; // emulate browser and admin CP } $stepMode = $this->_getOpt('stepmode'); $step = $this->_getOpt('step'); $profileName = $this->_getOpt('profile'); $csvInfo = $this->_getCsvInfo(); $sesData = $this->_initJoomlaSession($csvInfo); $stepSize = $this->_getStepSize(); $rowsCount = $sesData['count']; $stepsCount = (int) ceil($rowsCount / $stepSize); if ($stepsCount <= 0) { $this->_('Count of steps is <= 0', 'Error', 1); } $this->_showProfiler('Import - prepared'); $this->_('CSV File: ' . $csvInfo['path'], 'Info'); $this->_('CSV lines: ' . $csvInfo['count'], 'Info'); $this->_('Step size: ' . $stepSize, 'Info'); $this->_('Steps count: ' . $stepsCount, 'Info'); $this->_('Step mode: ' . ($stepMode ? 'on' : 'off'), 'Info'); // Show progress bar and run process $jbimport = $this->_jbimport; $_this = $this; $isFinished = false; if ($stepMode) { if ($step >= 0) { $jbimport->itemsProcess($step); $this->_addTmpData($this->_jbsession->get('ids', 'import-ids')); } else { $this->_cleanTmpData(); $this->_progressBar('import', $stepsCount, 1, function ($currentStep) use($jbimport, $stepsCount, $profileName, $_this) { $phpBin = Env::getBinary(); $binPath = './' . FS::getRelative($_SERVER['SCRIPT_FILENAME'], JPATH_ROOT, '/'); $options = array('profile' => $profileName, 'step' => (int) $currentStep, 'stepmode' => '', 'q' => ''); $result = Cli::exec($phpBin . ' ' . $binPath . ' import:items', $options, JPATH_ROOT, false); if (0 && $this->_isDebug()) { $_this->_($result); } return $currentStep <= $stepsCount; }); $this->_jbsession->set('ids', $this->_getTmpData(), 'import-ids'); $isFinished = true; } } else { $this->_progressBar('import', $stepsCount, 1, function ($currentStep) use($jbimport) { $result = $jbimport->itemsProcess($currentStep); return $result['progress'] >= 100 ? false : true; }); $isFinished = true; } if ($isFinished) { $this->_showProfiler('Import - finished'); // Remove or disable other items $this->_jbsession->set('ids', $this->_getTmpData(), 'import-ids'); $this->_postImport(); $this->_showProfiler('Import - Post handler'); $this->_moveCsvFile($csvInfo['path']); $this->_showProfiler('Import - Done!'); $this->_cleanTmpData(); } }