Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Database driver test class for testing moodle_read_slave_trait 19 * 20 * @package core 21 * @category dml 22 * @copyright 2018 Srdjan Janković, Catalyst IT 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace core; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 require_once (__DIR__.'/read_slave_moodle_database.php'); 31 32 /** 33 * Database driver mock test class that uses read_slave_moodle_recordset_special 34 * 35 * @package core 36 * @category dml 37 * @copyright 2018 Catalyst IT 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class read_slave_moodle_database_special extends read_slave_moodle_database { 41 /** 42 * Returns empty array 43 * @param string $sql the SQL select query to execute. 44 * @param array $params array of sql parameters 45 * @param int $limitfrom return a subset of records, starting at this point (optional). 46 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). 47 * @return string $handle handle property 48 */ 49 public function get_records_sql($sql, array $params = null, $limitfrom = 0, $limitnum = 0) { 50 $dbhandle = parent::get_records_sql($sql, $params); 51 return []; 52 } 53 54 /** 55 * Returns read_slave_moodle_database::get_records_sql() 56 * For the tests where we need both fake result and dbhandle info. 57 * @param string $sql the SQL select query to execute. 58 * @param array $params array of sql parameters 59 * @param int $limitfrom return a subset of records, starting at this point (optional). 60 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). 61 * @return string $handle handle property 62 */ 63 public function get_records_sql_p($sql, array $params = null, $limitfrom = 0, $limitnum = 0) { 64 return parent::get_records_sql($sql, $params); 65 } 66 67 /** 68 * Returns fake recordset 69 * @param string $sql 70 * @param array $params 71 * @param int $limitfrom 72 * @param int $limitnum 73 * @return bool true 74 */ 75 public function get_recordset_sql($sql, array $params = null, $limitfrom = 0, $limitnum = 0) { 76 $dbhandle = parent::get_recordset_sql($sql, $params); 77 return new read_slave_moodle_recordset_special(); 78 } 79 80 /** 81 * Count the records in a table where all the given conditions met. 82 * 83 * @param string $table The table to query. 84 * @param array $conditions optional array $fieldname=>requestedvalue with AND in between 85 * @return int The count of records returned from the specified criteria. 86 */ 87 public function count_records($table, array $conditions = null) { 88 return 1; 89 } 90 } 91 92 /** 93 * Database recordset mock test class 94 * 95 * @package core 96 * @category dml 97 * @copyright 2018 Catalyst IT 98 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 99 */ 100 class read_slave_moodle_recordset_special extends \moodle_recordset { 101 /** 102 * Iterator interface 103 * @return void 104 */ 105 public function close() { 106 } 107 /** 108 * Iterator interface 109 * @return \stdClass 110 */ 111 public function current(): \stdClass { 112 return new \stdClass(); 113 } 114 /** 115 * Iterator interface 116 * @return void 117 */ 118 public function next(): void { 119 } 120 /** 121 * Iterator interface 122 * @return mixed 123 */ 124 #[\ReturnTypeWillChange] 125 public function key() { 126 } 127 /** 128 * Iterator interface 129 * @return bool 130 */ 131 public function valid(): bool { 132 return false; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body