Best Mockery code snippet using are._getReturnValue
TracRPC.php
Source:TracRPC.php
...69 } elseif (is_numeric($date) === true) {70 $date = array('datetime', date("o-m-d\TH:i:s+00:00", $date));71 }72 $this->_addRequest('wiki.getRecentChanges', array(array('__jsonclass__' => $date)));73 return $this->_getReturnValue();74 }75 /**76 * Get a wiki page in it's RAW format or HTML. Can get a version of a page.77 *78 * @param string $name Wiki page name.79 * @param int $version Version of the page to get.80 * @param bool $raw true gets raw wiki page. false will return HTML.81 * @return mixed The result of the request or the integer id on a multicall. false on error.82 */83 public function getWikiPage($name = '', $version = 0, $raw = true)84 {85 if ($name === '') {86 throw new \InvalidArgumentException('Parameter $name is empty. Please specify the WikiPage name you want to fetch.');87 }88 if ($version == 0) {89 if ($raw === true) {90 $this->_addRequest('wiki.getPage', array($name));91 } else {92 $this->_addRequest('wiki.getPageHTML', array($name));93 }94 } else {95 if ($raw === true) {96 $this->_addRequest('wiki.getPageVersion', array($name, $version));97 } else {98 $this->_addRequest('wiki.getPageHTMLVersion', array($name, $version));99 }100 }101 return $this->_getReturnValue();102 }103 /**104 * Get page info for a specific wiki page and possible version of the page.105 *106 * @param string $name107 * @param int $version108 * @return mixed The result of the request or the integer id on a multicall. false on error.109 */110 public function getWikiPageInfo($name = '', $version = 0)111 {112 if ($name === '') {113 throw new \InvalidArgumentException('Parameter $name is empty. Please specify the WikiPage name you want to fetch.');114 }115 if ($version == 0) {116 $this->_addRequest('wiki.getPageInfo', array($name));117 } else {118 $this->_addRequest('wiki.getPageInfoVersion', array($name, $version));119 }120 return $this->_getReturnValue();121 }122 /**123 * Get a list of wiki pages in TRAC.124 *125 * @return mixed The result of the request or the integer id on a multicall. false on error.126 */127 public function getWikiPages()128 {129 $this->_addRequest('wiki.getAllPages');130 return $this->_getReturnValue();131 }132 /**133 * Get the recent changed tickets.134 *135 * @param int $date A timestamp integer. Defaults to current day.136 * @return mixed The result of the request or the integer id on a multicall. false on error.137 */138 public function getRecentChangedTickets($date = 0)139 {140 if ($date == false) {141 $date = array('datetime', date("o-m-d\T00:00:00"));142 } elseif (is_numeric($date) === true) {143 $date = array('datetime', date("o-m-d\TH:i:s+00:00", $date));144 }145 $this->_addRequest('ticket.getRecentChanges', array(array('__jsonclass__' => $date)));146 return $this->_getReturnValue();147 }148 /**149 * Get a ticket.150 *151 * @param string $id The id of the ticket.152 * @return mixed The result of the request or the integer id on a multicall. false on error.153 */154 public function getTicket($id = '')155 {156 if ($id === '') {157 throw new \InvalidArgumentException('Parameter $id is empty.');158 }159 $this->_addRequest('ticket.get', $id);160 return $this->_getReturnValue();161 }162 /**163 * Get a all ticket fields.164 *165 * @return mixed The result of the request or the integer id on a multicall. false on error.166 */167 public function getTicketFields()168 {169 $this->_addRequest('ticket.getTicketFields');170 return $this->_getReturnValue();171 }172 /**173 * Get the recent changed tickets.174 *175 * @param string $id The id of the ticket.176 * @param int $when When in the changelog.177 * @return mixed The result of the request or the integer id on a multicall. false on error.178 */179 public function getTicketChangelog($id = '', $when = 0)180 {181 if ($id === '') {182 throw new \InvalidArgumentException('Parameter $id empty.');183 }184 $this->_addRequest('ticket.changeLog', array($id, $when));185 return $this->_getReturnValue();186 }187 /**188 * Get a ticket actions.189 *190 * @param string $id The id of the ticket.191 * @return mixed The result of the request or the integer id on a multicall. false on error.192 */193 public function getTicketActions($id = '')194 {195 if ($id === '') {196 throw new \InvalidArgumentException('Parameter $id empty.');197 }198 $this->_addRequest('ticket.getActions', $id);199 return $this->_getReturnValue();200 }201 /**202 * Perform requests relating to attachments for wiki pages.203 *204 * Get a list of attachments for a wiki page.205 * Get an attachment for a wiki page.206 * Delete an attachment for a wiki page.207 * Creat an attachment for a wiki page.208 *209 * @param string $action What action to perform for ticket attachments.210 * Possible values list, get, delete, or create.211 * Default list.212 * @param string $name The pagename of the wiki page.213 * @param string $file Filenamepath of the file to add to the wiki page.214 * @return mixed The result of the request or the integer id on a multicall. false on error.215 */216 public function getWikiAttachments($action = 'list', $name = '', $file = '')217 {218 if ($name === '') {219 throw new \InvalidArgumentException('Parameter $name empty.');220 }221 $params = array($name);222 switch ($action) {223 case 'list':224 default:225 $method = 'wiki.listAttachments';226 break;227 case 'get':228 if ($file === '') {229 throw new \InvalidArgumentException('Parameter $file empty.');230 }231 $method = 'wiki.getAttachment';232 $params[] = $file;233 break;234 case 'delete':235 if ($file === '') {236 throw new \InvalidArgumentException('Parameter $file empty.');237 }238 $method = 'wiki.deleteAttachment';239 $params[] = $file;240 break;241 case 'create':242 if (is_file($file) === false) {243 return false;244 }245 $contents = file_get_contents($file, FILE_BINARY);246 if ($contents === true) {247 $contents = array('__jsonclass__' => array('binary', base64_encode($contents)));248 }249 $method = 'wiki.putAttachment';250 $params[] = basename($file);251 $params[] = $contents;252 break;253 }254 $this->_addRequest($method, $params);255 return $this->_getReturnValue();256 }257 /**258 * Perform requests relating to attachments for tickets.259 *260 * Get a list of attachments for a ticket.261 * Get an attachment for a ticket.262 * Delete an attachment for a ticket.263 * Create an attachment for a ticket.264 *265 * @param string $action What action to perform for ticket attachments.266 * Possible values list, get, delete, or create.267 * Default list.268 * @param string $id The id of the ticket.269 * @param string $file Filenamepath of the file to add to the ticket.270 * @param string $desc Description of the attachment.271 * @param bool $replace true will replace the attachment if it exists false will not replace it.272 * @return mixed The result of the request or the integer id on a multicall. false on error.273 */274 public function getTicketAttachments($action = 'list', $id = '', $file = '', $desc = '', $replace = true)275 {276 if ($id === '') {277 throw new \InvalidArgumentException('Parameter $id empty.');278 }279 $params = array($id);280 switch ($action) {281 case 'list':282 default:283 $method = 'ticket.listAttachments';284 break;285 case 'get':286 if ($file === '') {287 throw new \InvalidArgumentException('Parameter $file empty.');288 }289 $method = 'ticket.getAttachment';290 $params[] = $file;291 break;292 case 'delete':293 if ($file === '') {294 throw new \InvalidArgumentException('Parameter $file empty.');295 }296 $method = 'ticket.deleteAttachment';297 $params[] = $file;298 break;299 case 'create':300 if (is_file($file) === false) {301 return false;302 }303 $contents = file_get_contents($file, FILE_BINARY);304 if ($contents === true) {305 $contents = array('__jsonclass__' => array('binary', base64_encode($contents)));306 }307 $method = 'ticket.putAttachment';308 $params[] = basename($file);309 $params[] = $desc;310 $params[] = $contents;311 $params[] = $replace;312 break;313 }314 $this->_addRequest($method, $params);315 return $this->_getReturnValue();316 }317 /**318 * Create or delete a wiki page.319 *320 * @param string $action What action to perform for a ticket.321 * Possible values create or delete.322 * Default create.323 * @param string $name The pagename of the wiki page.324 * @param string $pageContent The content of the wiki page to set.325 * @param array $data Name/value paired array of data for the wiki page.326 * @return mixed The result of the request or the integer id on a multicall. false on error.327 */328 public function getWikiUpdate($action = 'create', $name = '', $pageContent = '', $data = array())329 {330 if ($name === '') {331 throw new \InvalidArgumentException('Parameter $name empty.');332 }333 switch ($action) {334 case 'create':335 default:336 $method = 'wiki.putPage';337 $params = array(338 0 => $name,339 1 => $pageContent,340 2 => $data,341 );342 break;343 case 'delete':344 $method = 'wiki.deletePage';345 $params = $name;346 break;347 }348 $this->_addRequest($method, $params);349 return $this->_getReturnValue();350 }351 /**352 * Create, delete, or update a ticket.353 *354 * @param string $action What action to perform for a ticket.355 * Possible values create, update, or delete.356 * Default create.357 * @param string $id The id of the ticket.358 * @param array $data Name/value paired array of data for the ticket.359 * @return mixed The result of the request or the integer id on a multicall. false on error.360 */361 public function getTicketUpdate($action = 'create', $id = '', $data = array())362 {363 switch ($action) {364 case 'create':365 default:366 $method = 'ticket.create';367 $params = array(368 0 => ($data['summary'] !== null) ? $data['summary'] : '',369 1 => ($data['desc'] !== null) ? $data['desc'] : '',370 2 => ($data['attr'] !== null) ? $data['attr'] : array(),371 3 => ($data['notify'] !== null) ? $data['notify'] : false372 );373 break;374 case 'update':375 $method = 'ticket.update';376 $params = array(377 0 => $id,378 1 => ($data['comment'] !== null) ? $data['comment'] : '',379 2 => ($data['attr'] !== null) ? $data['attr'] : array(),380 3 => ($data['notify'] !== null) ? $data['notify'] : false381 );382 break;383 case 'delete':384 if ($id === '') {385 throw new \InvalidArgumentException('Parameter $id empty.');386 }387 $method = 'ticket.delete';388 $params = $id;389 break;390 }391 $this->_addRequest($method, $params);392 return $this->_getReturnValue();393 }394 /**395 * Search for tickets.396 *397 * @param string|array $query Query string to search.398 * @return mixed The result of the request or the integer id on a multicall. false on error.399 */400 public function getTicketSearch($query = '')401 {402 if (is_array($query) === true and false === empty($query)) {403 $ops = array('=', '~=', '^=', '$=', '!=', '!~=', '!^=', '!$=');404 $query_str = '';405 foreach ($query as $key => $value) {406 if (is_array($value) === true) {407 $value = implode('|', $value);408 $query[$key] = $value;409 }410 if (false === empty($value)) {411 $op = '=';412 foreach ($ops as $sign) {413 if (strrpos($sign, $key) === true) {414 $op = '';415 break;416 }417 }418 $query_str .= $key . $op . $value . '&';419 }420 }421 if (empty($query_str)) {422 return false;423 }424 $query = substr($query_str, 0, -1);425 unset($query_str);426 } elseif (empty($query)) {427 return false;428 }429 $this->_addRequest('ticket.query', $query);430 return $this->_getReturnValue();431 }432 /**433 * Get all ticket components, get a specific component,434 * create a component, edit an existing component, or delete a component.435 *436 * @param string $action What action to perform for ticket component.437 * Possible values get_all, get, delete, update, or438 * create. Default get_all.439 * @param string $name The name of the component.440 * @param array $attr Name/value paired array of data for the ticket441 * component.442 * @return mixed The result of the request or the integer id on a multicall.443 * false on error.444 */445 public function getTicketComponent($action = 'get_all', $name = '', $attr = array())446 {447 $params = '';448 switch ($action) {449 case 'get_all':450 default:451 $method = 'ticket.component.getAll';452 break;453 case 'get':454 if ($name === '') {455 throw new \InvalidArgumentException('Parameter $name empty.');456 }457 $method = 'ticket.component.get';458 $params = array(0 => $name);459 break;460 case 'delete':461 if ($name == false) {462 return false;463 }464 $method = 'ticket.component.delete';465 $params = array(0 => $name);466 break;467 case 'update':468 case 'create':469 if ($name === '') {470 throw new \InvalidArgumentException('Parameter $name empty.');471 }472 if (!is_array($attr)) {473 throw new \InvalidArgumentException('Parameter $attr empty.');474 }475 $method = 'ticket.component.' . $action;476 $params = array($name, $attr);477 break;478 }479 $this->_addRequest($method, $params);480 return $this->_getReturnValue();481 }482 /**483 * Get all ticket milestones, get a specific milestone,484 * create a milestone, edit an existing milestone, or delete a milestone.485 *486 * @param string $action What action to perform for ticket milestone.487 * Possible values get_all, get, delete, update, or create.488 * Default get_all.489 * @param string $name The name of the milestone.490 * @param array $attr Name/value paired array of data for the ticket milestone.491 * @return mixed The result of the request or the integer id on a multicall. false on error.492 */493 public function getTicketMilestone($action = 'get_all', $name = '', $attr = array())494 {495 $params = '';496 switch ($action) {497 case 'get_all':498 default:499 $method = 'ticket.milestone.getAll';500 break;501 case 'get':502 if ($name === '') {503 throw new \InvalidArgumentException('Parameter $name empty. Please specify a milestone.');504 }505 $method = 'ticket.milestone.get';506 $params = array(0 => $name);507 break;508 case 'delete':509 if ($name === '') {510 throw new \InvalidArgumentException('Parameter $name empty. Please specify a milestone.');511 }512 $method = 'ticket.milestone.delete';513 $params = array(0 => $name);514 break;515 case 'update':516 case 'create':517 if ($name == '' || !is_array($attr)) {518 return false;519 }520 $method = 'ticket.milestone.' . $action;521 $params = array($name, $attr);522 break;523 }524 $this->_addRequest($method, $params);525 return $this->_getReturnValue();526 }527 /**528 * Get all ticket prioritys, get a specific priority,529 * create a priority, edit an existing priority, or delete a priority.530 *531 * @param string $action What action to perform for ticket priority.532 * Possible values get_all, get, delete, update, or create.533 * Default get_all.534 * @param string $name The name of the priority.535 * @param string $attr Priority name.536 * @return mixed The result of the request or the integer id on a multicall. false on error.537 */538 public function getTicketPriority($action = 'get_all', $name = '', $attr = '')539 {540 $params = '';541 switch ($action) {542 case 'get_all':543 default:544 $method = 'ticket.priority.getAll';545 break;546 case 'get':547 if ($name === '') {548 throw new \InvalidArgumentException('Parameter $name empty. Please specify a priority.');549 }550 $method = 'ticket.priority.get';551 $params = array(0 => $name);552 break;553 case 'delete':554 if ($name === '') {555 throw new \InvalidArgumentException('Parameter $name empty. Please specify a priority.');556 }557 $method = 'ticket.priority.delete';558 $params = array(0 => $name);559 break;560 case 'update':561 case 'create':562 if ($name === '') {563 throw new \InvalidArgumentException('Parameter $name empty. Please specify a priority.');564 }565 if ($attr === '') {566 throw new \InvalidArgumentException('Parameter $attr empty. Please specify a priority.');567 }568 $method = 'ticket.priority.' . $action;569 $params = array($name, $attr);570 break;571 }572 $this->_addRequest($method, $params);573 return $this->_getReturnValue();574 }575 /**576 * Get all ticket resolutions, get a specific resolution,577 * create a resolution, edit an existing resolution, or delete a resolution.578 *579 * @param string $action What action to perform for ticket resolution.580 * Possible values get_all, get, delete, update, or create.581 * Default get_all.582 * @param string $name The name of the resolution.583 * @param string $attr Resolution name.584 * @return mixed The result of the request or the integer id on a multicall. false on error.585 */586 public function getTicketResolution($action = 'get_all', $name = '', $attr = '')587 {588 $params = '';589 switch ($action) {590 case 'get_all':591 default:592 $method = 'ticket.resolution.getAll';593 break;594 case 'get':595 if ($name === '') {596 throw new \InvalidArgumentException('Parameter $name empty. Please specify a resolution.');597 }598 $method = 'ticket.resolution.get';599 $params = array(0 => $name);600 break;601 case 'delete':602 if ($name === '') {603 throw new \InvalidArgumentException('Parameter $name empty. Please specify a resolution.');604 }605 $method = 'ticket.resolution.delete';606 $params = array(0 => $name);607 break;608 case 'update':609 case 'create':610 if ($name === '') {611 throw new \InvalidArgumentException('Parameter $name empty. Please specify a resolution.');612 }613 if ($attr === '') {614 throw new \InvalidArgumentException('Parameter $attr empty. Please specify attributes.');615 }616 $method = 'ticket.resolution.' . $action;617 $params = array($name, $attr);618 break;619 }620 $this->_addRequest($method, $params);621 return $this->_getReturnValue();622 }623 /**624 * Get all ticket severitys, get a specific severity,625 * create a severity, edit an existing severity, or delete a severity.626 *627 * @param string $action What action to perform for ticket severity.628 * Possible values get_all, get, delete, update, or create.629 * Default get_all.630 * @param string $name The name of the severity.631 * @param string $attr Severity name.632 * @return mixed The result of the request or the integer id on a multicall. false on error.633 */634 public function getTicketSeverity($action = 'get_all', $name = '', $attr = '')635 {636 $params = '';637 switch ($action) {638 case 'get_all':639 default:640 $method = 'ticket.severity.getAll';641 break;642 case 'get':643 if ($name === '') {644 throw new \InvalidArgumentException('Parameter $name empty. Please specify a severity.');645 }646 $method = 'ticket.severity.get';647 $params = array(0 => $name);648 break;649 case 'delete':650 if ($name === '') {651 throw new \InvalidArgumentException('Parameter $name empty. Please specify a severity.');652 }653 $method = 'ticket.severity.delete';654 $params = array(0 => $name);655 break;656 case 'update':657 case 'create':658 if ($name === '') {659 throw new \InvalidArgumentException('Parameter $name empty. Please specify a severity.');660 }661 if ($attr === '') {662 throw new \InvalidArgumentException('Parameter $attr empty. Please specify a severity.');663 }664 $method = 'ticket.severity.' . $action;665 $params = array($name, $attr);666 break;667 }668 $this->_addRequest($method, $params);669 return $this->_getReturnValue();670 }671 /**672 * Get all ticket types, get a specific type, create a type, edit an existing type, or delete a type673 *674 * @param string $action What action to perform for ticket type.675 * Possible values get_all, get, delete, update, or create.676 * Default get_all.677 * @param string $name The name of the type.678 * @param string $attr Type name.679 * @return mixed The result of the request or the integer id on a multicall. false on error.680 */681 public function getTicketType($action = 'get_all', $name = '', $attr = '')682 {683 $params = '';684 switch ($action) {685 case 'get_all':686 default:687 $method = 'ticket.type.getAll';688 break;689 case 'get':690 if ($name === '') {691 throw new \InvalidArgumentException('Parameter $name empty. Please specify a type.');692 }693 $method = 'ticket.type.get';694 $params = array(0 => $name);695 break;696 case 'delete':697 if ($name === '') {698 throw new \InvalidArgumentException('Parameter $name empty. Please specify a type.');699 }700 $method = 'ticket.type.delete';701 $params = array(0 => $name);702 break;703 case 'update':704 case 'create':705 if ($name === '') {706 throw new \InvalidArgumentException('Parameter $name empty. Please specify a type.');707 }708 if ($attr === '') {709 throw new \InvalidArgumentException('Parameter $attr empty. Please specify a type.');710 }711 $method = 'ticket.type.' . $action;712 $params = array($name, $attr);713 break;714 }715 $this->_addRequest($method, $params);716 return $this->_getReturnValue();717 }718 /**719 * Get all ticket versions, get a specific version,720 * create a version, edit an existing version, or delete a version.721 *722 * @param string $action What action to perform for ticket version.723 * Possible values get_all, get, delete, update, or create.724 * Default get_all.725 * @param string $name The name of the version.726 * @param array $attr Name/value paired array of data for the ticket version.727 * @return mixed The result of the request or the integer id on a multicall. false on error.728 */729 public function getTicketVersion($action = 'get_all', $name = '', $attr = array())730 {731 $params = array();732 switch ($action) {733 case 'get_all':734 default:735 $method = 'ticket.version.getAll';736 break;737 case 'get':738 if ($name === '') {739 throw new \InvalidArgumentException('Parameter $name empty. Please specify a version.');740 }741 $method = 'ticket.version.get';742 $params = array(0 => $name);743 break;744 case 'delete':745 if ($name === '') {746 return false;747 }748 $method = 'ticket.version.delete';749 $params = array(0 => $name);750 break;751 case 'update':752 case 'create':753 if ($name === '') {754 throw new \InvalidArgumentException('Parameter $name empty. Please specify a version.');755 }756 if (!is_array($attr)) {757 throw new \InvalidArgumentException('Parameter $attr empty. Please specify a version.');758 }759 $method = ('ticket.version.' . $action);760 break;761 }762 $this->_addRequest($method, $params);763 return $this->_getReturnValue();764 }765 /**766 * Get all status.767 *768 * @return mixed The result of the request or the integer id on a multicall. false on error.769 */770 public function getTicketStatus()771 {772 $this->_addRequest('ticket.status.getAll');773 $this->_getReturnValue();774 }775 /**776 * Perform a global search in TRAC.777 *778 * @param string $query Query string to search for,779 * @param array $filter Search filters to use.780 * @return mixed The result of the request or the integer id on a multicall. false on error.781 */782 public function getSearch($query = '', $filter = array())783 {784 $params = array();785 if ($query != '') {786 $params[0] = $query;787 } else {788 return false;789 }790 if (is_array($filter) === true and false === empty($filter)) {791 $params[1] = $filter;792 }793 $this->_addRequest('search.performSearch', $params);794 return $this->_getReturnValue();795 }796 /**797 * Convert a string of raw wiki text to HTML.798 *799 * @param string $text A string of raw wiki text.800 * @return mixed The result of the request or the integer id on a multi_call. false on error.801 */802 public function getWikiTextToHTML($text = '')803 {804 if ($text === '') {805 throw new \InvalidArgumentException('Parameter $text empty. Please specify a text.');806 }807 $this->_addRequest('wiki.wikiToHTML', $text);808 return $this->_getReturnValue();809 }810 /**811 * Get all search filters.812 * Its a list of search filters with each element in the form (name, description).813 *814 * @return mixed The result of the request or the integer id on a multicall. false on error.815 */816 public function getSearchFilters()817 {818 $this->_addRequest('search.getSearchFilters');819 return $this->_getReturnValue();820 }821 /**822 * Get the API version from Trac.823 *824 * @return mixed The result of the request or the integer id on a multicall. false on error.825 */826 public function getApiVersion()827 {828 $this->_addRequest('system.getAPIVersion');829 return $this->_getReturnValue();830 }831 /**832 * Executes a RPC request to Trac. Accepts method and arguments.833 *834 * @param string $method A RPC method to execute.835 * @param array $args Arguments to pass with the RPC call.836 * @return bool true on a successful request. false on error.837 */838 public function doRequest($method = '', $args = array())839 {840 if ($method != '') {841 $this->_addRequest($method, $args);842 }843 if (empty($this->request)) {844 return false;845 }846 if ($this->multiCall === true) {847 $this->_addRequest('system.multicall');848 }849 // create JSON request850 if (is_array($this->request) === true & $this->content_type === 'json') {851 $this->request = json_encode(array_pop($this->request));852 // Replace empty arrays with structs(objects, in PHP parlance)853 $this->request = str_replace('[]', '{}', $this->request);854 }855 // create XML request856 if ($this->content_type === 'xml') {857 if (!extension_loaded('xmlrpc')) {858 throw new \RuntimeException('PHP Extension "xmlrpc" is required. Please activate in php.ini.');859 }860 $this->request = \xmlrpc_encode_request($this->request[0]['method'], $this->request[0]['params']);861 }862 if ($this->_doCurlRequest() === true) {863 if ($this->content_type === 'xml') {864 //var_dump($this->response);865 $this->response = \xmlrpc_decode($this->response);866 //var_dump($this->response);867 } elseif ($this->content_type === 'json' && $this->json_decode === true) {868 $this->response = json_decode($this->response);869 $this->parseResult();870 }871 return true;872 }873 return false;874 }875 /**876 * Adds a new request to the request stack877 *878 * @param string $method The method name to call.879 * @param array $args Arguments to pass with the call.880 * @param string $id The id to set to the call.881 * @return bool Always true.882 */883 protected function _addRequest($method = '', $args = array(), $id = '')884 {885 if ($method === '') {886 return false;887 }888 if (false === is_array($args) and false === empty($args)) {889 $args = array($args);890 } elseif (false === is_array($args)) {891 $args = array();892 }893 if (false === is_array($this->request)) {894 $this->request = array();895 }896 if (empty($id)) {897 $id = $this->_incrementRequestId();898 }899 if ($method == 'system.multicall') {900 $request = array(901 'method' => $method,902 'params' => $this->request,903 'id' => $id904 );905 $this->request = array(0 => $request);906 } else {907 $this->request[] = array(908 'method' => $method,909 'params' => $args,910 'id' => $id911 );912 }913 return true;914 }915 /**916 * Increment the current payload id by 1 and returns it.917 *918 * @return int The incremented request id.919 */920 protected function _incrementRequestId()921 {922 $this->request_id++;923 return $this->request_id;924 }925 /**926 *927 * The JSON-RPC protocol gets used when sending928 * a 'Content-Type': 'application/json' header request to:929 *930 * Anonymous access931 * http://trac.example.com/rpc932 * http://trac.example.com/jsonrpc933 * Authenticated access934 * http://trac.example.com/login/rpc935 * http://trac.example.com/login/jsonrpc936 *937 * The XML-RPC protocol gets used when sending938 * a 'Content-Type': 'application/xml' or 'text/xml' header request to:939 *940 * Anonymous access941 * http://trac.example.com/rpc942 * http://trac.example.com/xmlrpc943 * Authenticated access944 * http://trac.example.com/login/rpc945 * http://trac.example.com/login/xmlrpc946 *947 * if URL ends with "/rpc" we can not differentiate between XML and JSON for the content-type.948 * you need to define "content-type" in $params or via setter. it defaults to "json".949 */950 protected function _setContentTypeFromURL($url)951 {952 if (strpos($url, 'jsonrpc') !== false) {953 $this->content_type = 'json';954 } elseif (strpos($url, 'xmlrpc') !== false) {955 $this->content_type = 'xml';956 }957 }958 /**959 * Make the request using CURL.960 *961 * @return bool true is a successful CURL request. false CURL isn't installed or the url or payload is empty.962 * @throws \Exception If making an authenticated request without authentication963 */964 protected function _doCurlRequest()965 {966 if (empty($this->tracURL)) {967 throw new \InvalidArgumentException('Provide the URL to the Trac Env you want to query.');968 }969 if (empty($this->request)) {970 throw new \InvalidArgumentException('No valid Request. Check the request parameters.');971 }972 if (empty($this->content_type)) {973 throw new \InvalidArgumentException('Please set the content type (xml or json) for this request.');974 }975 $ch = curl_init();976 curl_setopt($ch, CURLOPT_URL, $this->tracURL);977 /**978 * Set correct HttpHeader Content Type979 * depending on the requested content type via tracURL.980 *981 */982 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/' . $this->content_type));983 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);984 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);985 // workaround for CURLOPT_FOLLOWLOCATION986 // cannot be activated when safe_mode is enabled or an open_basedir is set987 if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {988 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);989 } else {990 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);991 // alternative following handling via header 301?992 }993 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);994 curl_setopt($ch, CURLOPT_HEADER, false);995 curl_setopt($ch, CURLOPT_TIMEOUT, 30);996 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);997 curl_setopt($ch, CURLOPT_POST, true);998 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);999 /**1000 * Determine if this is an authenticated access, then set user credentials accordingly.1001 */1002 if (strpos($this->tracURL, 'login') !== false) {1003 if (empty($this->username) || empty($this->password)) {1004 throw new \Exception(1005 'You are trying an authenticated access without providing username and password.'1006 );1007 } else {1008 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // CURLAUTH_BASIC | CURLAUTH_DIGEST1009 curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);1010 }1011 }1012 $this->response = trim(curl_exec($ch));1013 if (curl_errno($ch) > 0) {1014 $this->error = curl_error($ch);1015 }1016 curl_close($ch);1017 return true;1018 }1019 /**1020 * Loop through the results and do any parsing needed.1021 *1022 * JSON RPC doesn't have datatypes so special objects are made for datetime1023 * and base64 value. This method finds those objects and converts them into1024 * proper php values. For datetime types, the value is converted into a UNIX1025 * timestamp. Base64 decodes the value.1026 *1027 * @param array|object $response1028 * @return bool true on a non-empty result and false if it is empty.1029 */1030 public function parseResult($response = array())1031 {1032 if (empty($response)) {1033 $response = $this->getResponse();1034 $this->response = array();1035 }1036 if (false === is_object($response) and false === is_array($response)) {1037 return false;1038 }1039 if (($response->result !== null) and is_array($response->result) && $this->content_type === 'xml') {1040 return; // single call on xml for now1041 }1042 if (($response->result !== null) and is_array($response->result)) {1043 foreach ($response->result as $key => $resp) {1044 if (isset($resp->result) === true) {1045 $this->parseResult($resp);1046 continue;1047 }1048 if (is_array($resp) === true || is_object($resp) === true) {1049 $values = array();1050 foreach ($resp as $r_key => $value) {1051 if ($r_key === '__jsonclass__') {1052 switch ($value[0]) {1053 case 'datetime':1054 $value = strtotime($value[1]);1055 break;1056 case 'binary':1057 $value = base64_decode($value[1]);1058 break;1059 }1060 $values = $value;1061 } else {1062 $values[$r_key] = $value;1063 }1064 }1065 $response->result[$key] = $values;1066 } else {1067 $response->result[$key] = $resp;1068 }1069 }1070 }1071 $id = 0;1072 if (($response->id !== null) and ($response->id != null)) {1073 $id = $response->id;1074 }1075 $this->response[$id] = $response->result;1076 $this->error[$id] = false;1077 if (($response->error !== null) and is_object($response->error) === true) {1078 foreach ($response->error as $key => $value) {1079 $this->error[$id][$key] = $value;1080 }1081 }1082 return true;1083 }1084 /**1085 * Set the property user.1086 *1087 * @param string $username1088 * @return object TracRPC1089 */1090 public function setUser($username = '')1091 {1092 $this->username = $username;1093 return $this;1094 }1095 /**1096 * Set the property password.1097 *1098 * @param string $password1099 * @return object TracRPC1100 */1101 public function setPassword($password = '')1102 {1103 $this->password = $password;1104 return $this;1105 }1106 /**1107 * Set the property tracURL1108 *1109 * @param string $tracURL1110 * @return object TracRPC1111 */1112 public function setTracURL($tracURL = '')1113 {1114 $this->_setContentTypeFromURL($tracURL);1115 $this->tracURL = $tracURL;1116 return $this;1117 }1118 /**1119 * Set the property multiCall.1120 *1121 * @param bool $multi1122 * @return bool1123 */1124 public function setMultiCall($multi = false)1125 {1126 $this->multiCall = ($multi === true) ? true : false;1127 return $this->multiCall;1128 }1129 /**1130 * Set the content-type.1131 * Only needed for URLs using "/rpc".1132 *1133 * @param string $type The content-type. Defaults to json.1134 * @return object TracRPC1135 */1136 public function setContentType($type = 'json')1137 {1138 $this->content_type = $type;1139 return $this;1140 }1141 /**1142 * Set the property json_decode.1143 *1144 * @param bool $json_decode1145 * @return object TracRPC1146 */1147 public function setJsonDecode($json_decode = false)1148 {1149 $this->json_decode = ($json_decode === true) ? true : false;1150 return $this;1151 }1152 /**1153 * Get the response from the request.1154 *1155 * @param mixed|int|array The id of the call (or an array of ids).1156 * @return object stdClass1157 */1158 public function getResponse($id = false)1159 {1160 // response is an object1161 if (is_object($this->response)) {1162 return $this->response;1163 }1164 // response is an array1165 if (is_array($this->response)) {1166 if ($this->content_type === 'xml') { // @todo this returns a single response for now1167 return $this->response;1168 }1169 // response is an array - but no id requested1170 if ($id === false) {1171 return current($this->response);1172 }1173 // response is an array - with id requested1174 if (isset($id) && is_int($id)) {1175 return $this->response[$id];1176 }1177 // response is an array - with an array of id's requested1178 if (isset($id) && is_array($id)) {1179 $ret = array();1180 foreach ($id as $key) {1181 if (false === isset($this->response[$key])) {1182 continue;1183 }1184 $ret[$key] = $this->response[$key];1185 }1186 return $ret;1187 }1188 }1189 // raw json string, not decoded1190 if (is_string($this->response)) {1191 return $this->response;1192 }1193 return false;1194 }1195 /**1196 * Get any error message set for the request.1197 *1198 * @param bool|array $id The id of the call made. Used for multiCalls.1199 * @return string The error message1200 */1201 public function getErrorMessage($id = false)1202 {1203 if ($id) {1204 if (is_array($id) === true) {1205 $ret = array();1206 foreach ($id as $eid) {1207 if (isset($this->error[$eid]) === false) {1208 continue;1209 }1210 $ret[$eid] = $this->error[$eid];1211 }1212 return $ret;1213 }1214 if ($this->error[$id] !== null) {1215 return $this->error[$id];1216 }1217 }1218 return $this->error;1219 }1220 /**1221 * Get the appropriate return value.1222 *1223 * Returns an integer (the request id) when multicall is enabled, an object1224 * representing the last response if the request was successful, and false on1225 * failure.1226 *1227 * @return boolean|integer|object1228 */1229 protected function _getReturnValue()1230 {1231 if ($this->multiCall === true) {1232 return $this->request_id;1233 }1234 if ($this->doRequest() === true) {1235 return $this->getResponse();1236 }1237 return false;1238 }1239}...
Expectation.php
Source:Expectation.php
...155 public function verifyCall(array $args)156 {157 $this->validateOrder();158 $this->_actualCount++;159 $return = $this->_getReturnValue($args);160 if ($return instanceof \Exception && $this->_throw === true) {161 throw $return;162 }163 return $return; 164 }165 166 /**167 * Fetch the return value for the matching args168 *169 * @param array $args170 * @return mixed171 */172 protected function _getReturnValue(array $args)173 {174 if (count($this->_closureQueue) > 1) {175 return call_user_func_array(array_shift($this->_closureQueue), $args);176 } elseif (count($this->_closureQueue) > 0) {177 return call_user_func_array(current($this->_closureQueue), $args);178 } elseif (count($this->_returnQueue) > 1) {179 return array_shift($this->_returnQueue);180 } elseif (count($this->_returnQueue) > 0) {181 return current($this->_returnQueue);182 }183 }184 /**185 * Checks if this expectation is eligible for additional calls186 *...
_getReturnValue
Using AI Code Generation
1$are = new Are();2echo $are->_getReturnValue();3$are = new Are();4echo $are->_getReturnValue();5$are = new Are();6echo $are->_getReturnValue();7$are = new Are();8echo $are->_getReturnValue();9$are = new Are();10echo $are->_getReturnValue();11$are = new Are();12echo $are->_getReturnValue();13$are = new Are();14echo $are->_getReturnValue();15$are = new Are();16echo $are->_getReturnValue();17$are = new Are();18echo $are->_getReturnValue();19$are = new Are();20echo $are->_getReturnValue();21$are = new Are();22$are->_readFile();23$are->_writeFile();24$are = new Are();25$are->_readFile();26$are->_writeFile();27$are = new Are();28$are->_readFile();29$are->_writeFile();30$are = new Are();31$are->_readFile();32$are->_writeFile();33$are = new Are();34$are->_readFile();35$are->_writeFile();
_getReturnValue
Using AI Code Generation
1$are = new ARE();2$are->_getReturnValue();3$are = new ARE();4$are->_getReturnValue();5$are = new ARE();6$are->_getReturnValue();7$are = new ARE();8$are->_getReturnValue();9$are = new ARE();10$are->_getReturnValue();11$are = new ARE();12$are->_getReturnValue();13$are = new ARE();14$are->_getReturnValue();15$are = new ARE();16$are->_getReturnValue();17$are = new ARE();18$are->_getReturnValue();19$are = new ARE();20$are->_getReturnValue();21$are = new ARE();22$are->_getReturnValue();23$are = new ARE();24$are->_getReturnValue();
_getReturnValue
Using AI Code Generation
1$obj = new are();2$obj->setReturnValue(10);3echo $obj->_getReturnValue();4$obj = new are();5$obj->setReturnValue(20);6echo $obj->_getReturnValue();
_getReturnValue
Using AI Code Generation
1$are = new are();2$are->setReturnValue(20, 20);3echo $are->getReturnValue();4$are = new are();5$are->setReturnValue(20, 30);6echo $are->getReturnValue();7$are = new are();8$are->setReturnValue(20, 40);9echo $are->getReturnValue();10$are = new are();11$are->setReturnValue(20, 50);12echo $are->getReturnValue();13$are = new are();14$are->setReturnValue(20, 60);15echo $are->getReturnValue();16$are = new are();17$are->setReturnValue(20, 70);18echo $are->getReturnValue();19$are = new are();20$are->setReturnValue(20, 80);21echo $are->getReturnValue();22$are = new are();23$are->setReturnValue(20, 90);24echo $are->getReturnValue();25$are = new are();26$are->setReturnValue(20, 100);27echo $are->getReturnValue();28$are = new are();29$are->setReturnValue(20, 110);30echo $are->getReturnValue();31$are = new are();32$are->setReturnValue(20, 120);33echo $are->getReturnValue();34$are = new are();35$are->setReturnValue(20, 130);36echo $are->getReturnValue();
_getReturnValue
Using AI Code Generation
1require_once("are.php");2$are = new are();3$are->setReturnValue("Hello");4echo $are->_getReturnValue();5require_once("are.php");6$are = new are();7$are->setReturnValue("Hello");8echo $are->_getReturnValue();9require_once("are.php");10$are = new are();11$are->setReturnValue("Hello");12echo $are->_getReturnValue();13require_once("are.php");14$are = new are();15$are->setReturnValue("Hello");16echo $are->_getReturnValue();17require_once("are.php");18$are = new are();19$are->setReturnValue("Hello");20echo $are->_getReturnValue();21require_once("are.php");22$are = new are();23$are->setReturnValue("Hello");24echo $are->_getReturnValue();25require_once("are.php");26$are = new are();27$are->setReturnValue("Hello");28echo $are->_getReturnValue();29require_once("are.php");30$are = new are();31$are->setReturnValue("Hello");32echo $are->_getReturnValue();33require_once("are.php");34$are = new are();35$are->setReturnValue("Hello");36echo $are->_getReturnValue();37require_once("are.php");38$are = new are();39$are->setReturnValue("Hello");40echo $are->_getReturnValue();
_getReturnValue
Using AI Code Generation
1include_once('are.php');2$obj = new are();3$obj->setRadius(5);4echo $obj->_getReturnValue();5include_once('are.php');6$obj = new are();7$obj->setRadius(5);8echo $obj->getReturnValue();9include_once('are.php');10$obj = new are();11$obj->setRadius(5);12echo $obj->getReturnValue();13{14 private $radius;15 private $returnValue;16 public function setRadius($radius)17 {18 $this->radius = $radius;19 }20 public function getReturnValue()21 {22 $this->returnValue = $this->radius * $this->radius * 3.14;23 return $this->returnValue;24 }25 public function _getReturnValue()26 {27 $this->returnValue = $this->radius * $this->radius * 3.14;28 return $this->returnValue;29 }30}31Now, if we rename the method _getReturnValue() to getReturnValue(), we will get the following result:32Fatal error: Cannot redeclare are::getReturnValue() in /home/are.php on line 43
_getReturnValue
Using AI Code Generation
1require_once 'class.are.php';2$are = new are();3$are->_getReturnValue();4{5 var $return_value = 0;6 function _getReturnValue()7 {8 $this->return_value = $this->return_value + 1;9 echo $this->return_value;10 }11}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with _getReturnValue on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!