Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * Test SQL debugging fixture
  19   *
  20   * @package    core
  21   * @category   dml
  22   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Test SQL debugging fixture
  30   *
  31   * @package    core
  32   * @category   dml
  33   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class test_dml_sql_debugging_fixture {
  37      /** @var db handle */
  38      private $db;
  39  
  40      /**
  41       * constructor
  42       * @param testcase $testcase test object
  43       */
  44      public function __construct($testcase) {
  45          $this->db = $testcase->getMockBuilder(\moodle_database::class)
  46              ->getMockForAbstractClass();
  47      }
  48  
  49      /**
  50       * Get db handle
  51       * @return a db handle
  52       */
  53      public function get_mock() {
  54          return $this->db;
  55      }
  56  
  57      /**
  58       * Test caller in stacktrace
  59       * @param string $sql original sql
  60       * @return string sql with comments
  61       */
  62      public function one(string $sql) {
  63          $method = new \ReflectionMethod($this->db, 'add_sql_debugging');
  64          $method->setAccessible(true);
  65          return $method->invoke($this->db, $sql);
  66      }
  67  
  68      /**
  69       * Test caller in stacktrace
  70       * @param string $sql original sql
  71       * @return string sql with comments
  72       */
  73      public function two(string $sql) {
  74          return $this->one($sql);
  75      }
  76  
  77      /**
  78       * Test caller in stacktrace
  79       * @param string $sql original sql
  80       * @return string sql with comments
  81       */
  82      public function three(string $sql) {
  83          return $this->two($sql);
  84      }
  85  
  86      /**
  87       * Test caller in stacktrace
  88       * @param string $sql original sql
  89       * @return string sql with comments
  90       */
  91      public function four(string $sql) {
  92          return $this->three($sql);
  93      }
  94  
  95  }