assertInstanceOf(Request::class, $req); $this->assertSame('https://example.com/api', $req->getUrl()); } public function testDefaultMethodIsGet(): void { $req = Request::factory('https://example.com'); $this->assertSame('GET', $req->getMethod()); } public function testMethodSetter(): void { $req = Request::factory('https://example.com')->method('post'); $this->assertSame('POST', $req->getMethod()); } public function testHeaderSetter(): void { $req = Request::factory('https://example.com') ->header('Authorization', 'Bearer token123'); $this->assertSame(['Authorization' => 'Bearer token123'], $req->getHeaders()); } public function testBodySetter(): void { $req = Request::factory('https://example.com')->body('raw body'); $this->assertSame('raw body', $req->getBody()); } public function testDefaultBodyIsNull(): void { $req = Request::factory('https://example.com'); $this->assertNull($req->getBody()); } public function testJsonSetsBodyAndHeaders(): void { $req = Request::factory('https://example.com')->json(['key' => 'value']); $this->assertStringContainsString('"key":"value"', $req->getBody()); $this->assertSame('application/json', $req->getHeaders()['Content-Type']); $this->assertSame('application/json', $req->getHeaders()['Accept']); } public function testJsonEncodesUnicode(): void { $req = Request::factory('https://example.com')->json(['name' => 'Иван']); $this->assertStringContainsString('Иван', $req->getBody()); } public function testTimeoutDefault(): void { $req = Request::factory('https://example.com'); $this->assertSame(30, $req->getTimeout()); } public function testTimeoutSetter(): void { $req = Request::factory('https://example.com')->timeout(10); $this->assertSame(10, $req->getTimeout()); } public function testFluentInterface(): void { $req = Request::factory('https://example.com') ->method('POST') ->header('X-Custom', 'value') ->timeout(5) ->body('data'); $this->assertSame('POST', $req->getMethod()); $this->assertSame('value', $req->getHeaders()['X-Custom']); $this->assertSame(5, $req->getTimeout()); $this->assertSame('data', $req->getBody()); } }