diff --git a/lib/testing/tests/util_test.php b/lib/testing/tests/util_test.php new file mode 100644 index 00000000000..59b233cce4a --- /dev/null +++ b/lib/testing/tests/util_test.php @@ -0,0 +1,80 @@ +. + +namespace core\testing; + +/** + * Testing util tests. + * + * @package core + * @category phpunit + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class util_test extends \advanced_testcase { + /** + * Note: This test is required for the other two parts because the first time + * a table is written to it may not have had the initial value reset. + * + * @coversNothing + */ + public function test_increment_reset_part_one(): void { + global $DB; + + switch ($DB->get_dbfamily()) { + case 'mssql': + $this->markTestSkipped('MSSQL does not support sequences'); + return; + } + + $this->resetAfterTest(); + $DB->insert_record('config_plugins', [ + 'plugin' => 'example', + 'name' => 'test_increment', + 'value' => 0, + ]); + } + + /** + * @coversNothing + * @depends test_increment_reset_part_one + */ + public function test_increment_reset_part_two(): int { + global $DB; + + $this->resetAfterTest(); + return $DB->insert_record('config_plugins', [ + 'plugin' => 'example', + 'name' => 'test_increment', + 'value' => 0, + ]); + } + + /** + * @depends test_increment_reset_part_two + */ + public function test_increment_reset_part_three(int $previousid): void { + global $DB; + + $this->resetAfterTest(); + $id = $DB->insert_record('config_plugins', [ + 'plugin' => 'example', + 'name' => 'test_increment', + 'value' => 0, + ]); + $this->assertEquals($previousid, $id); + } +}