MDL-51756 tests: Refactor test to use data-provider
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 15 Oct 2015 06:40:49 +0000 (14:40 +0800)
committerDamyon Wiese <damyon@moodle.com>
Thu, 15 Oct 2015 07:17:02 +0000 (15:17 +0800)
The benefit is that this becomes one test per external function instead of one
test testing them all - so more information is shown on failure and we get lots
more dots (we love dots!).

lib/tests/externallib_test.php

index 63d7b51..f67a120 100644 (file)
@@ -265,23 +265,32 @@ class core_externallib_testcase extends advanced_testcase {
         test_exernal_api::get_context_wrapper(array('roleid' => 3, 'userid' => $USER->id, 'instanceid' => $course->id));
     }
 
-    public function test_all_external_info() {
+    public function all_external_info_provider() {
         global $DB;
 
-        $functions = $DB->get_records('external_functions', array(), 'name');
         // We are testing here that all the external function descriptions can be generated without
         // producing warnings. E.g. misusing optional params will generate a debugging message which
         // will fail this test.
+        $functions = $DB->get_records('external_functions', array(), 'name');
+        $return = array();
         foreach ($functions as $f) {
-            $desc = external_function_info($f);
-            $this->assertNotEmpty($desc->name);
-            $this->assertNotEmpty($desc->classname);
-            $this->assertNotEmpty($desc->methodname);
-            $this->assertEquals($desc->component, clean_param($desc->component, PARAM_COMPONENT));
-            $this->assertInstanceOf('external_function_parameters', $desc->parameters_desc);
-            if ($desc->returns_desc != null) {
-                $this->assertInstanceOf('external_description', $desc->returns_desc);
-            }
+            $return[$f->name] = array($f);
+        }
+        return $return;
+    }
+
+    /**
+     * @dataProvider all_external_info_provider
+     */
+    public function test_all_external_info($f) {
+        $desc = external_function_info($f);
+        $this->assertNotEmpty($desc->name);
+        $this->assertNotEmpty($desc->classname);
+        $this->assertNotEmpty($desc->methodname);
+        $this->assertEquals($desc->component, clean_param($desc->component, PARAM_COMPONENT));
+        $this->assertInstanceOf('external_function_parameters', $desc->parameters_desc);
+        if ($desc->returns_desc != null) {
+            $this->assertInstanceOf('external_description', $desc->returns_desc);
         }
     }
 }