1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: aappen |
5
|
|
|
* Date: 01.10.18 |
6
|
|
|
* Time: 17:59 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace seretos\testrail\api; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Cases extends AbstractApi |
13
|
|
|
{ |
14
|
|
|
public function all(int $projectId, int $suiteId, int $sectionId = null) |
15
|
|
|
{ |
16
|
|
|
return $this->connector->send_get('get_cases/'.$this->encodePath($projectId).'&suite_id='.$this->encodePath($suiteId).'§ion_id='.$this->encodePath($sectionId)); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function findBySection(int $projectId, int $suiteId, int $sectionId = null) { |
20
|
|
|
$cases = $this->all($projectId, $suiteId, $sectionId); |
21
|
|
|
$resultCases = []; |
22
|
|
|
foreach ($cases as $case) { |
23
|
|
|
if ($case['section_id'] === $sectionId) { |
24
|
|
|
$resultCases[] = $case; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
return $resultCases; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function get(int $caseId) |
31
|
|
|
{ |
32
|
|
|
return $this->connector->send_get('get_case/'.$this->encodePath($caseId)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function findByField(int $projectId, int $suiteId, string $field, string $value, int $sectionId = null) { |
36
|
|
|
$allCases = $this->all($projectId, $suiteId, $sectionId); |
37
|
|
|
foreach ($allCases as $case) { |
38
|
|
|
if ($case[$field] === $value) { |
39
|
|
|
return $case; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
return []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param int $sectionId |
47
|
|
|
* @param string $title |
48
|
|
|
* @param int $templateId |
49
|
|
|
* @param int $typeId |
50
|
|
|
* @param array $customFields |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function create(int $sectionId, string $title, int $templateId, int $typeId, array $customFields = []) |
54
|
|
|
{ |
55
|
|
|
$params = $customFields; |
56
|
|
|
$params['title'] = $title; |
57
|
|
|
$params['template_id'] = $templateId; |
58
|
|
|
$params['type_id'] = $typeId; |
59
|
|
|
$case = $this->connector->send_post('add_case/'.$this->encodePath($sectionId), $params); |
60
|
|
|
return $case; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param int $caseId |
65
|
|
|
* @param array $parameters { |
66
|
|
|
* @var string $title |
67
|
|
|
* @var int $template_id |
68
|
|
|
* @var int $type_id |
69
|
|
|
* } |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function update(int $caseId, array $parameters = []) { |
73
|
|
|
$case = $this->connector->send_post('update_case/'.$this->encodePath($caseId), $parameters); |
74
|
|
|
return $case; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function delete(int $caseId) { |
78
|
|
|
$this->connector->send_post('delete_case/'.$this->encodePath($caseId), []); |
79
|
|
|
} |
80
|
|
|
} |