File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ $packageName = 'acme-website/package';
8282$client->customers()->removePackage($customerId, $packageName);
8383```
8484
85+ #### Regenerate a customer's Composer repository token
86+ ``` php
87+ $customerId = 42;
88+ $confirmation = [
89+ 'IConfirmOldTokenWillStopWorkingImmediately' => true,
90+ ];
91+ $composerRepository = $client->customers()->regenerateToken($customerId, $confirmation);
92+ ```
93+ Returns the updated Composer repository.
94+
8595#### Package
8696
8797##### List an organization's packages
Original file line number Diff line number Diff line change @@ -41,4 +41,13 @@ public function removePackage($customerId, $packageName)
4141 {
4242 return $ this ->delete (sprintf ('/customers/%s/packages/%s/ ' , $ customerId , $ packageName ));
4343 }
44+
45+ public function regenerateToken ($ customerId , array $ confirmation )
46+ {
47+ if (!isset ($ confirmation ['IConfirmOldTokenWillStopWorkingImmediately ' ])) {
48+ throw new InvalidArgumentException ('Confirmation is required to regenerate the Composer repository token. ' );
49+ }
50+
51+ return $ this ->post (sprintf ('/customers/%s/token/regenerate ' , $ customerId ), $ confirmation );
52+ }
4453}
Original file line number Diff line number Diff line change @@ -129,6 +129,42 @@ public function testRemovePackage()
129129 $ this ->assertSame ($ expected , $ api ->removePackage (1 , $ packageName ));
130130 }
131131
132+ public function testRegenerateToken ()
133+ {
134+ $ expected = [
135+ 'url ' => 'https://repo.packagist.com/acme-website/ ' ,
136+ 'user ' => 'token ' ,
137+ 'token ' => 'regenerated-token ' ,
138+ 'lastUsed ' => null ,
139+ ];
140+
141+ $ confirmation = [
142+ 'IConfirmOldTokenWillStopWorkingImmediately ' => true ,
143+ ];
144+
145+ /** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
146+ $ api = $ this ->getApiMock ();
147+ $ api ->expects ($ this ->once ())
148+ ->method ('post ' )
149+ ->with ($ this ->equalTo ('/customers/1/token/regenerate ' ), $ this ->equalTo ($ confirmation ))
150+ ->will ($ this ->returnValue ($ expected ));
151+
152+ $ this ->assertSame ($ expected , $ api ->regenerateToken (1 , $ confirmation ));
153+ }
154+
155+ /**
156+ * @expectedException \PrivatePackagist\ApiClient\Exception\InvalidArgumentException
157+ */
158+ public function testRegenerateTokenMissingConfirmation ()
159+ {
160+ /** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
161+ $ api = $ this ->getApiMock ();
162+ $ api ->expects ($ this ->never ())
163+ ->method ('post ' );
164+
165+ $ api ->regenerateToken (1 , []);
166+ }
167+
132168 protected function getApiClass ()
133169 {
134170 return Customers::class;
You can’t perform that action at this time.
0 commit comments