assertEquals(0, $cast->god_type); // 测试设置值 $cast->god_type = 1; // 丰收之神 $this->assertEquals(1, $cast->god_type); $cast->god_type = 2; // 雨露之神 $this->assertEquals(2, $cast->god_type); $cast->god_type = 3; // 屠草之神 $this->assertEquals(3, $cast->god_type); $cast->god_type = 4; // 拭虫之神 $this->assertEquals(4, $cast->god_type); } /** * 测试神像时间属性 */ public function testGodDurationAttribute() { $cast = new NumericAttributesCast(); // 测试默认值 $this->assertEquals(0, $cast->god_duration_seconds); // 测试设置值 $cast->god_duration_seconds = 3600; // 1小时 $this->assertEquals(3600, $cast->god_duration_seconds); $cast->god_duration_seconds = 86400; // 24小时 $this->assertEquals(86400, $cast->god_duration_seconds); } /** * 测试神像物品识别逻辑 */ public function testGodItemIdentification() { $cast = new NumericAttributesCast(); // 非神像物品 $cast->god_duration_seconds = 0; $cast->god_type = 0; $this->assertFalse($this->isGodItem($cast)); // 只有时间没有类型 $cast->god_duration_seconds = 3600; $cast->god_type = 0; $this->assertFalse($this->isGodItem($cast)); // 只有类型没有时间 $cast->god_duration_seconds = 0; $cast->god_type = 1; $this->assertFalse($this->isGodItem($cast)); // 完整的神像物品 $cast->god_duration_seconds = 3600; $cast->god_type = 1; $this->assertTrue($this->isGodItem($cast)); } /** * 测试JSON序列化和反序列化 */ public function testJsonSerialization() { $cast = new NumericAttributesCast(); $cast->god_duration_seconds = 86400; $cast->god_type = 2; $cast->pet_power = 50; // 转换为数组 $array = $cast->toArray(); $this->assertEquals(86400, $array['god_duration_seconds']); $this->assertEquals(2, $array['god_type']); $this->assertEquals(50, $array['pet_power']); // 从数组创建新实例 $newCast = new NumericAttributesCast(); $newCast->fromArray($array); $this->assertEquals(86400, $newCast->god_duration_seconds); $this->assertEquals(2, $newCast->god_type); $this->assertEquals(50, $newCast->pet_power); } /** * 辅助方法:判断是否为神像物品 */ private function isGodItem(NumericAttributesCast $cast): bool { return $cast->god_duration_seconds > 0 && $cast->god_type > 0; } }