Reorder methods

This commit is contained in:
ErickSkrauch 2019-04-07 22:46:30 +02:00
parent 36cab232b6
commit c9eed8e290
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
2 changed files with 57 additions and 57 deletions

View File

@ -177,6 +177,35 @@ class Api {
return $result; return $result;
} }
/**
* @param string $accessToken
* @param string $accountUuid
* @param \Psr\Http\Message\StreamInterface|resource|string $skinContents
* @param bool $isSlim
*
* @throws GuzzleException
*
* @url https://wiki.vg/Mojang_API#Upload_Skin
*/
public function uploadSkin(string $accessToken, string $accountUuid, $skinContents, bool $isSlim): void {
$this->getClient()->request('PUT', "https://api.mojang.com/user/profile/{$accountUuid}/skin", [
'multipart' => [
[
'name' => 'file',
'contents' => $skinContents,
'filename' => 'char.png',
],
[
'name' => 'model',
'contents' => $isSlim ? 'slim' : '',
],
],
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
],
]);
}
/** /**
* @param string $login * @param string $login
* @param string $password * @param string $password
@ -247,35 +276,6 @@ class Api {
return false; return false;
} }
/**
* @param string $accessToken
* @param string $accountUuid
* @param \Psr\Http\Message\StreamInterface|resource|string $skinContents
* @param bool $isSlim
*
* @throws GuzzleException
*
* @url https://wiki.vg/Mojang_API#Upload_Skin
*/
public function uploadSkin(string $accessToken, string $accountUuid, $skinContents, bool $isSlim): void {
$this->getClient()->request('PUT', "https://api.mojang.com/user/profile/{$accountUuid}/skin", [
'multipart' => [
[
'name' => 'file',
'contents' => $skinContents,
'filename' => 'char.png',
],
[
'name' => 'model',
'contents' => $isSlim ? 'slim' : '',
],
],
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
],
]);
}
/** /**
* @param string $accessToken * @param string $accessToken
* @param string $accountUuid * @param string $accountUuid

View File

@ -231,17 +231,6 @@ class ApiTest extends TestCase {
$this->assertTrue($result['mockusername']->isDemo()); $this->assertTrue($result['mockusername']->isDemo());
} }
public function testPlayernamesToUuidsInvalidArgumentException() {
$names = [];
for ($i = 0; $i < 101; $i++) {
$names[] = base64_encode(random_bytes(4));
}
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You cannot request more than 100 names per request');
$this->api->playernamesToUuids($names);
}
public function testUsernameToTextures() { public function testUsernameToTextures() {
$this->mockHandler->append($this->createResponse(200, [ $this->mockHandler->append($this->createResponse(200, [
'id' => '86f6e3695b764412a29820cac1d4d0d6', 'id' => '86f6e3695b764412a29820cac1d4d0d6',
@ -262,6 +251,34 @@ class ApiTest extends TestCase {
$this->assertStringStartsWith('https://sessionserver.mojang.com/session/minecraft/profile/86f6e3695b764412a29820cac1d4d0d6', (string)$request2->getUri()); $this->assertStringStartsWith('https://sessionserver.mojang.com/session/minecraft/profile/86f6e3695b764412a29820cac1d4d0d6', (string)$request2->getUri());
} }
public function testUploadSkinNotSlim() {
$this->mockHandler->append(new Response(200));
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
/** @var \Psr\Http\Message\RequestInterface $request */
$request = $this->history[0]['request'];
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
}
public function testUploadSkinSlim() {
$this->mockHandler->append(new Response(200));
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
/** @var \Psr\Http\Message\RequestInterface $request */
$request = $this->history[0]['request'];
$this->assertStringContainsString('slim', $request->getBody()->getContents());
}
public function testPlayernamesToUuidsInvalidArgumentException() {
$names = [];
for ($i = 0; $i < 101; $i++) {
$names[] = base64_encode(random_bytes(4));
}
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You cannot request more than 100 names per request');
$this->api->playernamesToUuids($names);
}
public function testAuthenticate() { public function testAuthenticate() {
$this->mockHandler->append($this->createResponse(200, [ $this->mockHandler->append($this->createResponse(200, [
'accessToken' => 'access token value', 'accessToken' => 'access token value',
@ -355,23 +372,6 @@ class ApiTest extends TestCase {
$this->assertFalse($this->api->validate('mocked access token')); $this->assertFalse($this->api->validate('mocked access token'));
} }
public function testUploadSkinNotSlim() {
$this->mockHandler->append(new Response(200));
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
/** @var \Psr\Http\Message\RequestInterface $request */
$request = $this->history[0]['request'];
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
}
public function testUploadSkinSlim() {
$this->mockHandler->append(new Response(200));
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
/** @var \Psr\Http\Message\RequestInterface $request */
$request = $this->history[0]['request'];
$this->assertStringContainsString('slim', $request->getBody()->getContents());
}
public function testJoinServer() { public function testJoinServer() {
$this->mockHandler->append(new Response(200)); $this->mockHandler->append(new Response(200));
$this->api->joinServer('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'ad72fe1efe364e6eb78c644a9fba1d30'); $this->api->joinServer('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'ad72fe1efe364e6eb78c644a9fba1d30');