-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathCompactTest.php
More file actions
65 lines (53 loc) · 1.63 KB
/
CompactTest.php
File metadata and controls
65 lines (53 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace qtism\cli;
use cli\Arguments;
use qtism\data\storage\xml\XmlCompactDocument;
use qtism\data\storage\xml\XmlDocument;
use qtism\data\storage\xml\XmlStorageException;
use ReflectionException;
class CompactTest extends Cli
{
protected function run()
{
$arguments = $this->getArguments();
$doc = new XmlDocument();
try {
$doc->load($arguments['input']);
$compactDoc = XmlCompactDocument::createFromXmlAssessmentTestDocument($doc);
$compactDoc->save($arguments['output']);
} catch (XmlStorageException $e) {
$this->fail('Input XML Test document could not be read.');
} catch (ReflectionException $e) {
$this->fail('An unexpected error occurred.');
}
}
protected function setupArguments(): Arguments
{
$arguments = new Arguments(['strict' => false]);
// -- Options
// Session option.
$arguments->addOption(
['input'],
[
'description' => 'The input QTI test file.',
]
);
// XML option.
$arguments->addOption(
['output'],
[
'description' => 'The output QTI compact test file.',
]
);
return $arguments;
}
protected function checkArguments()
{
$arguments = $this->getArguments();
if ($arguments['input'] === null) {
$this->fail('Please provide the --input argument.');
} else if ($arguments['output'] === null) {
$this->fail('Please provide the --output argument.');
}
}
}