Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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  namespace core\testing;
  18  
  19  /**
  20   * Testing util tests.
  21   *
  22   * @package    core
  23   * @category   phpunit
  24   * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  class util_test extends \advanced_testcase {
  28      /**
  29       * Note: This test is required for the other two parts because the first time
  30       * a table is written to it may not have had the initial value reset.
  31       *
  32       * @coversNothing
  33       */
  34      public function test_increment_reset_part_one(): void {
  35          global $DB;
  36  
  37          switch ($DB->get_dbfamily()) {
  38              case 'mssql':
  39                  $this->markTestSkipped('MSSQL does not support sequences');
  40                  return;
  41          }
  42  
  43          $this->resetAfterTest();
  44          $DB->insert_record('config_plugins', [
  45              'plugin' => 'example',
  46              'name' => 'test_increment',
  47              'value' => 0,
  48          ]);
  49      }
  50  
  51      /**
  52       * @coversNothing
  53       * @depends test_increment_reset_part_one
  54       */
  55      public function test_increment_reset_part_two(): int {
  56          global $DB;
  57  
  58          $this->resetAfterTest();
  59          return $DB->insert_record('config_plugins', [
  60              'plugin' => 'example',
  61              'name' => 'test_increment',
  62              'value' => 0,
  63          ]);
  64      }
  65  
  66      /**
  67       * @depends test_increment_reset_part_two
  68       */
  69      public function test_increment_reset_part_three(int $previousid): void {
  70          global $DB;
  71  
  72          $this->resetAfterTest();
  73          $id = $DB->insert_record('config_plugins', [
  74              'plugin' => 'example',
  75              'name' => 'test_increment',
  76              'value' => 0,
  77          ]);
  78          $this->assertEquals($previousid, $id);
  79      }
  80  }