From 6b6e7eaad2d431896949940ae13ce4370c4ebb17 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 6 Mar 2023 13:39:52 +0000 Subject: [PATCH] MDL-69882 phpunit: final removal of deprecated 310 helper methods. --- lib/phpunit/classes/advanced_testcase.php | 49 +++------------ lib/phpunit/tests/advanced_test.php | 72 ----------------------- lib/upgrade.txt | 5 ++ 3 files changed, 13 insertions(+), 113 deletions(-) diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 991e63796ac..b2b81728016 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -147,64 +147,31 @@ abstract class advanced_testcase extends base_testcase { } /** - * Creates a new XMLDataSet with the given $xmlFile. (absolute path.) - * * @deprecated since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info. - * @todo This will be removed for Moodle 4.2 as part of MDL-69882. - * - * @param string $xmlFile - * @return phpunit_dataset */ - protected function createXMLDataSet($xmlFile) { - debugging(__FUNCTION__ . '() is deprecated. Please use dataset_from_files() instead.', DEBUG_DEVELOPER); - return $this->dataset_from_files([$xmlFile]); + protected function createXMLDataSet() { + throw new coding_exception(__FUNCTION__ . '() is deprecated. Please use dataset_from_files() instead.'); } /** - * Creates a new CsvDataSet from the given array of csv files. (absolute paths.) - * * @deprecated since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info. - * @todo This will be removed for Moodle 4.2 as part of MDL-69882. - * - * @param array $files array tablename=>cvsfile - * @param string $delimiter unused - * @param string $enclosure unused - * @param string $escape unused - * @return phpunit_dataset */ - protected function createCsvDataSet($files, $delimiter = ',', $enclosure = '"', $escape = '"') { - debugging(__FUNCTION__ . '() is deprecated. Please use dataset_from_files() instead.', DEBUG_DEVELOPER); - return $this->dataset_from_files($files); + protected function createCsvDataSet() { + throw new coding_exception(__FUNCTION__ . '() is deprecated. Please use dataset_from_files() instead.'); } /** - * Creates new ArrayDataSet from given array - * * @deprecated since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info. - * @todo This will be removed for Moodle 4.2 as part of MDL-69882. - * - * @param array $data array of tables, first row in each table is columns - * @return phpunit_dataset */ - protected function createArrayDataSet(array $data) { - debugging(__FUNCTION__ . '() is deprecated. Please use dataset_from_array() instead.', DEBUG_DEVELOPER); - return $this->dataset_from_array($data); + protected function createArrayDataSet() { + throw new coding_exception(__FUNCTION__ . '() is deprecated. Please use dataset_from_array() instead.'); } /** - * Load date into moodle database tables from standard PHPUnit data set. - * * @deprecated since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info. - * @todo This will be removed for Moodle 4.2 as part of MDL-69882. - * - * Note: it is usually better to use data generators - * - * @param phpunit_dataset $dataset - * @return void */ - protected function loadDataSet(phpunit_dataset $dataset) { - debugging(__FUNCTION__ . '() is deprecated. Please use dataset->to_database() instead.', DEBUG_DEVELOPER); - $dataset->to_database(); + protected function loadDataSet() { + throw new coding_exception(__FUNCTION__ . '() is deprecated. Please use dataset->to_database() instead.'); } /** diff --git a/lib/phpunit/tests/advanced_test.php b/lib/phpunit/tests/advanced_test.php index 8ee2388c63f..62d6750795e 100644 --- a/lib/phpunit/tests/advanced_test.php +++ b/lib/phpunit/tests/advanced_test.php @@ -308,78 +308,6 @@ class advanced_test extends \advanced_testcase { $this->assertFalse($DB->get_record('user', array('id'=>9999))); } - public function test_load_data_dataset_xml() { - global $DB; - - $this->resetAfterTest(); - - $this->assertFalse($DB->record_exists('user', array('id' => 5))); - $this->assertFalse($DB->record_exists('user', array('id' => 7))); - $dataset = $this->createXMLDataSet(__DIR__.'/fixtures/sample_dataset.xml'); - $this->assertDebuggingCalled('createXMLDataSet() is deprecated. Please use dataset_from_files() instead.'); - $this->loadDataSet($dataset); - $this->assertDebuggingCalled('loadDataSet() is deprecated. Please use dataset->to_database() instead.'); - $this->assertTrue($DB->record_exists('user', array('id' => 5))); - $this->assertTrue($DB->record_exists('user', array('id' => 7))); - $user5 = $DB->get_record('user', array('id' => 5)); - $user7 = $DB->get_record('user', array('id' => 7)); - $this->assertSame('bozka.novakova', $user5->username); - $this->assertSame('pepa.novak', $user7->username); - - } - - public function test_load_dataset_csv() { - global $DB; - - $this->resetAfterTest(); - - $this->assertFalse($DB->record_exists('user', array('id' => 8))); - $this->assertFalse($DB->record_exists('user', array('id' => 9))); - $dataset = $this->createCsvDataSet(array('user' => __DIR__.'/fixtures/sample_dataset.csv')); - $this->assertDebuggingCalled('createCsvDataSet() is deprecated. Please use dataset_from_files() instead.'); - $this->loadDataSet($dataset); - $this->assertDebuggingCalled('loadDataSet() is deprecated. Please use dataset->to_database() instead.'); - $this->assertEquals(5, $DB->get_field('user', 'id', array('username' => 'bozka.novakova'))); - $this->assertEquals(7, $DB->get_field('user', 'id', array('username' => 'pepa.novak'))); - - } - - public function test_load_dataset_array() { - global $DB; - - $this->resetAfterTest(); - - $data = array( - 'user' => array( - array('username', 'email'), - array('top.secret', 'top@example.com'), - array('low.secret', 'low@example.com'), - ), - ); - - $this->assertFalse($DB->record_exists('user', array('email' => 'top@example.com'))); - $this->assertFalse($DB->record_exists('user', array('email' => 'low@example.com'))); - $dataset = $this->createArrayDataSet($data); - $this->assertDebuggingCalled('createArrayDataSet() is deprecated. Please use dataset_from_array() instead.'); - $this->loadDataSet($dataset); - $this->assertDebuggingCalled('loadDataSet() is deprecated. Please use dataset->to_database() instead.'); - $this->assertTrue($DB->record_exists('user', array('email' => 'top@example.com'))); - $this->assertTrue($DB->record_exists('user', array('email' => 'low@example.com'))); - - $data = array( - 'user' => array( - array('username' => 'noidea', 'email' => 'noidea@example.com'), - array('username' => 'onemore', 'email' => 'onemore@example.com'), - ), - ); - $dataset = $this->createArrayDataSet($data); - $this->assertDebuggingCalled('createArrayDataSet() is deprecated. Please use dataset_from_array() instead.'); - $this->loadDataSet($dataset); - $this->assertDebuggingCalled('loadDataSet() is deprecated. Please use dataset->to_database() instead.'); - $this->assertTrue($DB->record_exists('user', array('username' => 'noidea'))); - $this->assertTrue($DB->record_exists('user', array('username' => 'onemore'))); - } - public function test_assert_time_current() { $this->assertTimeCurrent(time()); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 5d85b1306e4..3dfe742f711 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -79,6 +79,11 @@ information provided here is intended especially for developers. Course formats using components will be allowed to use one level indentation only. * The method `flexible_table::set_columnsattributes` now can be used with 'class' key to add custom classes to the DOM. * The editor_tinymce plugin has been removed from core. +* The following phpunit advanced testcase helper methods, deprecated since 3.10, have been removed and can no longer be used: + - `createXMLDataSet` + - `createCsvDataSet` + - `createArrayDataSet` + - `loadDataSet` === 4.1 ===