Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ExitTest | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
process | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2017-2022 (original work) Open Assessment Technologies SA ; |
19 | */ |
20 | |
21 | namespace oat\taoQtiTest\models\runner\synchronisation\action; |
22 | |
23 | use common_Exception; |
24 | use common_exception_Error; |
25 | use common_exception_InconsistentData; |
26 | use common_Logger; |
27 | use Exception; |
28 | use oat\taoQtiTest\model\Service\ExitTestCommand; |
29 | use oat\taoQtiTest\model\Service\ExitTestService; |
30 | use oat\taoQtiTest\models\runner\synchronisation\TestRunnerAction; |
31 | |
32 | /** |
33 | * Exit the current test abruptly |
34 | * |
35 | * @package oat\taoQtiTest\models\runner\synchronisation\action |
36 | */ |
37 | class ExitTest extends TestRunnerAction |
38 | { |
39 | /** |
40 | * Process the exitTest action. |
41 | * |
42 | * Validate required fields. |
43 | * Stop/Start timer and save item state. |
44 | * Save item response and wrap the move to runner service. |
45 | * Start next timer. |
46 | * |
47 | * @throws common_Exception |
48 | * @throws common_exception_Error |
49 | * @throws common_exception_InconsistentData |
50 | */ |
51 | public function process(): array |
52 | { |
53 | $this->validate(); |
54 | |
55 | try { |
56 | $command = new ExitTestCommand($this->getServiceContext()); |
57 | |
58 | $this->setNavigationContextToCommand($command); |
59 | $this->setItemContextToCommand($command); |
60 | $this->setToolsStateContextToCommand($command); |
61 | |
62 | /** @var ExitTestService $exitTest */ |
63 | $exitTest = $this->getPsrContainer()->get(ExitTestService::class); |
64 | |
65 | $response = $exitTest($command); |
66 | |
67 | return $response->toArray(); |
68 | } catch (Exception $e) { |
69 | common_Logger::e( |
70 | $e->getMessage(), |
71 | ['deliveryExecutionId' => $this->getServiceContext()->getTestExecutionUri()] |
72 | ); |
73 | |
74 | return $this->getErrorResponse($e); |
75 | } |
76 | } |
77 | } |