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   * Provides {@link testable_code_manager} class.
  19   *
  20   * @package     core_plugin
  21   * @category    test
  22   * @copyright   2015 David Mudrak <david@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\update;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * Testable variant of \core\update\code_manager class.
  32   *
  33   * Provides access to some protected methods we want to explicitly test and
  34   * bypass the actual cURL calls by providing fake responses.
  35   *
  36   * @copyright 2015 David Mudrak <david@moodle.com>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class testable_code_manager extends code_manager {
  40  
  41      /** @var int how many times $this->download_file_content() was called */
  42      public $downloadscounter = 0;
  43  
  44      /**
  45       * Fake method to simulate fetching file via cURL.
  46       *
  47       * It simply creates a new file in the given location, the contents of
  48       * which is the URL itself.
  49       *
  50       * @param string $url URL to the file
  51       * @param string $tofile full path to where to store the downloaded file
  52       * @return bool
  53       */
  54      protected function download_file_content($url, $tofile) {
  55          $this->downloadscounter++;
  56          file_put_contents($tofile, $url);
  57          return true;
  58      }
  59  }