1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: aappen |
5
|
|
|
* Date: 01.10.18 |
6
|
|
|
* Time: 14:24 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace seretos\testrail\api; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Projects extends AbstractApi |
13
|
|
|
{ |
14
|
|
|
public const SINGLE_SUITE_MODE = 1; |
15
|
|
|
public const BASELINE_SUITE_MODE = 2; |
16
|
|
|
public const MULTI_SUITE_MODE = 3; |
17
|
|
|
private $cache = null; |
18
|
|
|
|
19
|
|
|
public function all() |
20
|
|
|
{ |
21
|
|
|
if ($this->cache === null) { |
22
|
|
|
$this->cache = $this->connector->send_get('get_projects'); |
23
|
|
|
} |
24
|
|
|
return $this->cache; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function get(int $projectId) |
28
|
|
|
{ |
29
|
|
|
return $this->connector->send_get('get_project/'.$this->encodePath($projectId)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function findByName(string $name) |
33
|
|
|
{ |
34
|
|
|
$allProjects = $this->all(); |
35
|
|
|
foreach ($allProjects as $project) { |
36
|
|
|
if ($project['name'] === $name) { |
37
|
|
|
return $project; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
return []; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function create(string $name, string $announcement = null, bool $show_announcement = false, int $suite_mode = self::MULTI_SUITE_MODE) |
44
|
|
|
{ |
45
|
|
|
$project = $this->connector->send_post('add_project', |
46
|
|
|
['name' => $name, |
47
|
|
|
'announcement' => $announcement, |
48
|
|
|
'show_announcement' => $show_announcement, |
49
|
|
|
'suite_mode' => $suite_mode]); |
50
|
|
|
$this->cache = null; |
51
|
|
|
return $project; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param int $projectId |
56
|
|
|
* @param array $parameters { |
57
|
|
|
* @var string $name |
58
|
|
|
* @var string $announcement |
59
|
|
|
* @var bool $show_announcement |
60
|
|
|
* @var bool $suite_mode |
61
|
|
|
* @var bool $is_completed |
62
|
|
|
* } |
63
|
|
|
*/ |
64
|
|
|
public function update(int $projectId, array $parameters = []) { |
65
|
|
|
$project = $this->connector->send_post('update_project/'.$this->encodePath($projectId), $parameters); |
66
|
|
|
$this->cache = null; |
67
|
|
|
return $project; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function delete(int $projectId) { |
71
|
|
|
$this->connector->send_post('delete_project/'.$this->encodePath($projectId), []); |
72
|
|
|
$this->cache = null; |
73
|
|
|
} |
74
|
|
|
} |