public function testMain() { ob_start(); dump(['test' => rand()]); // это тест! expect('Функция дампа не отдает результат', ob_get_clean())->notEmpty(); $this->assertInstanceOf(yii\log\Dispatcher::class, YiiLog()); $this->assertInstanceOf(yii\db\Connection::class, DB()); $this->assertInstanceOf(yii\base\ErrorHandler::class, ErrorHandler()); $this->assertInstanceOf(yii\caching\Cache::class, Cache()); $this->assertInstanceOf(yii\i18n\Formatter::class, Formatter()); $this->assertInstanceOf(yii\base\View::class, View()); $this->assertInstanceOf(yii\i18n\I18N::class, I18N()); $this->assertInstanceOf(yii\rbac\ManagerInterface::class, AuthManager()); $this->assertInstanceOf(yii\web\AssetManager::class, AssetManager()); $this->assertInstanceOf(yii\web\User::class, User()); $this->assertInstanceOf(yii\base\Request::class, Request()); $this->assertInstanceOf(yii\base\Response::class, Response()); $this->assertInstanceOf(yii\web\Session::class, Session()); $this->assertInstanceOf(yii\web\UrlManager::class, UrlManager()); $this->assertInstanceOf(yii\mail\MailerInterface::class, Mailer()); $this->assertInstanceOf(services\File\Service::class, FileService()); $this->assertInstanceOf(services\Activity\Service::class, ActivityService()); }
private function _request($urlType, $urlData = array()) { $rtn = array('rc' => self::RC_SUC, 'info' => array(), 'qheader' => array(), 'pheader' => array(), 'data' => '', 'urlType' => $urlType); if (is_array($urlType)) { $urlConfig = $urlType; } elseif (ctype_alnum($urlType)) { //现阶段不支持URL配置 //$urlConfig = self::getUrlConfig($urlType); } else { $urlConfig = array('reqUrl' => $urlType); } $urlConfig['reqUrl'] = preg_replace('/(%[2-5])/', '%$1', $urlConfig['reqUrl']); $urlConfig = self::arrayMerge(array('reqLogUrl' => False, 'reqLogPData' => False, 'reqLogQData' => False), $urlConfig); array_unshift($urlData, $urlConfig['reqUrl']); $url = call_user_func_array('sprintf', $urlData); $this->setOpt(array(CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $this->getCurlHeader())); $content = curl_exec($this->handler); $rtn['info'] = curl_getinfo($this->handler); if (empty($rtn['info']['request_header'])) { $rtn['info']['request_header'] = ''; } $rtn['qheader'] = $this->headerStr2Arr($rtn['info']['request_header']); $urlConfig['reqLogUrl'] && YiiLog(self::getLog(array('请求地址:%s', $url))); $urlConfig['reqLogUrl'] && !empty($rtn['qheader']['Cookie']) && YiiLog(self::getLog(array('请求Cookie:%s', $rtn['qheader']['Cookie']))); if ($rtn['info']['http_code'] != '200') { $rtn['rc'] = $rtn['info']['http_code']; $rtn['info']['error_no'] = curl_errno($this->handler); $rtn['info']['error_msg'] = curl_error($this->handler); return $rtn; } $content = explode("\r\n\r\n", $content, 2); if (count($content) < 2) { $rtn['data'] = $content[0]; } else { //在uuwise中的上传验证码步骤 返回两个头 其中第一个为 HTTP/1.1 100 Continue $tmp = explode("\r\n", $content[1]); if (preg_match('/\\s*?HTTP\\/1.[01]\\s+?\\d{3}\\s+?\\w+?\\s*?/i', $tmp[0])) { $content = explode("\r\n\r\n", $content[1], 2); } $rtn['pheader'] = $this->headerStr2Arr($content[0]); $rtn['data'] = count($content) < 2 ? $content[0] : $content[1]; if ($this->autoSetCookie && !empty($rtn['pheader']['Set-Cookie'])) { $this->setHeader(array('Cookie' => $rtn['pheader']['Set-Cookie'])); } } $urlConfig['reqLogPData'] && YiiLog(self::getLog(array('返回数据:%s', $rtn['data']))); $urlConfig['reqLogUrl'] && !empty($rtn['pheader']['Set-Cookie']) && YiiLog(self::getLog(array('响应Cookie:%s', $rtn['pheader']['Set-Cookie']))); return $rtn; }