Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
TimeoutService | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
5 |
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) 2021 (original work) Open Assessment Technologies SA; |
19 | * |
20 | * @author Ricardo Quintanilha <ricardo.quintanilha@taotesting.com> |
21 | */ |
22 | |
23 | declare(strict_types=1); |
24 | |
25 | namespace oat\taoQtiTest\model\Service; |
26 | |
27 | use oat\taoQtiTest\model\Domain\Model\ItemResponseRepositoryInterface; |
28 | use oat\taoQtiTest\model\Domain\Model\ToolsStateRepositoryInterface; |
29 | use oat\taoQtiTest\models\runner\PersistableRunnerServiceInterface; |
30 | use oat\taoQtiTest\models\runner\RunnerService; |
31 | |
32 | class TimeoutService |
33 | { |
34 | /** @var RunnerService */ |
35 | private $runnerService; |
36 | |
37 | /** @var ItemResponseRepositoryInterface */ |
38 | private $itemResponseRepository; |
39 | |
40 | /** @var ToolsStateRepositoryInterface */ |
41 | private $toolsStateRepository; |
42 | |
43 | public function __construct( |
44 | RunnerService $runnerService, |
45 | ItemResponseRepositoryInterface $itemResponseRepository, |
46 | ToolsStateRepositoryInterface $toolsStateRepository |
47 | ) { |
48 | $this->runnerService = $runnerService; |
49 | $this->itemResponseRepository = $itemResponseRepository; |
50 | $this->toolsStateRepository = $toolsStateRepository; |
51 | } |
52 | |
53 | public function __invoke(TimeoutCommand $command): ActionResponse |
54 | { |
55 | $serviceContext = $command->getServiceContext(); |
56 | |
57 | $this->itemResponseRepository->save($command->getItemResponse(), $serviceContext); |
58 | $this->toolsStateRepository->save($command->getToolsState(), $serviceContext); |
59 | |
60 | $this->runnerService->check($serviceContext); |
61 | $serviceContext->init(); |
62 | |
63 | $result = $this->runnerService->timeout( |
64 | $serviceContext, |
65 | $command->getScope(), |
66 | $command->getRef(), |
67 | $command->isLateSubmissionAllowed() |
68 | ); |
69 | |
70 | if ($command->hasStartTimer()) { |
71 | $this->runnerService->startTimer($serviceContext, $command->getTimestamp()); |
72 | } |
73 | |
74 | if ($this->runnerService instanceof PersistableRunnerServiceInterface) { |
75 | $this->runnerService->persist($serviceContext); |
76 | } |
77 | |
78 | if ($result === false) { |
79 | return ActionResponse::empty(); |
80 | } |
81 | |
82 | $testMap = $serviceContext->containsAdaptive() |
83 | ? $this->runnerService->getTestMap($serviceContext, true) |
84 | : null; |
85 | |
86 | return ActionResponse::success( |
87 | $this->runnerService->getTestContext($serviceContext), |
88 | $testMap |
89 | ); |
90 | } |
91 | } |