Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 55... Línea 55...
55
 
55
 
56
    /**
56
    /**
57
     * Runs the bare test sequence.
57
     * Runs the bare test sequence.
58
     */
58
     */
59
    final public function runBare(): void {
59
    final public function runBare(): void {
Línea 60... Línea 60...
60
        global $DB;
60
        global $CFG, $DB;
61
 
61
 
62
        if (phpunit_util::$lastdbwrites != $DB->perf_get_writes()) {
62
        if (phpunit_util::$lastdbwrites != $DB->perf_get_writes()) {
63
            // This happens when previous test does not reset, we can not use transactions.
63
            // This happens when previous test does not reset, we can not use transactions.
Línea 68... Línea 68...
68
        }
68
        }
Línea 69... Línea 69...
69
 
69
 
70
        try {
70
        try {
71
            $this->setCurrentTimeStart();
71
            $this->setCurrentTimeStart();
72
            parent::runBare();
-
 
73
            // Set DB reference in case somebody mocked it in test.
-
 
74
            $DB = phpunit_util::get_global_backup('DB');
-
 
75
 
-
 
76
            // Deal with any debugging messages.
-
 
77
            $debugerror = phpunit_util::display_debugging_messages(true);
-
 
78
            $this->resetDebugging();
-
 
79
            if (!empty($debugerror)) {
-
 
80
                trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
-
 
81
            }
72
            parent::runBare();
82
        } catch (Exception $ex) {
73
        } catch (Exception $ex) {
83
            $e = $ex;
74
            $e = $ex;
84
        } catch (Throwable $ex) {
75
        } catch (Throwable $ex) {
85
            // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
76
            // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
-
 
77
            $e = $ex;
-
 
78
        } finally {
-
 
79
            // Reset global state after test and test failure.
-
 
80
            $CFG = phpunit_util::get_global_backup('CFG');
-
 
81
            $DB = phpunit_util::get_global_backup('DB');
-
 
82
 
-
 
83
            // We need to reset the autoloader.
86
            $e = $ex;
84
            \core_component::reset();
Línea 87... Línea 85...
87
        }
85
        }
88
 
86
 
89
        if (isset($e)) {
87
        if (isset($e)) {
90
            // Cleanup after failed expectation.
88
            // Cleanup after failed expectation.
91
            self::resetAllData();
89
            self::resetAllData();
Línea -... Línea 90...
-
 
90
            throw $e;
-
 
91
        }
-
 
92
 
-
 
93
        // Deal with any debugging messages.
-
 
94
        $debugerror = phpunit_util::display_debugging_messages(true);
-
 
95
        $this->resetDebugging();
-
 
96
        if (!empty($debugerror)) {
92
            throw $e;
97
            trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
93
        }
98
        }
94
 
99
 
Línea 95... Línea 100...
95
        if (!$this->testdbtransaction || $this->testdbtransaction->is_disposed()) {
100
        if (!$this->testdbtransaction || $this->testdbtransaction->is_disposed()) {
Línea 822... Línea 827...
822
 
827
 
823
        $plugins[$plugintype][$pluginname] = $path;
828
        $plugins[$plugintype][$pluginname] = $path;
824
        $mockedcomponent->setStaticPropertyValue('plugins', $plugins);
829
        $mockedcomponent->setStaticPropertyValue('plugins', $plugins);
825
        $this->resetDebugging();
830
        $this->resetDebugging();
-
 
831
    }
-
 
832
 
-
 
833
    /**
-
 
834
     * Convenience method to load a fixture from a component's fixture directory.
-
 
835
     *
-
 
836
     * @param string $component
-
 
837
     * @param string $path
-
 
838
     * @throws coding_exception
-
 
839
     */
-
 
840
    protected static function load_fixture(
-
 
841
        string $component,
-
 
842
        string $path,
-
 
843
    ): void {
-
 
844
        $fullpath = sprintf(
-
 
845
            "%s/tests/fixtures/%s",
-
 
846
            \core_component::get_component_directory($component),
-
 
847
            $path,
-
 
848
        );
-
 
849
        if (!file_exists($fullpath)) {
-
 
850
            throw new \coding_exception("Fixture file not found: $fullpath");
-
 
851
        }
-
 
852
 
-
 
853
        global $ADMIN;
-
 
854
        global $CFG;
-
 
855
        global $DB;
-
 
856
        global $SITE;
-
 
857
        global $USER;
-
 
858
        global $OUTPUT;
-
 
859
        global $PAGE;
-
 
860
        global $SESSION;
-
 
861
        global $COURSE;
-
 
862
        global $SITE;
-
 
863
 
-
 
864
        require_once($fullpath);
826
    }
865
    }