Best Mockery code snippet using HasKey
APIBaseClass.php
Source:APIBaseClass.php
...241 ->hasKey('name')242 ->hasKey('entities_id')243 ->hasKey('links')244 ->hasKey('_logs') // with_logs == true245 ->notHasKey('password');246 $this->boolean(is_numeric($item['entities_id']))->isFalse(); // for expand_dropdowns247 }248 }249 /**250 * @tags api251 * @covers API::listSearchOptions252 */253 public function testListSearchOptions() {254 // test retrieve all users255 $data = $this->query('listSearchOptions',256 ['itemtype' => 'Computer',257 'headers' => ['Session-Token' => $this->session_token]]);258 $this->variable($data)->isNotFalse();259 $this->array($data)260 ->size->isGreaterThanOrEqualTo(128);261 $this->array($data[1])262 ->string['name']->isIdenticalTo('Name')263 ->string['table']->isIdenticalTo('glpi_computers')264 ->string['field']->isIdenticalTo('name')265 ->array['available_searchtypes'];266 $this->array($data[1]['available_searchtypes'])267 ->isIdenticalTo(['contains', 'notcontains', 'equals', 'notequals']);268 }269 /**270 * @tags api271 * @covers API::searchItems272 */273 public function testListSearch() {274 // test retrieve all users275 $data = $this->query('search',276 ['itemtype' => 'User',277 'headers' => ['Session-Token' => $this->session_token],278 'query' => [279 'sort' => 19,280 'order' => 'DESC',281 'range' => '0-10',282 'forcedisplay' => '81',283 'rawdata' => true]]);284 $this->array($data)285 ->hasKey('headers')286 ->hasKey('totalcount')287 ->hasKey('count')288 ->hasKey('sort')289 ->hasKey('order')290 ->hasKey('rawdata');291 $headers = $data['headers'];292 $this->array($data['headers'])293 ->hasKey('Accept-Range');294 $this->string($headers['Accept-Range'][0])295 ->startWith('User');296 $this->array($data['rawdata'])297 ->hasSize(11);298 $first_user = array_shift($data['data']);299 $second_user = array_shift($data['data']);300 $this->array($first_user)->hasKey(81);301 $this->array($second_user)->hasKey(81);302 $first_user_date_mod = strtotime($first_user[19]);303 $second_user_date_mod = strtotime($second_user[19]);304 $this->integer($second_user_date_mod)->isLessThanOrEqualTo($first_user_date_mod);305 $this->checkContentRange($data, $headers);306 }307 /**308 * @tags api309 * @covers API::searchItems310 */311 public function testListSearchPartial() {312 // test retrieve partial users313 $data = $this->query('search',314 ['itemtype' => 'User',315 'headers' => ['Session-Token' => $this->session_token],316 'query' => [317 'sort' => 19,318 'order' => 'DESC',319 'range' => '0-2',320 'forcedisplay' => '81',321 'rawdata' => true]],322 206);323 $this->variable($data)->isNotFalse();324 $this->array($data)325 ->hasKey('totalcount')326 ->hasKey('count')327 ->hasKey('sort')328 ->hasKey('order')329 ->hasKey('rawdata');330 $this->array($data['rawdata'])331 ->hasSize(11);332 $first_user = array_shift($data['data']);333 $second_user = array_shift($data['data']);334 $this->array($first_user)->hasKey(81);335 $this->array($second_user)->hasKey(81);336 $first_user_date_mod = strtotime($first_user[19]);337 $second_user_date_mod = strtotime($second_user[19]);338 $this->integer($second_user_date_mod)->isLessThanOrEqualTo($first_user_date_mod);339 $this->checkContentRange($data, $data['headers']);340 }341 /**342 * @tags api343 * @covers API::searchItems344 */345 public function testListSearchEmpty() {346 // test retrieve partial users347 $data = $this->query('search',348 ['itemtype' => 'User',349 'headers' => ['Session-Token' => $this->session_token],350 'query' => [351 'sort' => 19,352 'order' => 'DESC',353 'range' => '0-100',354 'forcedisplay' => '81',355 'rawdata' => true,356 'criteria' => [357 [358 'field' => 1,359 'searchtype' => 'contains',360 'value' => 'nonexistent',361 ]362 ]]]);363 $this->variable($data)->isNotFalse();364 $this->array($data)365 ->hasKey('headers')366 ->hasKey('totalcount')367 ->hasKey('count')368 ->hasKey('sort')369 ->hasKey('order')370 ->hasKey('rawdata');371 $this->array($data['headers'])372 ->hasKey('Accept-Range');373 $this->string($data['headers']['Accept-Range'][0])374 ->startWith('User');375 $this->array($data['rawdata'])376 ->hasSize(11);377 $this->checkEmptyContentRange($data, $data['headers']);378 }379 /**380 * @tags api381 * @covers API::searchItems382 */383 public function testSearchWithBadCriteria() {384 // test retrieve all users385 // multidimensional array of vars in query string not supported ?386 // test a non existing search option ID387 $data = $this->query('search',388 ['itemtype' => 'User',389 'headers' => ['Session-Token' => $this->session_token],390 'query' => [391 'reset' => 'reset',392 'criteria' => [[393 'field' => '134343',394 'searchtype' => 'contains',395 'value' => 'dsadasd',396 ]]397 ]],398 400, // 400 code expected (error, bad request)399 'ERROR');400 // test a non numeric search option ID401 $data = $this->query('search',402 ['itemtype' => 'User',403 'headers' => ['Session-Token' => $this->session_token],404 'query' => [405 'reset' => 'reset',406 'criteria' => [[407 'field' => '\134343',408 'searchtype' => 'contains',409 'value' => 'dsadasd',410 ]]411 ]],412 400, // 400 code expected (error, bad request)413 'ERROR');414 // test an incomplete criteria415 $data = $this->query('search',416 ['itemtype' => 'User',417 'headers' => ['Session-Token' => $this->session_token],418 'query' => [419 'reset' => 'reset',420 'criteria' => [[421 'field' => '134343',422 'searchtype' => 'contains',423 ]]424 ]],425 400, // 400 code expected (error, bad request)426 'ERROR');427 }428 /**429 * @tags api430 */431 protected function badEndpoint($expected_code = null, $expected_symbol = null) {432 $data = $this->query('badEndpoint',433 ['headers' => [434 'Session-Token' => $this->session_token]],435 $expected_code,436 $expected_symbol);437 }438 /**439 * Create a computer440 *441 * @return Computer442 */443 protected function createComputer() {444 $data = $this->query('createItems',445 ['verb' => 'POST',446 'itemtype' => 'Computer',447 'headers' => ['Session-Token' => $this->session_token],448 'json' => ['input' => ['name' => "My single computer "]]],449 201);450 $this->variable($data)451 ->isNotFalse();452 $this->array($data)453 ->hasKey('id')454 ->hasKey('message');455 $computers_id = $data['id'];456 $this->boolean(is_numeric($computers_id))->isTrue();457 $this->integer((int)$computers_id)->isGreaterThanOrEqualTo(0);458 $computer = new Computer;459 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();460 return $computer;461 }462 /**463 * Create a network port464 *465 * @param integer $computers_id Computer ID466 *467 * @return void468 */469 protected function createNetworkPort($computers_id) {470 $data = $this->query('createItems',471 ['verb' => 'POST',472 'itemtype' => 'NetworkPort',473 'headers' => ['Session-Token' => $this->session_token],474 'json' => [475 'input' => [476 'instantiation_type' => "NetworkPortEthernet",477 'name' => "test port",478 'logical_number' => 1,479 'items_id' => $computers_id,480 'itemtype' => "Computer",481 'NetworkName_name' => "testname",482 'NetworkName_fqdns_id' => 0,483 // add an aditionnal key to the next array484 // to avoid xmlrpc losing -1 key.485 // see https://bugs.php.net/bug.php?id=37746486 'NetworkName__ipaddresses' => ['-1' => "1.2.3.4",487 '_xmlrpc_fckng_fix' => ''],488 '_create_children' => true]]],489 201);490 $this->variable($data)->isNotFalse();491 $this->array($data)492 ->hasKey('id')493 ->hasKey('message');494 }495 /**496 * Create a note497 *498 * @param integer $computers_id Computer ID499 *500 * @return void501 */502 protected function createNote($computers_id) {503 $data = $this->query('createItems',504 ['verb' => 'POST',505 'itemtype' => 'Notepad',506 'headers' => ['Session-Token' => $this->session_token],507 'json' => [508 'input' => [509 'itemtype' => 'Computer',510 'items_id' => $computers_id,511 'content' => 'note about a computer']]],512 201);513 $this->variable($data)->isNotFalse();514 $this->array($data)515 ->hasKey('id')516 ->hasKey('message');517 }518 /**519 * @tags api520 * @covers API::CreateItems521 */522 public function testCreateItem() {523 $computer = $this->createComputer();524 $computers_id = $computer->getID();525 // create a network port for the previous computer526 $this->createNetworkPort($computers_id);527 // try to create a new note528 $this->createNote($computers_id);529 }530 /**531 * @tags api532 * @covers API::CreateItems533 */534 public function testCreateItems() {535 $data = $this->query('createItems',536 ['verb' => 'POST',537 'itemtype' => 'Computer',538 'headers' => ['Session-Token' => $this->session_token],539 'json' => [540 'input' => [[541 'name' => "My computer 2"542 ],[543 'name' => "My computer 3"544 ],[545 'name' => "My computer 4"]]]],546 201);547 $this->variable($data)->isNotFalse();548 $first_computer = $data[0];549 $second_computer = $data[1];550 $this->array($first_computer)551 ->hasKey('id')552 ->hasKey('message');553 $this->array($second_computer)554 ->hasKey('id')555 ->hasKey('message');556 $this->boolean(is_numeric($first_computer['id']))->isTrue();557 $this->boolean(is_numeric($second_computer['id']))->isTrue();558 $this->integer((int)$first_computer['id'])->isGreaterThanOrEqualTo(0);559 $this->integer((int)$second_computer['id'])->isGreaterThanOrEqualTo(0);560 $computer = new Computer;561 $this->boolean((bool)$computer->getFromDB($first_computer['id']))->isTrue();562 $this->boolean((bool)$computer->getFromDB($second_computer['id']))->isTrue();563 unset($data['headers']);564 return $data;565 }566 /**567 * @tags apit568 * @covers API::getItem569 */570 public function testGetItem() {571 $computer = $this->createComputer();572 $computers_id = $computer->getID();573 // create a network port for the previous computer574 $this->createNetworkPort($computers_id);575 // Get the User TU_USER576 $uid = getItemByTypeName('User', TU_USER, true);577 $data = $this->query('getItem',578 ['itemtype' => 'User',579 'id' => $uid,580 'headers' => ['Session-Token' => $this->session_token],581 'query' => [582 'expand_dropdowns' => true,583 'with_logs' => true]]);584 $this->variable($data)->isNotFalse();585 $this->array($data)586 ->hasKey('id')587 ->hasKey('name')588 ->hasKey('entities_id')589 ->hasKey('links')590 ->hasKey('_logs') // with_logs == true591 ->notHasKey('password');592 $this->boolean(is_numeric($data['entities_id']))->isFalse(); // for expand_dropdowns593 // Get user's entity594 $eid = getItemByTypeName('Entity', '_test_root_entity', true);595 $data = $this->query('getItem',596 ['itemtype' => 'Entity',597 'id' => $eid,598 'headers' => ['Session-Token' => $this->session_token],599 'query' => ['get_hateoas' => false]]);600 $this->variable($data)->isNotFalse();601 $this->array($data)602 ->hasKey('id')603 ->hasKey('name')604 ->hasKey('completename')605 ->notHasKey('links'); // get_hateoas == false606 // Get the previously created 'computer 1'607 $data = $this->query('getItem',608 ['itemtype' => 'Computer',609 'id' => $computers_id,610 'headers' => ['Session-Token' => $this->session_token],611 'query' => ['with_networkports' => true]]);612 $this->variable($data)->isNotFalse();613 $this->array($data)614 ->hasKey('id')615 ->hasKey('name')616 ->hasKey('_networkports');617 $this->array($data['_networkports'])618 ->hasKey('NetworkPortEthernet');619 $this->array($data['_networkports']['NetworkPortEthernet'][0])->hasKey('NetworkName');620 $networkname = $data['_networkports']['NetworkPortEthernet'][0]['NetworkName'];621 $this->array($networkname)622 ->hasKey('IPAddress')623 ->hasKey('FQDN')624 ->hasKey('id')625 ->hasKey('name');626 $this->array($networkname['IPAddress'][0])627 ->hasKey('name')628 ->hasKey('IPNetwork');629 $this->string($networkname['IPAddress'][0]['name'])->isIdenticalTo('1.2.3.4');630 }631 /**632 * @tags api633 * @covers API::getItem634 */635 public function testGetItemWithNotes() {636 $computer = $this->createComputer();637 $computers_id = $computer->getID();638 // try to create a new note639 $this->createNote($computers_id);640 // Get the previously created 'computer 1'641 $data = $this->query('getItem',642 ['itemtype' => 'Computer',643 'id' => $computers_id,644 'headers' => ['Session-Token' => $this->session_token],645 'query' => ['with_notes' => true]]);646 $this->variable($data)->isNotFalse();647 $this->array($data)648 ->hasKey('id')649 ->hasKey('name')650 ->hasKey('_notes');651 $this->array($data['_notes'][0])652 ->hasKey('id')653 ->hasKey('itemtype')654 ->hasKey('items_id')655 ->hasKey('users_id')656 ->hasKey('content');657 }658 /**659 * @tags api660 * @covers API::getItem661 */662 public function testGetItems() {663 // test retrieve all users664 $data = $this->query('getItems',665 ['itemtype' => 'User',666 'headers' => ['Session-Token' => $this->session_token],667 'query' => [668 'expand_dropdowns' => true]]);669 $this->variable($data)->isNotFalse();670 $this->array($data)671 ->hasKey('headers')672 ->hasKey(0)673 ->size->isGreaterThanOrEqualTo(4);674 unset($data['headers']);675 $this->array($data[0])676 ->hasKey('id')677 ->hasKey('name')678 ->hasKey('is_active')679 ->hasKey('entities_id')680 ->notHasKey('password');681 $this->boolean(is_numeric($data[0]['entities_id']))->isFalse(); // for expand_dropdowns682 // test retrieve partial users683 $data = $this->query('getItems',684 ['itemtype' => 'User',685 'headers' => ['Session-Token' => $this->session_token],686 'query' => [687 'range' => '0-1',688 'expand_dropdowns' => true]],689 206);690 $this->variable($data)->isNotFalse();691 $this->array($data)692 ->hasKey('headers')693 ->hasSize(3);694 unset($data['headers']);695 $this->array($data[0])696 ->hasKey('id')697 ->hasKey('name')698 ->hasKey('is_active')699 ->hasKey('entities_id')700 ->notHasKey('password');701 $this->boolean(is_numeric($data[0]['entities_id']))->isFalse(); // for expand_dropdowns702 // test retrieve 1 user with a text filter703 $data = $this->query('getItems',704 ['itemtype' => 'User',705 'headers' => ['Session-Token' => $this->session_token],706 'query' => ['searchText' => ['name' => 'gl']]]);707 $this->variable($data)->isNotFalse();708 $this->array($data)709 ->hasKey('headers')710 ->hasSize(2);711 unset($data['headers']);712 $this->array($data[0])713 ->hasKey('id')714 ->hasKey('name');715 $this->string($data[0]['name'])->isIdenticalTo('glpi');716 // Test only_id param717 $data = $this->query('getItems',718 ['itemtype' => 'User',719 'headers' => ['Session-Token' => $this->session_token],720 'query' => ['only_id' => true]]);721 $this->variable($data)->isNotFalse();722 $this->array($data)723 ->hasKey('headers')724 ->size->isGreaterThanOrEqualTo(5);725 $this->array($data[0])726 ->hasKey('id')727 ->notHasKey('name')728 ->notHasKey('is_active')729 ->notHasKey('password');730 // test retrieve all config731 $data = $this->query('getItems',732 ['itemtype' => 'Config',733 'headers' => ['Session-Token' => $this->session_token],734 'query' => ['expand_dropdowns' => true]]);735 $this->variable($data)->isNotFalse();736 $this->array($data)->hasKey('headers');737 unset($data['headers']);738 foreach ($data as $config_row) {739 $this->string($config_row['name'])740 ->isNotEqualTo('smtp_passwd')741 ->isNotEqualTo('proxy_passwd');742 }743 }744 /**745 * try to retrieve invalid range of users746 * We expect a http code 400747 *748 * @tags api749 * @covers API::getItem750 */751 public function testgetItemsInvalidRange() {752 $data = $this->query('getItems',753 ['itemtype' => 'User',754 'headers' => ['Session-Token' => $this->session_token],755 'query' => [756 'range' => '100-105',757 'expand_dropdowns' => true]],758 400,759 'ERROR_RANGE_EXCEED_TOTAL');760 }761 /**762 * This function test https://github.com/glpi-project/glpi/issues/1103763 * A post-only user could retrieve tickets of others users when requesting itemtype764 * without first letter in uppercase765 *766 * @tags api767 * @covers API::getItem768 */769 public function testgetItemsForPostonly() {770 // init session for postonly771 $data = $this->query('initSession',772 ['query' => [773 'login' => 'post-only',774 'password' => 'postonly']]);775 // create a ticket for another user (glpi - super-admin)776 $ticket = new \Ticket;777 $tickets_id = $ticket->add(['name' => 'test post-only',778 'content' => 'test post-only',779 '_users_id_requester' => 2]);780 $this->integer((int)$tickets_id)->isGreaterThan(0);781 // try to access this ticket with post-only782 $this->query('getItem',783 ['itemtype' => 'Ticket',784 'id' => $tickets_id,785 'headers' => [786 'Session-Token' => $data['session_token']]],787 401,788 'ERROR_RIGHT_MISSING');789 // try to access ticket list (we should get empty return)790 $data = $this->query('getItems',791 ['itemtype' => 'Ticket',792 'headers' => ['Session-Token' => $data['session_token'],793 'query' => [794 'expand_dropdowns' => true]]]);795 $this->variable($data)->isNotFalse();796 $this->array($data)797 ->hasKey('headers')798 ->hasSize(1);799 // delete ticket800 $ticket->delete(['id' => $tickets_id], true);801 }802 /**803 * @tags api804 * @covers API::updateItems805 */806 public function testUpdateItem() {807 $computer = $this->createComputer();808 $computers_id = $computer->getID();809 $data = $this->query('updateItems',810 ['itemtype' => 'Computer',811 'verb' => 'PUT',812 'headers' => ['Session-Token' => $this->session_token],813 'json' => [814 'input' => [815 'id' => $computers_id,816 'serial' => "abcdef"]]]);817 $this->variable($data)->isNotFalse();818 $computer = array_shift($data);819 $this->array($computer)820 ->hasKey($computers_id)821 ->hasKey('message');822 $this->boolean((bool)$computer[$computers_id])->isTrue();823 $computer = new Computer;824 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();825 $this->string($computer->fields['serial'])->isIdenticalTo('abcdef');826 }827 /**828 * @tags api829 * @covers API::updateItems830 */831 public function testUpdateItems() {832 $computers_id_collection = $this->testCreateItems();833 $input = [];834 $computer = new Computer;835 foreach ($computers_id_collection as $key => $computers_id) {836 $input[] = ['id' => $computers_id['id'],837 'otherserial' => "abcdef"];838 }839 $data = $this->query('updateItems',840 ['itemtype' => 'Computer',841 'verb' => 'PUT',842 'headers' => ['Session-Token' => $this->session_token],843 'json' => ['input' => $input]]);844 $this->variable($data)->isNotFalse();845 $this->array($data)->hasKey('headers');846 unset($data['headers']);847 foreach ($data as $index => $row) {848 $computers_id = $computers_id_collection[$index]['id'];849 $this->array($row)850 ->hasKey($computers_id)851 ->hasKey('message');852 $this->boolean(true, (bool) $row[$computers_id])->isTrue();853 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();854 $this->string($computer->fields['otherserial'])->isIdenticalTo('abcdef');855 }856 }857 /**858 * @tags api859 * @covers API::deleteItems860 */861 public function testDeleteItem() {862 $computer = new \Computer();863 $this->integer(864 $computer->add([865 'name' => 'A computer to delete',866 'entities_id' => 1867 ])868 )->isGreaterThan(0);869 $computers_id = $computer->getID();870 $data = $this->query('deleteItems',871 ['itemtype' => 'Computer',872 'id' => $computers_id,873 'verb' => 'DELETE',874 'headers' => ['Session-Token' => $this->session_token],875 'query' => ['force_purge' => "true"]]);876 $this->variable($data)->isNotFalse();877 $this->array($data)->hasKey('headers');878 unset($data['headers']);879 $computer = array_shift($data);880 $this->array($computer)881 ->hasKey($computers_id)882 ->hasKey('message');883 $computer = new \Computer;884 $this->boolean((bool)$computer->getFromDB($computers_id))->isFalse();885 }886 /**887 * @tags api888 * @covers API::deleteItems889 */890 public function testDeleteItems() {891 $computers_id_collection = $this->testCreateItems();892 $input = [];893 $computer = new Computer;894 $lastComputer = array_pop($computers_id_collection);895 foreach ($computers_id_collection as $key => $computers_id) {896 $input[] = ['id' => $computers_id['id']];897 }898 $data = $this->query('deleteItems',899 ['itemtype' => 'Computer',900 'verb' => 'DELETE',901 'headers' => ['Session-Token' => $this->session_token],902 'json' => [903 'input' => $input,904 'force_purge' => true]]);905 $this->variable($data)->isNotFalse();906 unset($data['headers']);907 foreach ($data as $index => $row) {908 $computers_id = $computers_id_collection[$index]['id'];909 $this->array($row)910 ->hasKey($computers_id)911 ->hasKey('message');912 $this->boolean((bool)$row[$computers_id])->isTrue();913 $this->boolean((bool)$computer->getFromDB($computers_id))->isFalse();914 }915 // Test multiple delete with multi-status916 $input = [];917 $computers_id_collection = [918 ['id' => $lastComputer['id']],919 ['id' => $lastComputer['id'] + 1] // Non existing computer id920 ];921 foreach ($computers_id_collection as $key => $computers_id) {922 $input[] = ['id' => $computers_id['id']];923 }924 $data = $this->query('deleteItems',925 ['itemtype' => 'Computer',926 'verb' => 'DELETE',927 'headers' => ['Session-Token' => $this->session_token],928 'json' => [929 'input' => $input,930 'force_purge' => true]],931 207);932 $this->variable($data)->isNotFalse();933 $this->boolean($data[1][0][$computers_id_collection[0]['id']])->isTrue();934 $this->array($data[1][0])->hasKey('message');935 $this->boolean($data[1][1][$computers_id_collection[1]['id']])->isFalse();936 $this->array($data[1][1])->hasKey('message');937 }938 /**939 * @tags api940 */941 public function testInjection() {942 $data = $this->query('createItems',943 ['itemtype' => 'Computer',944 'verb' => 'POST',945 'headers' => ['Session-Token' => $this->session_token],946 'json' => [947 'input' => [948 'name' => "my computer', (SELECT `password` from `glpi_users` as `otherserial` WHERE `id`=2), '0 ' , '2016-10-26 00:00:00', '2016-10-26 00 :00 :00')#",949 'otherserial' => "Not hacked"]]],950 201);951 $this->array($data)952 ->hasKey('id');953 $new_id = $data['id'];954 $computer = new Computer();955 $this->boolean((bool)$computer->getFromDB($new_id))->isTrue();956 //Add SQL injection spotted!957 $this->boolean($computer->fields['otherserial'] != 'Not hacked')->isFalse();958 $data = $this->query('updateItems',959 ['itemtype' => 'Computer',960 'verb' => 'PUT',961 'headers' => ['Session-Token' => $this->session_token],962 'json' => [963 'input' => [964 'id' => $new_id,965 'serial' => "abcdef', `otherserial`='injected"]]]);966 $this->boolean((bool)$computer->getFromDB($new_id))->isTrue();967 //Update SQL injection spotted!968 $this->boolean($computer->fields['otherserial'] === 'injected')->isFalse();969 $computer = new Computer();970 $computer->delete(['id' => $new_id], true);971 }972 /**973 * @tags api974 */975 public function testProtectedConfigSettings() {976 $sensitiveSettings = [977 'proxy_passwd',978 'smtp_passwd',979 ];980 // set a non empty value to the sessionts to check981 foreach ($sensitiveSettings as $name) {982 Config::setConfigurationValues('core', [$name => 'not_empty_password']);983 $value = Config::getConfigurationValues('core', [$name]);984 $this->array($value)->hasKey($name);985 $this->string($value[$name])->isNotEmpty();986 }987 $config = new config();988 $rows = $config->find(['context' => 'core', 'name' => $sensitiveSettings]);989 $this->array($rows)990 ->hasSize(count($sensitiveSettings));991 // Check the value is not retrieved for sensitive settings992 foreach ($rows as $row) {993 $data = $this->query('getItem',994 ['itemtype' => 'Config',995 'id' => $row['id'],996 'headers' => ['Session-Token' => $this->session_token]]);997 $this->array($data)->notHasKey('value');998 }999 // Check an other setting is disclosed (when not empty)1000 $config = new Config();1001 $config->getFromDBByCrit(['context' => 'core', 'name' => 'admin_email']);1002 $data = $this->query('getItem',1003 ['itemtype' => 'Config',1004 'id' => $config->getID(),1005 'headers' => ['Session-Token' => $this->session_token]]);1006 $this->variable($data['value'])->isNotEqualTo('');1007 // Check a search does not disclose sensitive values1008 $criteria = [];1009 $queryString = "";1010 foreach ($rows as $row) {1011 $queryString = "&criteria[0][link]=or&criteria[0][field]=1&criteria[0][searchtype]=equals&criteria[0][value]=".$row['name'];1012 }1013 $data = $this->query('search',1014 ['itemtype' => 'Config',1015 'headers' => ['Session-Token' => $this->session_token],1016 'query' => []],1017 206);1018 foreach ($data['data'] as $row) {1019 foreach ($row as $col) {1020 $this->variable($col)->isNotEqualTo('not_empty_password');1021 }1022 }1023 }1024 /**1025 * @tags api1026 */1027 public function testProtectedDeviceSimcardFields() {1028 global $DB;1029 $sensitiveFields = [1030 'pin',1031 'pin2',1032 'puk',1033 'puk2',1034 ];1035 $obj = new \Item_DeviceSimcard();1036 // Add1037 $computer = getItemByTypeName('Computer', '_test_pc01');1038 $this->object($computer)->isInstanceOf('\Computer');1039 $deviceSimcard = getItemByTypeName('DeviceSimcard', '_test_simcard_1');1040 $this->integer((int) $deviceSimcard->getID())->isGreaterThan(0);1041 $this->object($deviceSimcard)->isInstanceOf('\Devicesimcard');1042 $input = [1043 'itemtype' => 'Computer',1044 'items_id' => $computer->getID(),1045 'devicesimcards_id' => $deviceSimcard->getID(),1046 'entities_id' => 0,1047 'pin' => '1234',1048 'pin2' => '2345',1049 'puk' => '3456',1050 'puk2' => '4567',1051 ];1052 $id = $obj->add($input);1053 $this->integer($id)->isGreaterThan(0);1054 //drop update access on item_devicesimcard1055 $DB->update(1056 'glpi_profilerights',1057 ['rights' => 2], [1058 'profiles_id' => 4,1059 'name' => 'devicesimcard_pinpuk'1060 ]1061 );1062 // Profile changed then login1063 $backupSessionToken = $this->session_token;1064 $this->initSessionCredentials();1065 $limitedSessionToken = $this->session_token;1066 //reset rights. Done here so ACLs are reset even if tests fails.1067 $DB->update(1068 'glpi_profilerights',1069 ['rights' => 3], [1070 'profiles_id' => 4,1071 'name' => 'devicesimcard_pinpuk'1072 ]1073 );1074 $this->session_token = $backupSessionToken;1075 // test getItem does not disclose sensitive fields when READ disabled1076 $data = $this->query('getItem',1077 ['itemtype' => 'Item_DeviceSimcard',1078 'id' => $id,1079 'headers' => ['Session-Token' => $limitedSessionToken]]);1080 foreach ($sensitiveFields as $field) {1081 $this->array($data)->notHasKey($field);1082 }1083 // test getItem discloses sensitive fields when READ enabled1084 $data = $this->query('getItem',1085 ['itemtype' => 'Item_DeviceSimcard',1086 'id' => $id,1087 'headers' => ['Session-Token' => $this->session_token]]);1088 foreach ($sensitiveFields as $field) {1089 $this->array($data)->hasKey($field);1090 }1091 // test searching a sensitive field as criteria id forbidden1092 $data = $this->query('search',1093 ['itemtype' => 'Item_DeviceSimcard',1094 'headers' => ['Session-Token' => $this->session_token],1095 'query' => ['criteria' => [1096 0 => ['field' => 15,1097 'searchtype' => 'equals',1098 'value' => $input['pin']1099 ]1100 ]1101 ]1102 ],1103 400,1104 'ERROR');1105 // test forcing display of a sensitive field1106 $data = $this->query('search',1107 ['itemtype' => 'Item_DeviceSimcard',1108 'headers' => ['Session-Token' => $this->session_token],1109 'query' => [1110 'forcedisplay' => [15]1111 ]1112 ],1113 400,1114 'ERROR');1115 }1116 /**1117 * @tags api1118 * @covers API::getGlpiConfig1119 */1120 public function testGetGlpiConfig() {1121 $data = $this->query('getGlpiConfig',1122 ['headers' => ['Session-Token' => $this->session_token]]);1123 // Test a disclosed data1124 $this->array($data)1125 ->hasKey('cfg_glpi');1126 $this->array($data['cfg_glpi'])1127 ->hasKey('infocom_types');1128 // Test undisclosed data are actually not disclosed1129 $this->array(Config::$undisclosedFields)1130 ->size->isGreaterThan(0);1131 foreach (Config::$undisclosedFields as $key) {1132 $this->array($data['cfg_glpi'])->notHasKey($key);1133 }1134 }1135 /**1136 * @tags api1137 * @covers API::killSession1138 */1139 public function testKillSession() {1140 // test retrieve all users1141 $res = $this->query('killSession',1142 ['headers' => ['Session-Token' => $this->session_token]]);1143 $res = $this->query('getFullSession',1144 ['headers' => ['Session-Token' => $this->session_token]],1145 401,1146 'ERROR_SESSION_TOKEN_INVALID');1147 }1148 /**1149 * @tags api1150 * @engine inline1151 */1152 public function testLostPasswordRequest() {1153 global $CFG_GLPI;1154 $user = getItemByTypeName('User', TU_USER);1155 $email = $user->getDefaultEmail();1156 // Test the verb POST is not alloxed1157 $res = $this->query('lostPassword',1158 ['verb' => 'POST',1159 ],1160 400,1161 'ERROR');1162 // Test the verb GET is not alloxed1163 $res = $this->query('lostPassword',1164 ['verb' => 'GET',1165 ],1166 400,1167 'ERROR');1168 // Test the verb DELETE is not allowed1169 $res = $this->query('lostPassword',1170 ['verb' => 'DELETE',1171 ],1172 400,1173 'ERROR');1174 $this->array($CFG_GLPI)1175 ->variable['use_notifications']->isEqualTo(0)1176 ->variable['notifications_mailing']->isEqualTo(0);1177 // Test disabled notifications make this fail1178 $res = $this->query('lostPassword',1179 ['verb' => 'PUT',1180 'json' => [1181 'email' => $email1182 ]1183 ],1184 400,1185 'ERROR');1186 //enable notifications1187 Config::setConfigurationValues('core', [1188 'use_notifications' => '1',1189 'notifications_mailing' => '1'1190 ]);1191 // Test an unknown email is rejected1192 $res = $this->query('lostPassword',1193 ['verb' => 'PUT',1194 'json' => [1195 'email' => 'nonexistent@localhost.local'1196 ]1197 ],1198 400,1199 'ERROR');1200 // Test a valid email is accepted1201 $res = $this->query('lostPassword',1202 ['verb' => 'PATCH',1203 'json' => [1204 'email' => $email1205 ]1206 ],1207 200);1208 // get the password recovery token1209 $user = getItemByTypeName('User', TU_USER);1210 $token = $user->getField('password_forget_token');1211 // Test reset password with a bad token1212 $res = $this->query('lostPassword',1213 ['verb' => 'PUT',1214 'json' => [1215 'email' => $email,1216 'password_forget_token' => $token . 'bad',1217 'password' => 'NewPassword',1218 ]1219 ],1220 400,1221 'ERROR');1222 // Test reset password with the good token1223 $res = $this->query('lostPassword',1224 ['verb' => 'PATCH',1225 'json' => [1226 'email' => $email,1227 'password_forget_token' => $token,1228 'password' => 'NewPassword',1229 ]1230 ],1231 200);1232 // Refresh the in-memory instance of user and get the password1233 $user->getFromDB($user->getID());1234 $newHash = $user->getField('password');1235 // Restore the initial password in the DB1236 $updateSuccess = $user->update([1237 'id' => $user->getID(),1238 'password' => TU_PASS,1239 'password2' => TU_PASS1240 ]);1241 $this->variable($updateSuccess)->isNotFalse('password update failed');1242 // Test the new password was saved1243 $this->variable(\Auth::checkPassword('NewPassword', $newHash))->isNotFalse();1244 //diable notifications1245 Config::setConfigurationValues('core', [1246 'use_notifications' => '0',1247 'notifications_mailing' => '0'1248 ]);1249 }1250 /**1251 * Check consistency of Content-Range header1252 *1253 * @param array $data Data1254 * @param array $headers Headers1255 *1256 * @return void1257 */1258 protected function checkContentRange($data, $headers) {1259 $this->integer($data['count'])->isLessThanOrEqualTo($data['totalcount']);1260 $this->array($headers)->hasKey('Content-Range');1261 $expectedContentRange = '0-'.($data['count'] - 1).'/'.$data['totalcount'];1262 $this->string($headers['Content-Range'][0])->isIdenticalTo($expectedContentRange);1263 }1264 /**1265 * Check consistency of empty Content-Range header1266 *1267 * @param array $data Data1268 * @param array $headers Headers1269 *1270 * @return void1271 */1272 protected function checkEmptyContentRange($data, $headers) {1273 $this->integer($data['count'])->isLessThanOrEqualTo($data['totalcount']);1274 $this->integer($data['totalcount'])->isEqualTo(0);1275 $this->array($headers)->notHasKey('Content-Range');1276 }1277}...
Context.php
Source:Context.php
1<?php2/**3 * Hoa4 *5 *6 * @license7 *8 * New BSD License9 *10 * Copyright © 2007-2017, Hoa community. All rights reserved.11 *12 * Redistribution and use in source and binary forms, with or without13 * modification, are permitted provided that the following conditions are met:14 * * Redistributions of source code must retain the above copyright15 * notice, this list of conditions and the following disclaimer.16 * * Redistributions in binary form must reproduce the above copyright17 * notice, this list of conditions and the following disclaimer in the18 * documentation and/or other materials provided with the distribution.19 * * Neither the name of the Hoa nor the names of its contributors may be20 * used to endorse or promote products derived from this software without21 * specific prior written permission.22 *23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE33 * POSSIBILITY OF SUCH DAMAGE.34 */35namespace Hoa\Math\Test\Unit;36use Hoa\Math\Context as CUT;37use Hoa\Test;38/**39 * Class \Hoa\Math\Test\Unit\Context.40 *41 * Test suite of the Hoa\Math\Context class.42 *43 * @copyright Copyright © 2007-2017 Hoa community44 * @license New BSD License45 */46class Context extends Test\Unit\Suite47{48 public function case_context_has_no_predefined_variable()49 {50 $this51 ->given($context = new CUT())52 ->when($result = $context->getVariables())53 ->then54 ->object($result)55 ->isInstanceOf('ArrayObject')56 ->array(iterator_to_array($result))57 ->isEmpty();58 }59 public function case_context_exception_when_getting_unknown_variable()60 {61 $this62 ->given(63 $name = 'foo',64 $context = new CUT()65 )66 ->then67 ->exception(function () use ($context, $name) {68 $context->getVariable($name);69 })70 ->isInstanceOf('Hoa\Math\Exception\UnknownVariable');71 }72 public function case_context_returns_variable_value()73 {74 $this75 ->given(76 $name = 'foo',77 $value = 42,78 $callable = function () use ($value) { return $value; },79 $context = new CUT(),80 $context->addVariable($name, $callable)81 )82 ->when($result = $context->getVariable($name))83 ->then84 ->integer($result)85 ->isEqualTo($value);86 }87 public function case_context_has_predefined_constants()88 {89 $this90 ->given($context = new CUT())91 ->when($result = $context->getConstants())92 ->then93 ->object($result)94 ->isInstanceOf('ArrayObject')95 ->array(iterator_to_array($result))96 ->isEqualTo([97 'PI' => M_PI,98 'PI_2' => M_PI_2,99 'PI_4' => M_PI_4,100 'E' => M_E,101 'SQRT_PI' => M_SQRTPI,102 'SQRT_2' => M_SQRT2,103 'SQRT_3' => M_SQRT3,104 'LN_PI' => M_LNPI,105 'LOG_2E' => M_LOG2E,106 'LOG_10E' => M_LOG10E,107 'LN_2' => M_LN2,108 'LN_10' => M_LN10,109 'ONE_OVER_PI' => M_1_PI,110 'TWO_OVER_PI' => M_2_PI,111 'TWO_OVER_SQRT_PI' => M_2_SQRTPI,112 'ONE_OVER_SQRT_2' => M_SQRT1_2,113 'EULER' => M_EULER,114 'INFINITE' => INF115 ]);116 }117 public function case_context_exception_when_getting_unknown_constant()118 {119 $this120 ->given(121 $name = 'FOO',122 $context = new CUT()123 )124 ->then125 ->exception(function () use ($context, $name) {126 $context->getConstant($name);127 })128 ->isInstanceOf('Hoa\Math\Exception\UnknownConstant');129 }130 public function case_context_exception_when_setting_already_defined_constant()131 {132 $this133 ->given(134 $name = 'PI',135 $context = new CUT()136 )137 ->then138 ->exception(function () use ($context, $name) {139 $context->addConstant($name, 42);140 })141 ->isInstanceOf('Hoa\Math\Exception\AlreadyDefinedConstant');142 }143 public function case_context_returns_constant_value()144 {145 $this146 ->given(147 $name = 'FOO',148 $value = 42,149 $context = new CUT(),150 $context->addConstant($name, $value)151 )152 ->when($result = $context->getConstant($name))153 ->then154 ->variable($result)155 ->isEqualTo($value);156 }157 public function case_context_has_predefined_functions()158 {159 $this160 ->given($context = new CUT())161 ->when($result = $context->getFunctions())162 ->then163 ->object($result)164 ->isInstanceOf('ArrayObject')165 ->array(iterator_to_array($result))166 ->hasSize(23)167 ->hasKey('abs')168 ->hasKey('acos')169 ->hasKey('asin')170 ->hasKey('atan')171 ->hasKey('average')172 ->hasKey('avg')173 ->hasKey('ceil')174 ->hasKey('cos')175 ->hasKey('count')176 ->hasKey('deg2rad')177 ->hasKey('exp')178 ->hasKey('floor')179 ->hasKey('ln')180 ->hasKey('log')181 ->hasKey('max')182 ->hasKey('min')183 ->hasKey('pow')184 ->hasKey('rad2deg')185 ->hasKey('round')186 ->hasKey('round')187 ->hasKey('sin')188 ->hasKey('sqrt')189 ->hasKey('sum')190 ->hasKey('tan');191 }192 public function case_context_exception_when_getting_unknown_function()193 {194 $this195 ->given(196 $name = 'foo',197 $context = new CUT()198 )199 ->then200 ->exception(function () use ($context, $name) {201 $context->getFunction($name);202 })203 ->isInstanceOf('Hoa\Math\Exception\UnknownFunction');204 }205 public function case_context_exception_when_setting_unknown_function()206 {207 $this208 ->given(209 $name = 'foo',210 $context = new CUT()211 )212 ->then213 ->exception(function () use ($context, $name) {214 $context->addFunction($name);215 })216 ->isInstanceOf('Hoa\Math\Exception\UnknownFunction');217 }218 public function case_context_returns_function_callable()219 {220 $this221 ->given(222 $name = 'foo',223 $callable = function () {},224 $context = new CUT(),225 $context->addFunction($name, $callable)226 )227 ->when($result = $context->getFunction($name))228 ->then229 ->object($result)230 ->isInstanceOf('Hoa\Consistency\Xcallable');231 }232 public function case_context_returns_the_right_function_callable()233 {234 $this235 ->given(236 $name = 'foo',237 $value = 42,238 $callable = function () use ($value) { return $value; },239 $context = new CUT(),240 $context->addFunction($name, $callable)241 )242 ->when($result = $context->getFunction($name))243 ->then244 ->integer($result())245 ->isEqualTo($value);246 }247}...
NeonParser.php
Source:NeonParser.php
1<?php2/**3 * This file is part of the Nette Framework.4 *5 * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)6 *7 * This source file is subject to the "Nette license", and/or8 * GPL license. For more information please see http://nette.org9 */10namespace Nette;11use Nette;12/**13 * Simple parser for Nette Object Notation.14 *15 * @author David Grudl16 */17class NeonParser extends Object18{19 /** @var array */20 private static $patterns = array(21 '\'[^\'\n]*\'|"(?:\\\\.|[^"\\\\\n])*"', // string22 '@[a-zA-Z_0-9\\\\]+', // object23 '[:-](?=\s|$)|[,=[\]{}()]', // symbol24 '?:#.*', // comment25 '\n *', // indent26 '[^#"\',:=@[\]{}()<>\s](?:[^#,:=\]})>\n]+|:(?!\s)|(?<!\s)#)*(?<!\s)', // literal / boolean / integer / float27 '?: +', // whitespace28 );29 /** @var Tokenizer */30 private static $tokenizer;31 private static $brackets = array(32 '[' => ']',33 '{' => '}',34 '(' => ')',35 );36 /** @var int */37 private $n;38 /**39 * Parser.40 * @param string41 * @return array42 */43 public function parse($input)44 {45 if (!self::$tokenizer) { // speed-up46 self::$tokenizer = new Tokenizer(self::$patterns, 'mi');47 }48 $input = str_replace("\r", '', $input);49 $input = strtr($input, "\t", ' ');50 $input = "\n" . $input . "\n"; // first \n is required by "Indent"51 self::$tokenizer->tokenize($input);52 $this->n = 0;53 $res = $this->_parse();54 while (isset(self::$tokenizer->tokens[$this->n])) {55 if (self::$tokenizer->tokens[$this->n][0] === "\n") {56 $this->n++;57 } else {58 $this->error();59 }60 }61 return $res;62 }63 /**64 * Tokenizer & parser.65 * @param int indentation (for block-parser)66 * @param string end char (for inline-hash/array parser)67 * @return array68 */69 private function _parse($indent = NULL, $endBracket = NULL)70 {71 $inlineParser = $endBracket !== NULL; // block or inline parser?72 $result = $inlineParser || $indent ? array() : NULL;73 $value = $key = $object = NULL;74 $hasValue = $hasKey = FALSE;75 $tokens = self::$tokenizer->tokens;76 $n = & $this->n;77 $count = count($tokens);78 for (; $n < $count; $n++) {79 $t = $tokens[$n];80 if ($t === ',') { // ArrayEntry separator81 if (!$hasValue || !$inlineParser) {82 $this->error();83 }84 if ($hasKey) $result[$key] = $value; else $result[] = $value;85 $hasKey = $hasValue = FALSE;86 } elseif ($t === ':' || $t === '=') { // KeyValuePair separator87 if ($hasKey || !$hasValue) {88 $this->error();89 }90 $key = (string) $value;91 $hasKey = TRUE;92 $hasValue = FALSE;93 } elseif ($t === '-') { // BlockArray bullet94 if ($hasKey || $hasValue || $inlineParser) {95 $this->error();96 }97 $key = NULL;98 $hasKey = TRUE;99 } elseif (isset(self::$brackets[$t])) { // Opening bracket [ ( {100 if ($hasValue) {101 $this->error();102 }103 $hasValue = TRUE;104 $value = $this->_parse(NULL, self::$brackets[$tokens[$n++]]);105 } elseif ($t === ']' || $t === '}' || $t === ')') { // Closing bracket ] ) }106 if ($t !== $endBracket) { // unexpected type of bracket or block-parser107 $this->error();108 }109 if ($hasValue) {110 if ($hasKey) $result[$key] = $value; else $result[] = $value;111 } elseif ($hasKey) {112 $this->error();113 }114 return $result; // inline parser exit point115 } elseif ($t[0] === '@') { // Object116 $object = $t; // TODO117 } elseif ($t[0] === "\n") { // Indent118 if ($inlineParser) {119 if ($hasValue) {120 if ($hasKey) $result[$key] = $value; else $result[] = $value;121 $hasKey = $hasValue = FALSE;122 }123 } else {124 while (isset($tokens[$n+1]) && $tokens[$n+1][0] === "\n") $n++; // skip to last indent125 $newIndent = strlen($tokens[$n]) - 1;126 if ($indent === NULL) { // first iteration127 $indent = $newIndent;128 }129 if ($newIndent > $indent) { // open new block-array or hash130 if ($hasValue || !$hasKey) {131 $this->error();132 } elseif ($key === NULL) {133 $result[] = $this->_parse($newIndent);134 } else {135 $result[$key] = $this->_parse($newIndent);136 }137 $newIndent = strlen($tokens[$n]) - 1;138 $hasKey = FALSE;139 } else {140 if ($hasValue && !$hasKey) { // block items must have "key"; NULL key means list item141 if ($result === NULL) return $value; // simple value parser exit point142 $this->error();143 } elseif ($hasKey) {144 $value = $hasValue ? $value : NULL;145 if ($key === NULL) $result[] = $value; else $result[$key] = $value;146 $hasKey = $hasValue = FALSE;147 }148 }149 if ($newIndent < $indent || !isset($tokens[$n+1])) { // close block150 return $result; // block parser exit point151 }152 }153 } else { // Value154 if ($hasValue) {155 $this->error();156 }157 if ($t[0] === '"') {158 $value = json_decode($t);159 if ($value === NULL) {160 $this->error();161 }162 } elseif ($t[0] === "'") {163 $value = substr($t, 1, -1);164 } elseif ($t === 'true' || $t === 'yes' || $t === 'TRUE' || $t === 'YES') {165 $value = TRUE;166 } elseif ($t === 'false' || $t === 'no' || $t === 'FALSE' || $t === 'NO') {167 $value = FALSE;168 } elseif ($t === 'null' || $t === 'NULL') {169 $value = NULL;170 } elseif (is_numeric($t)) {171 $value = $t * 1;172 } else { // literal173 $value = $t;174 }175 $hasValue = TRUE;176 }177 }178 throw new NeonException('Unexpected end of file.');179 }180 private function error()181 {182 list(, $line, $col) = self::$tokenizer->getOffset($this->n);183 throw new NeonException("Unexpected '" . str_replace("\n", '\n', substr(self::$tokenizer->tokens[$this->n], 0, 10))184 . "' on line " . ($line - 1) . ", column $col.");185 }186}187/**188 * The exception that indicates error of NEON decoding.189 */190class NeonException extends \Exception191{192}...
HasKey
Using AI Code Generation
1$mock = Mockery::mock('HasKey');2$mock->shouldReceive('has')->andReturn(true);3$mock->shouldReceive('get')->andReturn('foo');4$mock = Mockery::mock('HasKey');5$mock->shouldReceive('has')->andReturn(true);6$mock->shouldReceive('get')->andReturn('foo');7$mock = Mockery::mock('HasKey');8$mock->shouldReceive('has')->andReturn(true);9$mock->shouldReceive('get')->andReturn('foo');10$mock = Mockery::mock('HasKey');11$mock->shouldReceive('has')->andReturn(true);12$mock->shouldReceive('get')->andReturn('foo');13$mock = Mockery::mock('HasKey');14$mock->shouldReceive('has')->andReturn(true);15$mock->shouldReceive('get')->andReturn('foo');16$mock = Mockery::mock('HasKey');17$mock->shouldReceive('has')->andReturn(true);18$mock->shouldReceive('get')->andReturn('foo');19$mock = Mockery::mock('HasKey');20$mock->shouldReceive('has')->andReturn(true);21$mock->shouldReceive('get')->andReturn('foo');22$mock = Mockery::mock('HasKey');23$mock->shouldReceive('has')->andReturn(true);24$mock->shouldReceive('get')->andReturn('foo');25$mock = Mockery::mock('HasKey');26$mock->shouldReceive('has')->andReturn(true);27$mock->shouldReceive('get')->andReturn('foo');28$mock = Mockery::mock('HasKey');29$mock->shouldReceive('has')->andReturn(true);30$mock->shouldReceive('get')->andReturn('foo');31$mock = Mockery::mock('
HasKey
Using AI Code Generation
1$mock = Mockery::mock('HasKeys');2$mock->shouldReceive('hasKey')3->with('foo')4->once()5->andReturn(true);6$mock = Mockery::mock('HasKeys');7$mock->shouldReceive('hasKey')8->with('foo')9->once()10->andReturn(true);11$mock = Mockery::mock('HasKeys');12$mock->shouldReceive('hasKey')13->with('foo')14->once()15->andReturn(true);16$mock = Mockery::mock('HasKeys');17$mock->shouldReceive('hasKey')18->with('foo')19->once()20->andReturn(true);21$mock = Mockery::mock('HasKeys');22$mock->shouldReceive('hasKey')23->with('foo')24->once()25->andReturn(true);26$mock = Mockery::mock('HasKeys');27$mock->shouldReceive('hasKey')28->with('foo')29->once()30->andReturn(true);31$mock = Mockery::mock('HasKeys');32$mock->shouldReceive('hasKey')33->with('foo')34->once()35->andReturn(true);36$mock = Mockery::mock('HasKeys');37$mock->shouldReceive('hasKey')38->with('foo')39->once()40->andReturn(true);41$mock = Mockery::mock('HasKeys');42$mock->shouldReceive('hasKey')43->with('foo')44->once()45->andReturn(true);46$mock = Mockery::mock('HasKeys');47$mock->shouldReceive('hasKey')48->with('foo')49->once()50->andReturn(true);51$mock = Mockery::mock('HasKeys');
HasKey
Using AI Code Generation
1$mockery = new Mockery();2$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);3$mockery = new Mockery();4$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);5$mockery = new Mockery();6$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);7$mockery = new Mockery();8$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);9$mockery = new Mockery();10$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);11$mockery = new Mockery();12$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);13$mockery = new Mockery();14$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);15$mockery = new Mockery();16$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);17$mockery = new Mockery();18$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);19$mockery = new Mockery();20$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);21$mockery = new Mockery();22$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);23$mockery = new Mockery();24$mockery->shouldReceive('hasKey')->with('key')->andReturn(false);25$mockery = new Mockery();26$mockery->shouldReceive('hasKey')->with('key')->andReturn(true);
HasKey
Using AI Code Generation
1$mock = Mockery::mock('HasKey');2$mock->shouldReceive('hasKey')->once()->andReturn(true);3$mock->shouldReceive('hasKey')->once()->andReturn(false);4$mock->shouldReceive('hasKey')->times(3)->andReturn(true);5$mock->shouldReceive('hasKey')->times(4)->andReturn(false);6$mock->shouldReceive('hasKey')->andReturn(true);7$mock->shouldReceive('hasKey')->andReturn(false);8$mock->shouldReceive('hasKey')->andReturnUsing(function($arg) { return $arg; });9$mock = Mockery::mock('HasKey');10$mock->shouldReceive('hasKey')->once()->andReturn(true);11$mock->shouldReceive('hasKey')->once()->andReturn(false);12$mock->shouldReceive('hasKey')->times(3)->andReturn(true);13$mock->shouldReceive('hasKey')->times(4)->andReturn(false);14$mock->shouldReceive('hasKey')->andReturn(true);15$mock->shouldReceive('hasKey')->andReturn(false);16$mock->shouldReceive('hasKey')->andReturnUsing(function($arg) { return $arg; });17$mock = Mockery::mock('HasKey');18$mock->shouldReceive('hasKey')->once()->andReturn(true);19$mock->shouldReceive('hasKey')->once()->andReturn(false);20$mock->shouldReceive('hasKey')->times(3)->andReturn(true);21$mock->shouldReceive('hasKey')->times(4)->andReturn(false);22$mock->shouldReceive('hasKey')->andReturn(true);23$mock->shouldReceive('hasKey')->andReturn(false);24$mock->shouldReceive('hasKey')->andReturnUsing(function($arg) { return $arg; });25$mock = Mockery::mock('HasKey');26$mock->shouldReceive('hasKey')->once()->andReturn(true);27$mock->shouldReceive('hasKey')->once()->andReturn(false);28$mock->shouldReceive('hasKey')->times(3)->andReturn(true);29$mock->shouldReceive('hasKey')->times(4)->andReturn(false);30$mock->shouldReceive('hasKey')->andReturn(true);31$mock->shouldReceive('hasKey')->andReturn(false
HasKey
Using AI Code Generation
1$mock = Mockery::mock('Haskey');2$mock->shouldReceive('hasKey')->andReturn(false);3$mock->shouldReceive('setKey')->andReturn(true);4$mock->shouldReceive('getKey')->andReturn('key');5$mock->shouldReceive('deleteKey')->andReturn(true);6$mock->shouldReceive('clear')->andReturn(true);7$mock = Mockery::mock('Haskey');8$mock->shouldReceive('hasKey')->andReturn(true);9$mock->shouldReceive('setKey')->andReturn(false);10$mock->shouldReceive('getKey')->andReturn('key');11$mock->shouldReceive('deleteKey')->andReturn(false);12$mock->shouldReceive('clear')->andReturn(false);13$mock = Mockery::mock('Haskey');14$mock->shouldReceive('hasKey')->andReturn(true);15$mock->shouldReceive('setKey')->andReturn(true);16$mock->shouldReceive('getKey')->andReturn('key');17$mock->shouldReceive('deleteKey')->andReturn(true);18$mock->shouldReceive('clear')->andReturn(true);19$mock = Mockery::mock('Haskey');20$mock->shouldReceive('hasKey')->andReturn(false);21$mock->shouldReceive('setKey')->andReturn(false);22$mock->shouldReceive('getKey')->andReturn('key');23$mock->shouldReceive('deleteKey')->andReturn(false);24$mock->shouldReceive('clear')->andReturn(false);25$mock = Mockery::mock('Haskey');26$mock->shouldReceive('hasKey')->andReturn(true);27$mock->shouldReceive('setKey')->andReturn(true);28$mock->shouldReceive('getKey')->andReturn('key');29$mock->shouldReceive('deleteKey')->andReturn(false);30$mock->shouldReceive('clear')->andReturn(false);31$mock = Mockery::mock('Haskey');32$mock->shouldReceive('hasKey')->andReturn(false);33$mock->shouldReceive('setKey')->andReturn(true);34$mock->shouldReceive('getKey')->andReturn('key');35$mock->shouldReceive('deleteKey')->andReturn(false);36$mock->shouldReceive('clear')->andReturn(false);
HasKey
Using AI Code Generation
1$mock = Mockery::mock('alias:Illuminate\Support\Facades\Redis');2$mock->shouldReceive('hSet')->once()->with('users', '1', 'John Doe');3$mock->shouldReceive('hSet')->once()->with('users', '2', 'Jane Doe');4$mock->shouldReceive('hSet')->once()->with('users', '3', 'John Smith');5$mock->shouldReceive('hSet')->once()->with('users', '4', 'Jane Smith');6$mock->shouldReceive('hSet')->once()->with('users', '1', 'John Doe');7$mock->shouldReceive('hSet')->once()->with('users', '2', 'Jane Doe');8$mock->shouldReceive('hSet')->once()->with('users', '3', 'John Smith');9$mock->shouldReceive('hSet')->once()->with('users', '4', 'Jane Smith');10$mock->shouldReceive('hGet')->once()->with('users', '1')->andReturn('John Doe');11$mock->shouldReceive('hGet')->once()->with('users', '2')->andReturn('Jane Doe');12$mock->shouldReceive('hGet')->once()->with('users', '3')->andReturn('John Smith');13$mock->shouldReceive('hGet')->once()->with('users', '4')->andReturn('Jane Smith');14$mock->shouldReceive('hGet')->once()->with('users', '1')->andReturn('John Doe');15$mock->shouldReceive('hGet')->once()->with('users', '2')->andReturn('Jane Doe');16$mock->shouldReceive('hGet')->once()->with('users', '3')->andReturn('John Smith');17$mock->shouldReceive('hGet')->once()->with('users', '4')->andReturn('Jane Smith');18$mock->shouldReceive('hGetAll')->once()->with('users')->andReturn(['1' => 'John Doe', '2' => 'Jane Doe', '3' => 'John Smith', '4' => 'Jane Smith']);19$mock->shouldReceive('hGetAll')->once()->with('users')->andReturn(['1' => 'John Doe', '2' => 'Jane Doe', '3' => 'John Smith', '4' => 'Jane Smith']);20$mock->shouldReceive('hKeys')->once()->with('users')->andReturn(['1', '2', '3', '4']);21$mock->shouldReceive('hKeys')->once()->with('users')->andReturn
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.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!