An error occurred while loading the file. Please try again.
-
Lückemeyer authored5f2b4ada
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
/**
* entity class for DTA submission plugin result
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
class DtaResult {
/**
* Broadly used in logic, parametrized for easier change.
*/
const COMPONENT_NAME = "assignsubmission_dta";
/**
* Package name of the test.
*/
public $packagename;
/**
* Unit name of the test.
*/
public $classname;
/**
* Name of the test.
*/
public $name;
/**
* State is defined like below
*
* 0 UNKNOWN
* 1 SUCCESS
* 2 FAILURE
* 3 COMPILATIONERROR
*/
public $state;
/**
* Type of test failure if applicable, "" otherwise.
*/
public $failuretype;
/**
* Reason of test failure if applicable, "" otherwise.
*/
public $failurereason;
/**
* Stack trace of test failure if applicable, "" otherwise.
*/
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
public $stacktrace;
/**
* Column number of compile failure if applicable, "" otherwise.
*/
public $columnnumber;
/**
* Line number of compile failure if applicable, "" otherwise.
*/
public $linenumber;
/**
* Position of compile failure if applicable, "" otherwise.
*/
public $position;
/**
* Returns the name of a state with the given number of display.
* @return name of state as defined
*/
public static function getstatename(int $state): string {
if ($state == 1) {
return get_string("tests_successful", self::COMPONENT_NAME);
} else if ($state == 2) {
return get_string("failures", self::COMPONENT_NAME);
} else if ($state == 3) {
return get_string("compilation_errors", self::COMPONENT_NAME);
} else {
return get_string("unknown_state", self::COMPONENT_NAME);
}
}
}
/**
* entity class for DTA submission plugin result
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
class DtaResultSummary {
/**
* Result timestamp for chronological ordering and deletion of previous results.
*/
public $timestamp;
/**
* Global stack trace if applicable, "" otherwise.
*/
public $globalstacktrace;
/**
* Successfully tested competencies according to tests and weights, "" otherwise.
*/
public $successfultestcompetencies;
/**
* Overall tested competencies according to tests and weights, "" otherwise.
*/
public $overalltestcompetencies;
/**
* List of detail results.
*/
public $results;
/**
* Decodes the JSON result summary returned by the backend service call into the plugin PHP data structure.
* @param string $jsonString jsonString containing DtaResultSummary
* @return DtaResultSummary
*/
public static function decodejson($jsonstring): DtaResultSummary {
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
$response = json_decode($jsonstring);
$summary = new DtaResultSummary();
$summary->timestamp = $response->timestamp;
$summary->globalstacktrace = $response->globalstacktrace;
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile;
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile;
$summary->results = self::decodejsonresultarray($response->results);
return $summary;
}
/**
* Decodes the array of JSON detail results returned by the backend service call into the plugin PHP data structure.
* @param array $jsonArray decoded json array of results array
* @return array of DtaResult
*/
private static function decodejsonresultarray($jsonarray): array {
$ret = [];
foreach ($jsonarray as $entry) {
$value = new DtaResult();
$value->packagename = $entry->packageName;
$value->classname = $entry->className;
$value->name = $entry->name;
$value->state = $entry->state;
$value->failuretype = $entry->failureType;
$value->failurereason = $entry->failureReason;
$value->stacktrace = $entry->stacktrace;
$value->columnnumber = $entry->columnNumber;
$value->linenumber = $entry->lineNumber;
$value->position = $entry->position;
$ret[] = $value;
}
return $ret;
}
/**
* Returns the number of detail results attached to the summary.
* @return int count of occurences
*/
public function resultcount(): int {
return count($this->results);
}
/**
* Returns the number of detail results with the given state attached to the summary.
* @param int $state state ordinal number
* @return int count of occurences provided state has
*/
public function stateoccurencecount(int $state): int {
$num = 0;
foreach ($this->results as $r) {
if ($r->state == $state) {
$num++;
}
}
return $num;
}
/**
* Returns the number of detail results with compilation errors attached to the summary.
* @return int count of occurences
*/
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
public function compilationerrorcount(): int {
return $this->stateoccurencecount(3);
}
/**
* Returns the number of detail results with test failures attached to the summary.
* @return int count of occurences
*/
public function failedcount(): int {
return $this->stateoccurencecount(2);
}
/**
* Returns the number of detail results with successful tests attached to the summary.
* @return int count of occurences
*/
public function successfulcount(): int {
return $this->stateoccurencecount(1);
}
/**
* Returns the number of detail results with an unknown result - mostly due to compile errors - attached to the summary.
* @return int count of occurences
*/
public function unknowncount(): int {
return $this->stateoccurencecount(0);
}
}