Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SkipService
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
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
23declare(strict_types=1);
24
25namespace oat\taoQtiTest\model\Service;
26
27use oat\taoQtiTest\model\Domain\Model\ItemResponseRepositoryInterface;
28use oat\taoQtiTest\model\Domain\Model\ToolsStateRepositoryInterface;
29use oat\taoQtiTest\models\runner\PersistableRunnerServiceInterface;
30use oat\taoQtiTest\models\runner\RunnerService;
31
32class SkipService
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(SkipCommand $command): ActionResponse
54    {
55        $serviceContext = $command->getServiceContext();
56
57        $this->runnerService->check($serviceContext);
58        $serviceContext->init();
59
60        $this->itemResponseRepository->save($command->getItemResponse(), $serviceContext);
61        $this->toolsStateRepository->save($command->getToolsState(), $serviceContext);
62
63        $result = $this->runnerService->skip(
64            $serviceContext,
65            $command->getScope(),
66            $command->getRef()
67        );
68
69        if ($command->hasStartTimer()) {
70            $this->runnerService->startTimer($serviceContext, $command->getTimestamp());
71        }
72
73        if ($this->runnerService instanceof PersistableRunnerServiceInterface) {
74            $this->runnerService->persist($serviceContext);
75        }
76
77        if ($result === false) {
78            return ActionResponse::empty();
79        }
80
81        $testMap = $serviceContext->containsAdaptive()
82            ? $this->runnerService->getTestMap($serviceContext, true)
83            : null;
84
85        return ActionResponse::success(
86            $this->runnerService->getTestContext($serviceContext),
87            $testMap
88        );
89    }
90}