|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: aappen |
|
5
|
|
|
* Date: 04.10.18 |
|
6
|
|
|
* Time: 11:27 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace seretos\testrail\api; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class Plans extends AbstractApi |
|
13
|
|
|
{ |
|
14
|
|
|
private $cache = []; |
|
15
|
|
|
public function all(int $projectId) |
|
16
|
|
|
{ |
|
17
|
|
|
if (!isset($this->cache[$projectId])) { |
|
18
|
|
|
$this->cache[$projectId] = $this->connector->send_get('get_plans/'.$this->encodePath($projectId)); |
|
19
|
|
|
} |
|
20
|
|
|
return $this->cache[$projectId]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function get(int $planId) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->connector->send_get('get_plan/'.$this->encodePath($planId)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function findByName(int $projectId, string $name) |
|
29
|
|
|
{ |
|
30
|
|
|
$allPlans = $this->all($projectId); |
|
31
|
|
|
foreach ($allPlans as $plan) { |
|
32
|
|
|
if ($plan['name'] === $name) { |
|
33
|
|
|
return $plan; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
return []; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function create(int $projectId, string $name, string $description = null, int $milestoneId = null) |
|
40
|
|
|
{ |
|
41
|
|
|
$plan = $this->connector->send_post('add_plan/'.$this->encodePath($projectId), |
|
42
|
|
|
['name' => $name, |
|
43
|
|
|
'description' => $description, |
|
44
|
|
|
'milestone_id' => $milestoneId]); |
|
45
|
|
|
unset($this->cache[$projectId]); |
|
46
|
|
|
return $plan; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function createEntry(int $planId, int $suiteId, string $name, array $configIds = [], array $runs = [], string $description = null, bool $all = true, array $cases = [], int $assignedTo = null) { |
|
50
|
|
|
$entry = $this->connector->send_post('add_plan_entry/'.$this->encodePath($planId), |
|
51
|
|
|
['suite_id' => $suiteId, 'name' => $name, 'description' => $description, 'include_all' => $all, 'case_ids' => $cases, 'config_ids' => $configIds, 'runs' => $runs, 'assignedto_id' => $assignedTo]); |
|
52
|
|
|
$this->cache = []; |
|
53
|
|
|
return $entry; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param int $planId |
|
58
|
|
|
* @param array $parameters { |
|
59
|
|
|
* @var string $name |
|
60
|
|
|
* @var string $description |
|
61
|
|
|
* @var int $milestone_id |
|
62
|
|
|
* } |
|
63
|
|
|
*/ |
|
64
|
|
|
public function update(int $planId, array $parameters = []) { |
|
65
|
|
|
$plan = $this->connector->send_post('update_plan/'.$this->encodePath($planId), $parameters); |
|
66
|
|
|
$this->cache = []; |
|
67
|
|
|
return $plan; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function updateEntry(int $planId, int $entryId, array $parameters = []) { |
|
71
|
|
|
$entry = $this->connector->send_post('update_plan_entry/'.$this->encodePath($planId).'/'.$this->encodePath($entryId), $parameters); |
|
72
|
|
|
$this->cache = []; |
|
73
|
|
|
return $entry; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function delete(int $planId) { |
|
77
|
|
|
$this->connector->send_post('delete_plan/'.$this->encodePath($planId), []); |
|
78
|
|
|
$this->cache = []; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function deleteEntry(int $planId, int $entryId) { |
|
82
|
|
|
$this->connector->send_post('delete_plan_entry/'.$this->encodePath($planId).'/'.$this->encodePath($entryId), []); |
|
83
|
|
|
$this->cache = []; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function close(int $planId) { |
|
87
|
|
|
$plan = $this->connector->send_post('close_plan/'.$this->encodePath($planId), []); |
|
88
|
|
|
$this->cache = []; |
|
89
|
|
|
return $plan; |
|
90
|
|
|
} |
|
91
|
|
|
} |