mirror of
https://github.com/elyby/mojang-api.git
synced 2025-05-31 14:11:44 +05:30
Implemented Blocked Servers endpoint
This commit is contained in:
@@ -310,6 +310,21 @@ class ApiTest extends TestCase {
|
||||
$this->api->playernamesToUuids($names);
|
||||
}
|
||||
|
||||
public function testBlockedServers() {
|
||||
$this->mockHandler->append(new Response(200, [], trim('
|
||||
6f2520f8bd70a718c568ab5274c56bdbbfc14ef4
|
||||
7ea72de5f8e70a2ac45f1aa17d43f0ca3cddeedd
|
||||
c005ad34245a8f2105658da2d6d6e8545ef0f0de
|
||||
c645d6c6430db3069abd291ec13afebdb320714b
|
||||
') . "\n"));
|
||||
|
||||
$result = $this->api->blockedServers();
|
||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||
$request = $this->history[0]['request'];
|
||||
$this->assertSame('https://sessionserver.mojang.com/blockedservers', (string)$request->getUri());
|
||||
$this->assertCount(4, $result);
|
||||
}
|
||||
|
||||
public function testAuthenticate() {
|
||||
$this->mockHandler->append($this->createResponse(200, [
|
||||
'accessToken' => 'access token value',
|
||||
|
66
tests/Response/BlockedServersCollectionTest.php
Normal file
66
tests/Response/BlockedServersCollectionTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ely\Mojang\Test\Response;
|
||||
|
||||
use Ely\Mojang\Response\BlockedServersCollection;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BlockedServersCollectionTest extends TestCase {
|
||||
|
||||
public function testArrayAccess() {
|
||||
$model = new BlockedServersCollection(['1', '2', '3']);
|
||||
$this->assertTrue(isset($model[0]));
|
||||
$this->assertFalse(isset($model[65535]));
|
||||
$this->assertSame('1', $model[0]);
|
||||
$this->assertSame('2', $model[1]);
|
||||
unset($model[0]);
|
||||
$this->assertFalse(isset($model[0]));
|
||||
$model[3] = 'find me';
|
||||
$this->assertSame('find me', $model[3]);
|
||||
}
|
||||
|
||||
public function testCountable() {
|
||||
$model = new BlockedServersCollection(['1', '2', '3']);
|
||||
$this->assertCount(3, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getIsBlockedCases
|
||||
*/
|
||||
public function testIsBlocked(string $serverName, bool $expectedResult) {
|
||||
$model = new BlockedServersCollection([
|
||||
'6f2520f8bd70a718c568ab5274c56bdbbfc14ef4', // *.minetime.com
|
||||
'48f04e89d20b15de115503f22fedfe2cb2d1ab12', // brandonisan.unusualperson.com
|
||||
'4ca799b162d4ebdf2ec5e0ece2ed51fba5a3db65', // 136.243.*
|
||||
'b7a822278e90205f016c1b028122e222f836641b', // 147.117.184.134
|
||||
]);
|
||||
$this->assertSame($expectedResult, $model->isBlocked($serverName));
|
||||
}
|
||||
|
||||
public function getIsBlockedCases() {
|
||||
yield ['mc.minetime.com', true];
|
||||
yield ['MC.MINETIME.COM', true];
|
||||
yield ['sub.mc.minetime.com', true];
|
||||
yield ['minetime.com', false];
|
||||
yield ['minetime.mc.com', false];
|
||||
|
||||
yield ['brandonisan.unusualperson.com', true];
|
||||
yield ['other.unusualperson.com', false];
|
||||
|
||||
yield ['136.243.88.97', true];
|
||||
yield ['136.244.88.97', false];
|
||||
|
||||
yield ['147.117.184.134', true];
|
||||
yield ['147.117.184.135', false];
|
||||
}
|
||||
|
||||
public function testIsBlockedWithIPv6() {
|
||||
$model = new BlockedServersCollection([]);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Minecraft does not support IPv6, so this library too');
|
||||
$model->isBlocked('d860:5df:9447:61b3:d1dd:1170:146a:bcc');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user