Skip to content

Commit 899e88d

Browse files
ijaureguialzom1guelpf
authored andcommitted
Allow setting path and name when forking a Project
1 parent c58271a commit 899e88d

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,15 @@ public function languages($project_id)
629629
* @param array $params (
630630
*
631631
* @var string $namespace The ID or path of the namespace that the project will be forked to
632+
* @var string $path The path of the forked project (optional)
633+
* @var string $name The name of the forked project (optional)
632634
* )
633635
* @return mixed
634636
*/
635637
public function fork($project_id, array $parameters = [])
636638
{
637639
$resolver = new OptionsResolver();
638-
$resolver->setDefined('namespace');
640+
$resolver->setDefined(['namespace', 'path', 'name']);
639641

640642
$resolved = $resolver->resolve($parameters);
641643

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,72 @@ public function shouldGetLanguages()
12311231
$this->assertEquals($expectedArray, $api->languages(1));
12321232
}
12331233

1234+
/**
1235+
* @test
1236+
*/
1237+
public function shouldForkWithNamespace()
1238+
{
1239+
$expectedArray = [
1240+
'namespace' => 'new_namespace',
1241+
];
1242+
1243+
$api = $this->getApiMock();
1244+
$api->expects($this->once())
1245+
->method('post')
1246+
->with('projects/1/fork', $expectedArray)
1247+
->will($this->returnValue($expectedArray));
1248+
1249+
$this->assertEquals($expectedArray, $api->fork(1, [
1250+
'namespace' => 'new_namespace',
1251+
]));
1252+
}
1253+
1254+
/**
1255+
* @test
1256+
*/
1257+
public function shouldForkWithNamespaceAndPath()
1258+
{
1259+
$expectedArray = [
1260+
'namespace' => 'new_namespace',
1261+
'path' => 'new_path',
1262+
];
1263+
1264+
$api = $this->getApiMock();
1265+
$api->expects($this->once())
1266+
->method('post')
1267+
->with('projects/1/fork', $expectedArray)
1268+
->will($this->returnValue($expectedArray));
1269+
1270+
$this->assertEquals($expectedArray, $api->fork(1, [
1271+
'namespace' => 'new_namespace',
1272+
'path' => 'new_path',
1273+
]));
1274+
}
1275+
1276+
/**
1277+
* @test
1278+
*/
1279+
public function shouldForkWithNamespaceAndPathAndName()
1280+
{
1281+
$expectedArray = [
1282+
'namespace' => 'new_namespace',
1283+
'path' => 'new_path',
1284+
'name' => 'new_name'
1285+
];
1286+
1287+
$api = $this->getApiMock();
1288+
$api->expects($this->once())
1289+
->method('post')
1290+
->with('projects/1/fork', $expectedArray)
1291+
->will($this->returnValue($expectedArray));
1292+
1293+
$this->assertEquals($expectedArray, $api->fork(1, [
1294+
'namespace' => 'new_namespace',
1295+
'path' => 'new_path',
1296+
'name' => 'new_name'
1297+
]));
1298+
}
1299+
12341300
/**
12351301
* @test
12361302
*/

0 commit comments

Comments
 (0)