post = false; $request->url = 'https://httpbin.org/get?alreadyhere=true'; $request->params = 'soap=beans'; $request->setHeader('X-Test', 'teste'); $response = $request->execute(); $this->assertArrayHasKey('status', $response); $this->assertIsInt($response['status']); $this->assertEquals(200, $response['status']); $this->assertArrayHasKey('format', $response); $this->assertIsInt($response['format']); $this->assertEquals(1, $response['format']); $this->assertArrayHasKey('body', $response); $this->assertIsString($response['body']); $body = json_decode($response['body'], true); $this->assertIsArray($body); $this->assertArrayHasKey('headers', $body); $this->assertIsArray($body['headers']); $this->assertArrayHasKey('X-Test', $body['headers']); $this->assertEquals('teste', $body['headers']['X-Test']); $this->assertArrayHasKey('args', $body); $this->assertIsArray($body['args']); $this->assertArrayHasKey('alreadyhere', $body['args']); $this->assertEquals('true', $body['args']['alreadyhere']); $this->assertArrayHasKey('soap', $body['args']); $this->assertEquals('beans', $body['args']['soap']); } public function testPostRequest(): void { $request = new CurlHttpRequest; $request->post = true; $request->url = 'https://httpbin.org/post'; $request->params = 'windows=xp&macos=leopard'; $request->setHeader('X-Meow', 'soap'); $response = $request->execute(); $this->assertArrayHasKey('status', $response); $this->assertIsInt($response['status']); $this->assertEquals(200, $response['status']); $this->assertArrayHasKey('format', $response); $this->assertIsInt($response['format']); $this->assertEquals(1, $response['format']); $this->assertArrayHasKey('body', $response); $this->assertIsString($response['body']); $body = json_decode($response['body'], true); $this->assertIsArray($body); $this->assertArrayHasKey('headers', $body); $this->assertIsArray($body['headers']); $this->assertArrayHasKey('X-Meow', $body['headers']); $this->assertEquals('soap', $body['headers']['X-Meow']); $this->assertArrayHasKey('form', $body); $this->assertIsArray($body['form']); $this->assertArrayHasKey('windows', $body['form']); $this->assertEquals('xp', $body['form']['windows']); $this->assertArrayHasKey('macos', $body['form']); $this->assertEquals('leopard', $body['form']['macos']); } }