|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Qdrant\Tests\Unit\Models\Traits; |
| 4 | + |
| 5 | +use InvalidArgumentException; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use Psr\Http\Message\RequestFactoryInterface; |
| 8 | +use Psr\Http\Message\RequestInterface; |
| 9 | +use Qdrant\Endpoints\HttpFactoryTrait; |
| 10 | +use Qdrant\Models\Traits\ProtectedPropertyAccessor; |
| 11 | + |
| 12 | +class HttpFactoryTraitTest extends TestCase |
| 13 | +{ |
| 14 | + public function testCustomHttpRequestFactory() |
| 15 | + { |
| 16 | + $requestFactory = new class implements RequestFactoryInterface { |
| 17 | + public function createRequest(string $method, $uri): RequestInterface |
| 18 | + { |
| 19 | + } |
| 20 | + }; |
| 21 | + |
| 22 | + $mock = new class { |
| 23 | + use HttpFactoryTrait; |
| 24 | + }; |
| 25 | + $mock->setHttpFactory($requestFactory); |
| 26 | + $this->assertInstanceOf(get_class($requestFactory), $mock->getHttpFactory()); |
| 27 | + } |
| 28 | + |
| 29 | + public function testHeaders() |
| 30 | + { |
| 31 | + $mock = new class { |
| 32 | + use HttpFactoryTrait; |
| 33 | + |
| 34 | + public function test(string $method, string $uri, array $body = [], $queryString = []): RequestInterface |
| 35 | + { |
| 36 | + return $this->createRequest($method, $uri . $this->queryBuild($queryString), $body); |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + $request = $mock->test('GET', '/api', ['foo' => 'bar'], ['query' => 'string']); |
| 41 | + |
| 42 | + $this->assertEquals('{"foo":"bar"}', $request->getBody()->getContents()); |
| 43 | + $this->assertEquals('query=string', $request->getUri()->getQuery()); |
| 44 | + $this->assertEquals('/api', $request->getUri()->getPath()); |
| 45 | + } |
| 46 | +} |
0 commit comments