Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
TestPack | |
100.00% |
17 / 17 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getItems | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
JsonSerialize | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoTests\models\pack; |
23 | |
24 | use InvalidArgumentException; |
25 | use JsonSerializable; |
26 | |
27 | /** |
28 | * The Item Pack represents the item package data produced by the compilation. |
29 | * |
30 | * @package taoTests |
31 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
32 | */ |
33 | class TestPack implements JsonSerializable |
34 | { |
35 | /** |
36 | * The item type |
37 | * @var string |
38 | */ |
39 | private $type; |
40 | |
41 | /** |
42 | * The item data as arrays. Can be anything, just be careful of cyclic refs. |
43 | * @var array |
44 | */ |
45 | private $data = []; |
46 | |
47 | /** |
48 | * The test item's data |
49 | * @var array |
50 | */ |
51 | private $items = []; |
52 | |
53 | /** |
54 | * Creates an TestPack with the required data. |
55 | * |
56 | * @param string $type the test type |
57 | * @param array $data the test data |
58 | * @param array $items the test items |
59 | * @throw InvalidArgumentException |
60 | */ |
61 | public function __construct($type, $data, $items) |
62 | { |
63 | if (empty($type)) { |
64 | throw new InvalidArgumentException('Please provide a test type'); |
65 | } |
66 | if (!is_array($data)) { |
67 | throw new InvalidArgumentException('Please provide the test data as an array'); |
68 | } |
69 | if (!is_array($items)) { |
70 | throw new InvalidArgumentException('Please provide the items as an array'); |
71 | } |
72 | $this->type = $type; |
73 | $this->data = $data; |
74 | $this->items = $items; |
75 | } |
76 | |
77 | /** |
78 | * Get the test type |
79 | * @return string the type |
80 | */ |
81 | public function getType() |
82 | { |
83 | return $this->type; |
84 | } |
85 | |
86 | /** |
87 | * Get the test data |
88 | * @return array the data |
89 | */ |
90 | public function getData() |
91 | { |
92 | return $this->data; |
93 | } |
94 | |
95 | /** |
96 | * Get the test's items |
97 | * @return array the items |
98 | */ |
99 | public function getItems() |
100 | { |
101 | return $this->items; |
102 | } |
103 | |
104 | /** |
105 | * How to serialize the pack in JSON. |
106 | * |
107 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
108 | */ |
109 | public function JsonSerialize() |
110 | { |
111 | return [ |
112 | 'type' => $this->type, |
113 | 'data' => $this->data, |
114 | 'items' => $this->items |
115 | ]; |
116 | } |
117 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
118 | } |