testStringLength(); $this->testIntValue(); $this->testArrayCount(); } public function testStringLength(): void { $resolver = new OptionsResolver([ Option::string('username')->min(3)->max(10), ]); // Valid $options = $resolver->resolve(['username' => 'johndoe']); $this->assertStrictEquals('johndoe', $options['username']); // Invalid (too short) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['username' => 'jo']); }); // Invalid (too long) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['username' => 'johndoelongname']); }); } public function testIntValue(): void { $resolver = new OptionsResolver([ Option::int('port')->min(1024)->max(65535), ]); // Valid $options = $resolver->resolve(['port' => 8080]); $this->assertStrictEquals(8080, $options['port']); // Invalid (too small) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['port' => 80]); }); // Invalid (too large) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['port' => 70000]); }); } public function testArrayCount(): void { $resolver = new OptionsResolver([ Option::array('items')->min(1)->max(3), ]); // Valid $options = $resolver->resolve(['items' => ['a', 'b']]); $this->assertCount(2, $options['items']); // Invalid (too few) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['items' => []]); }); // Invalid (too many) $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['items' => ['a', 'b', 'c', 'd']]); }); } }