rpcii-php/tests/CurlHttpTest.php
flashwave 93ec139171 Rename and a set of reworks.
- Aiwass -> RPCii
 - Swapped the meaning of "Procedure" and "Action"
 - IRpcActionHandler is now RpcHandler, abstract class no longer exists like Index
 - Anything suffixed by Trait is now suffixed by Common
 - All I prefixes on interfaces are gone
 - A PHP StreamWrapper implementation of HttpRequest added as a fallback for when cURL isnt installed
 - HttpRpcServer now hosts on /_rpcii instead of /_aiwass
 - Packagist package is now flashii/rpcii instead of flashwave/aiwass

That's probably all of it but I probably forgor.
2024-11-13 23:17:29 +00:00

59 lines
2.2 KiB
PHP

<?php
// CurlHttpTest.php
// Created: 2024-08-13
// Updated: 2024-11-13
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use RPCii\Client\CurlHttpRequest;
#[CoversClass(CurlHttpRequest::class)]
final class CurlHttpTest extends TestCase {
public function testGetRequest(): void {
$request = new CurlHttpRequest;
$request->setPost(false);
$request->setUrl('https://httpbin.org/get?alreadyhere=true');
$request->setHeader('X-Test', 'teste');
$request->setParams('soap=beans');
$response = json_decode($request->execute(), true);
$this->assertIsArray($response);
$this->assertArrayHasKey('headers', $response);
$this->assertIsArray($response['headers']);
$this->assertArrayHasKey('X-Test', $response['headers']);
$this->assertEquals('teste', $response['headers']['X-Test']);
$this->assertArrayHasKey('args', $response);
$this->assertIsArray($response['args']);
$this->assertArrayHasKey('alreadyhere', $response['args']);
$this->assertEquals('true', $response['args']['alreadyhere']);
$this->assertArrayHasKey('soap', $response['args']);
$this->assertEquals('beans', $response['args']['soap']);
}
public function testPostRequest(): void {
$request = new CurlHttpRequest;
$request->setPost(true);
$request->setUrl('https://httpbin.org/post');
$request->setHeader('X-Meow', 'soap');
$request->setParams('windows=xp&macos=leopard');
$response = json_decode($request->execute(), true);
$this->assertIsArray($response);
$this->assertArrayHasKey('headers', $response);
$this->assertIsArray($response['headers']);
$this->assertArrayHasKey('X-Meow', $response['headers']);
$this->assertEquals('soap', $response['headers']['X-Meow']);
$this->assertArrayHasKey('form', $response);
$this->assertIsArray($response['form']);
$this->assertArrayHasKey('windows', $response['form']);
$this->assertEquals('xp', $response['form']['windows']);
$this->assertArrayHasKey('macos', $response['form']);
$this->assertEquals('leopard', $response['form']['macos']);
}
}