Skip to content

Commit

Permalink
MDL-37655 phpunit: Avoid having multiple testcase classes in 1 file
Browse files Browse the repository at this point in the history
Note that there wasn't any case of multiple testcase classes in
1 file. All the cases reported in the issue were false positives
caused but other "mock/fixture" files being named _test.

So all this issue does is:

1) rename any _test suffixed class in test files, because we are
   going to start renaming a lot of test classes to _test.

2) ensure that the 2 test case classes modified in this issue,
   are already observing the filename = classname rule that will
   be implemented soon (and verigy it works).
  • Loading branch information
stronk7 committed Mar 30, 2021
1 parent f0eb6a5 commit 870a8de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
20 changes: 10 additions & 10 deletions admin/tool/httpsreplace/tests/httpsreplace_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function test_upgrade_http_links($content, $ouputregex, $expectedcontent)
$this->resetAfterTest();
$this->expectOutputRegex($ouputregex);

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course = $generator->create_course((object) [
Expand Down Expand Up @@ -216,7 +216,7 @@ public function http_link_stats_provider() {
public function test_http_link_stats($content, $domain, $expectedcount) {
$this->resetAfterTest();

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course = $generator->create_course((object) [
Expand All @@ -237,7 +237,7 @@ public function test_links_and_text() {
$this->resetAfterTest();
$this->expectOutputRegex('/^$/');

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course = $generator->create_course((object) [
Expand Down Expand Up @@ -269,7 +269,7 @@ public function test_httpwwwroot() {
$CFG->wwwroot = preg_replace('/^https:/', 'http:', $CFG->wwwroot);
$this->expectOutputRegex('/^$/');

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course = $generator->create_course((object) [
Expand All @@ -292,7 +292,7 @@ public function test_upgrade_http_links_excluded_tables() {

set_config('test_upgrade_http_links', '<img src="http://somesite/someimage.png" />');

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();
ob_start();
$results = $finder->upgrade_http_links();
$output = ob_get_contents();
Expand All @@ -318,7 +318,7 @@ public function test_renames() {

set_config('renames', json_encode($renames), 'tool_httpsreplace');

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course = $generator->create_course((object) [
Expand Down Expand Up @@ -353,7 +353,7 @@ public function test_multiple() {
$original2 .= '<img src="http://example.com/image' . ($i + 15 ) . '.png">';
$expected2 .= '<img src="https://example.com/image' . ($i + 15) . '.png">';
}
$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();

$generator = $this->getDataGenerator();
$course1 = $generator->create_course((object) ['summary' => $original1]);
Expand Down Expand Up @@ -397,7 +397,7 @@ public function test_reserved_words() {
$columnamequoted = $dbman->generator->getEncQuoted('where');
$DB->execute("INSERT INTO {reserved_words_temp} ($columnamequoted) VALUES (?)", [$content]);

$finder = new tool_httpreplace_url_finder_test();
$finder = new tool_httpreplace_url_finder_mock();
$finder->upgrade_http_links();

$record = $DB->get_record('reserved_words_temp', []);
Expand All @@ -408,13 +408,13 @@ public function test_reserved_words() {
}

/**
* Class tool_httpreplace_url_finder_test for testing replace tool without calling curl
* Class tool_httpreplace_url_finder_mock for testing replace tool without calling curl
*
* @package tool_httpsreplace
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_httpreplace_url_finder_test extends \tool_httpsreplace\url_finder {
class tool_httpreplace_url_finder_mock extends \tool_httpsreplace\url_finder {
/**
* Check if url is available (check hardcoded for unittests)
*
Expand Down
20 changes: 10 additions & 10 deletions files/tests/converter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_files_converter_testcase extends advanced_testcase {
class converter_test extends advanced_testcase {

/**
* Get a testable mock of the abstract files_converter class.
Expand Down Expand Up @@ -247,7 +247,7 @@ public function test_get_document_converter_classes_plugin_class_not_found() {
* Test the get_document_converter_classes function when the returned classes do not meet requirements.
*/
public function test_get_document_converter_classes_plugin_class_requirements_not_met() {
$plugin = $this->getMockBuilder(\core_file_converter_requirements_not_met_test::class)
$plugin = $this->getMockBuilder(\core_file_converter_requirements_not_met::class)
->onlyMethods([])
->getMock();

Expand All @@ -266,7 +266,7 @@ public function test_get_document_converter_classes_plugin_class_requirements_no
* Test the get_document_converter_classes function when the returned classes do not meet requirements.
*/
public function test_get_document_converter_classes_plugin_class_met_not_supported() {
$plugin = $this->getMockBuilder(\core_file_converter_type_not_supported_test::class)
$plugin = $this->getMockBuilder(\core_file_converter_type_not_supported::class)
->onlyMethods([])
->getMock();

Expand All @@ -285,7 +285,7 @@ public function test_get_document_converter_classes_plugin_class_met_not_support
* Test the get_document_converter_classes function when the returned classes do not meet requirements.
*/
public function test_get_document_converter_classes_plugin_class_met_and_supported() {
$plugin = $this->getMockBuilder(\core_file_converter_type_supported_test::class)
$plugin = $this->getMockBuilder(\core_file_converter_type_supported::class)
->onlyMethods([])
->getMock();
$classname = get_class($plugin);
Expand Down Expand Up @@ -741,7 +741,7 @@ public function test_get_next_converter_first() {
}
}

class core_file_converter_requirements_test_base implements \core_files\converter_interface {
class core_file_converter_requirements_base implements \core_files\converter_interface {

/**
* Whether the plugin is configured and requirements are met.
Expand Down Expand Up @@ -799,7 +799,7 @@ public function get_supported_conversions() {
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_file_converter_requirements_not_met_test extends core_file_converter_requirements_test_base {
class core_file_converter_requirements_not_met extends core_file_converter_requirements_base {
}

/**
Expand All @@ -809,7 +809,7 @@ class core_file_converter_requirements_not_met_test extends core_file_converter_
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_file_converter_type_not_supported_test extends core_file_converter_requirements_test_base {
class core_file_converter_type_not_supported extends core_file_converter_requirements_base {

/**
* Whether the plugin is configured and requirements are met.
Expand All @@ -828,7 +828,7 @@ public static function are_requirements_met() {
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_file_converter_type_supported_test extends core_file_converter_requirements_test_base {
class core_file_converter_type_supported extends core_file_converter_requirements_base {

/**
* Whether the plugin is configured and requirements are met.
Expand Down Expand Up @@ -858,7 +858,7 @@ public static function supports($from, $to) {
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_file_converter_type_successful extends core_file_converter_requirements_test_base {
class core_file_converter_type_successful extends core_file_converter_requirements_base {

/**
* Convert a document to a new format and return a conversion object relating to the conversion in progress.
Expand Down Expand Up @@ -891,7 +891,7 @@ public static function supports($from, $to) {
* @copyright 2017 Andrew nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_file_converter_type_failed extends core_file_converter_requirements_test_base {
class core_file_converter_type_failed extends core_file_converter_requirements_base {

/**
* Whether the plugin is configured and requirements are met.
Expand Down
8 changes: 4 additions & 4 deletions grade/tests/reportlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* A test class used to test grade_report, the abstract grade report parent class
*/
class grade_report_test extends grade_report {
class grade_report_mock extends grade_report {
public function __construct($courseid, $gpr, $context, $user) {
parent::__construct($courseid, $gpr, $context);
$this->user = $user;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function process_action($target, $action) {
/**
* Tests grade_report, the parent class for all grade reports.
*/
class core_grade_reportlib_testcase extends advanced_testcase {
class reportlib_test extends advanced_testcase {

/**
* Tests grade_report::blank_hidden_total_and_adjust_bounds()
Expand Down Expand Up @@ -117,7 +117,7 @@ public function test_blank_hidden_total_and_adjust_bounds() {
set_coursemodule_visible($datacm->id, 0);

$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
$report = new grade_report_mock($course->id, $gpr, $coursecontext, $student);

// Should return the supplied student total grade regardless of hiding.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
Expand Down Expand Up @@ -193,7 +193,7 @@ public function test_blank_hidden_total_and_adjust_bounds() {
set_coursemodule_visible($forumcm->id, 0);

$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
$report = new grade_report_mock($course->id, $gpr, $coursecontext, $student);

// Should return the supplied student total grade regardless of hiding.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/portfoliolib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @copyright 2014 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_portfoliolib_testcase extends advanced_testcase {
class portfoliolib_test extends advanced_testcase {

public function test_portfolio_rewrite_pluginfile_urls() {
$this->resetAfterTest();
Expand Down Expand Up @@ -78,7 +78,7 @@ public function test_portfolio_rewrite_pluginfile_urls() {
$this->assertSame($input, $output);

// Now use our dummy format.
$format = new core_portfolio_format_dummytest();
$format = new core_portfolio_format_dummy();
$options = null;

// Test that the link is matching.
Expand Down Expand Up @@ -155,7 +155,7 @@ public function test_portfolio_rewrite_pluginfile_urls() {
* @copyright 2014 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_portfolio_format_dummytest extends portfolio_format {
class core_portfolio_format_dummy extends portfolio_format {

public static function file_output($file, $options = null) {
if (isset($options['attributes']) && is_array($options['attributes'])) {
Expand Down

0 comments on commit 870a8de

Please sign in to comment.