Skip to content

Commit

Permalink
Properly hook up query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyker committed Oct 2, 2024
1 parent 9eb1fb0 commit 7ab2dc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/SolderClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function request($url, $query = [], $useKey = true)
}

try {
$response = $this->client->get($url);
$response = $this->client->get($url, ['query' => $query]);
} catch (TransferException | GuzzleException $e) {
throw new ConnectionException('Request to \'' . $url . '\' failed. ' . $e->getMessage(), 0, $e);
}
Expand Down
37 changes: 34 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TechnicPack\SolderClient\Tests;

use GuzzleHttp\Middleware;
use TechnicPack\SolderClient\Exception\BadJSONException;
use TechnicPack\SolderClient\Exception\ConnectionException;
use TechnicPack\SolderClient\Exception\InvalidURLException;
Expand Down Expand Up @@ -242,17 +243,36 @@ public function testGetBuildUnauthorized()

public function testGetBuild()
{
$body = '{"minecraft":"1.5.2","forge":null,"java":null,"memory":null,"mods":[{"name":"armorbar","version":"v0.7.1","md5":"f323a8d582302ea0abd615a223f8a68b","url":"https://mirror.technicpack.net/Technic/mods/armorbar/armorbar-v0.7.1.zip"}]}';
$body = '{
"minecraft":"1.5.2",
"forge":null,
"java":null,
"memory":null,
"mods":[{
"id": 30,
"name":"armorbar",
"version":"v0.7.1",
"md5":"f323a8d582302ea0abd615a223f8a68b",
"url":"https://mirror.technicpack.net/Technic/mods/armorbar/armorbar-v0.7.1.zip",
"filesize": 25000,
"pretty_name": "Armor Bar",
"author": "Test",
"description": "Test description",
"link": "https://example.com/"
}]}';

// Create a mock and queue two responses.
$mock = new MockHandler([
new Response(200, ['Content-Length' => 0], '{"valid":"Key Validated.","name":"SolderClientTest","created_at":"2016-12-26T11:33:46.000Z"}'),
new Response(200, ['Content-Length' => 0], $body),
]);

$handler = HandlerStack::create($mock);
$handlerStack = HandlerStack::create($mock);

$client = SolderClient::factory('http://localhost/api/', 'C3gy35Um2pBE97xn90z0sUNhH1KbzI99', [], $handler);
$historyContainer = [];
$handlerStack->push(Middleware::history($historyContainer));

$client = SolderClient::factory('http://localhost/api/', 'C3gy35Um2pBE97xn90z0sUNhH1KbzI99', [], $handlerStack);

$build = $client->getBuild('hexxit', '1.0.1');

Expand All @@ -271,10 +291,21 @@ public function testGetBuild()
$this->assertCount(1, $build->mods);

$mod = $build->mods[0];
$this->assertEquals(30, $mod->id);
$this->assertEquals('armorbar', $mod->name);
$this->assertEquals('v0.7.1', $mod->version);
$this->assertEquals('f323a8d582302ea0abd615a223f8a68b', $mod->md5);
$this->assertEquals('https://mirror.technicpack.net/Technic/mods/armorbar/armorbar-v0.7.1.zip', $mod->url);
$this->assertEquals(25000, $mod->filesize);
$this->assertEquals('Armor Bar', $mod->pretty_name);
$this->assertEquals('Test', $mod->author);
$this->assertEquals('Test description', $mod->description);
$this->assertEquals('https://example.com/', $mod->link);

// Test if the query parameters are corrects
$lastRequest = end($historyContainer);
$expectedQuery = http_build_query(['include' => 'mods', 'k' => 'C3gy35Um2pBE97xn90z0sUNhH1KbzI99'], null, '&', PHP_QUERY_RFC3986);
$this->assertEquals($expectedQuery, $lastRequest['request']->getUri()->getQuery());
}

public function testBadPack()
Expand Down

0 comments on commit 7ab2dc6

Please sign in to comment.