Skip to content

Commit 40cd184

Browse files
committed
Tokens: throw InvalidArgumentException if both teamId and accessToAllPackages are set
1 parent 42676ff commit 40cd184

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Api/Tokens.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public function all()
2020

2121
public function create(array $tokenData)
2222
{
23+
if (isset($tokenData['teamId'], $tokenData['accessToAllPackages'])) {
24+
throw new InvalidArgumentException('Only set either "accessToAllPackages" or "teamId"');
25+
}
26+
2327
return $this->post('/tokens/', $tokenData);
2428
}
2529

tests/Api/TokensTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ public function testCreate()
6767
]));
6868
}
6969

70+
public function testCreateTeamIdAndAllAccess()
71+
{
72+
$this->expectException(\InvalidArgumentException::class);
73+
/** @var Tokens&MockObject $api */
74+
$api = $this->getApiMock();
75+
$api->expects($this->never())
76+
->method('post');
77+
78+
$api->create([
79+
'description' => 'Team Token',
80+
'access' => 'read',
81+
'teamId' => 1,
82+
'accessToAllPackages' => true,
83+
]);
84+
}
85+
7086
public function testRemove()
7187
{
7288
$expected = [];

0 commit comments

Comments
 (0)