Skip to content

Commit e6a4997

Browse files
Mitchell Davisacrobat
Mitchell Davis
authored andcommitted
Change DeployKeys::update method to match GitHub API (KnpLabs#797)
* Change DeployKeys::update method to first remove the existing key and then create a new one, in accordance with the supported GitHub APIs * Change DeployKeys::update method to first remove the existing key and then create a new one, in accordance with the supported GitHub APIs * Convert tabs to spaces
1 parent 275ce09 commit e6a4997

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/Github/Api/Repository/DeployKeys.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public function update($username, $repository, $id, array $params)
3737
throw new MissingArgumentException(['title', 'key']);
3838
}
3939

40-
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params);
40+
$this->remove($username, $repository, $id);
41+
42+
return $this->create($username, $repository, $params);
4143
}
4244

4345
public function remove($username, $repository, $id)

test/Github/Tests/Api/Repository/DeployKeysTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public function shouldNotUpdateDeployKeyWithoutTitle()
111111

112112
$api = $this->getApiMock();
113113
$api->expects($this->never())
114-
->method('patch');
114+
->method('delete');
115+
$api->expects($this->never())
116+
->method('post');
115117

116118
$api->update('KnpLabs', 'php-github-api', 123, $data);
117119
}
@@ -126,7 +128,9 @@ public function shouldNotUpdateDeployKeyWithoutKey()
126128

127129
$api = $this->getApiMock();
128130
$api->expects($this->never())
129-
->method('patch');
131+
->method('delete');
132+
$api->expects($this->never())
133+
->method('post');
130134

131135
$api->update('KnpLabs', 'php-github-api', 123, $data);
132136
}
@@ -141,8 +145,12 @@ public function shouldUpdateDeployKey()
141145

142146
$api = $this->getApiMock();
143147
$api->expects($this->once())
144-
->method('patch')
145-
->with('/repos/KnpLabs/php-github-api/keys/123', $data)
148+
->method('delete')
149+
->with('/repos/KnpLabs/php-github-api/keys/123')
150+
->will($this->returnValue($expectedValue));
151+
$api->expects($this->once())
152+
->method('post')
153+
->with('/repos/KnpLabs/php-github-api/keys', $data)
146154
->will($this->returnValue($expectedValue));
147155

148156
$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data));

0 commit comments

Comments
 (0)