diff --git a/src/Resources/Build.php b/src/Resources/Build.php index 2f734cc..4339c53 100644 --- a/src/Resources/Build.php +++ b/src/Resources/Build.php @@ -4,11 +4,11 @@ class Build { - public int $id; - public string $minecraft; - public ?string $java; - public ?int $memory; - public ?string $forge; + public int $id = -1; + public string $minecraft = ""; + public ?string $java = null; + public ?int $memory = -1; + public ?string $forge = null; /** * @var Mod[] $mods */ @@ -17,8 +17,8 @@ class Build public function __construct($properties) { foreach (get_object_vars($this) as $key => $val) { - if ($key !== "mods") { - $this->{$key} = $properties[$key] ?? null; + if ($key !== "mods" && array_key_exists($key, $properties)) { + $this->{$key} = $properties[$key]; } } diff --git a/src/Resources/Mod.php b/src/Resources/Mod.php index 6db96de..14418df 100644 --- a/src/Resources/Mod.php +++ b/src/Resources/Mod.php @@ -4,21 +4,23 @@ class Mod { - public int $id; - public string $name; - public string $version; - public string $md5; - public ?int $filesize; - public string $url; - public string $pretty_name; - public ?string $author; - public ?string $description; - public ?string $link; + public int $id = -1; + public string $name = ""; + public string $version = ""; + public string $md5 = ""; + public ?int $filesize = -1; + public string $url = ""; + public string $pretty_name = ""; + public ?string $author = null; + public ?string $description = null; + public ?string $link = null; public function __construct($properties) { foreach (get_object_vars($this) as $key => $val) { - $this->{$key} = $properties[$key] ?? null; + if (array_key_exists($key, $properties)) { + $this->{$key} = $properties[$key]; + } } } } \ No newline at end of file diff --git a/src/Resources/Modpack.php b/src/Resources/Modpack.php index c4cb218..81986a4 100644 --- a/src/Resources/Modpack.php +++ b/src/Resources/Modpack.php @@ -4,12 +4,12 @@ class Modpack { - public int $id; - public string $name; - public string $display_name; - public ?string $url; - public ?string $recommended; - public ?string $latest; + public int $id = -1; + public string $name = ""; + public string $display_name = ""; + public ?string $url = null; + public ?string $recommended = null; + public ?string $latest = null; /** * @var Build[] $builds */ diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 4f3199f..e3e0369 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -194,8 +194,14 @@ public function testGetModpack() $this->assertObjectHasProperty('recommended', $modpack); $this->assertObjectHasProperty('latest', $modpack); $this->assertObjectHasProperty('builds', $modpack); - $this->assertObjectHasProperty('builds', $modpack); $this->assertIsArray($modpack->builds); + + $this->assertEquals('hexxit', $modpack->name); + $this->assertEquals('Hexxit', $modpack->display_name); + $this->assertEquals(null, $modpack->url); + $this->assertEquals('1.0.10', $modpack->recommended); + $this->assertEquals('1.0.10', $modpack->latest); + $this->assertEquals(["1.0.0","1.0.1","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.0.10","2.0.0","2.0.1","2.0.1b","2.0.1c"], $modpack->builds); } public function testGetBuildDoesNotExist() @@ -256,6 +262,19 @@ public function testGetBuild() $this->assertObjectHasProperty('memory', $build); $this->assertObjectHasProperty('mods', $build); $this->assertIsArray($build->mods); + + $this->assertEquals(null, $build->forge); + $this->assertEquals('1.5.2', $build->minecraft); + $this->assertEquals(null, $build->java); + $this->assertEquals(null, $build->memory); + + $this->assertCount(1, $build->mods); + + $mod = $build->mods[0]; + $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); } public function testBadPack() diff --git a/tests/DynamicPropertiesTest.php b/tests/DynamicPropertiesTest.php index 861f76c..ceffaae 100644 --- a/tests/DynamicPropertiesTest.php +++ b/tests/DynamicPropertiesTest.php @@ -13,7 +13,6 @@ public function testBuild() { $props = [ 'id' => 1, - 'extra' => 'stuff', ]; @@ -21,6 +20,8 @@ public function testBuild() $this->assertTrue(property_exists($build, 'id')); $this->assertFalse(property_exists($build, 'extra')); + + $this->assertEquals(1, $build->id); } public function testMod() @@ -34,6 +35,8 @@ public function testMod() $this->assertTrue(property_exists($mod, 'id')); $this->assertFalse(property_exists($mod, 'extra')); + + $this->assertEquals(1, $mod->id); } public function testModpack() @@ -47,5 +50,7 @@ public function testModpack() $this->assertTrue(property_exists($modpack, 'id')); $this->assertFalse(property_exists($modpack, 'extra')); + + $this->assertEquals(1, $modpack->id); } }