Skip to content

Commit 53e3bca

Browse files
marebiscokriptoburakBurak Bayır
authored
test: run README quickstart with fake transport (closes #13) (#19)
* test: run README quickstart with fake transport (closes #13) * test: exercise README quickstart with fake transport Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com> --------- Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com> Co-authored-by: kriptoburak <kriptoburak@users.noreply.github.com> Co-authored-by: Burak Bayır <burakbayir1@gmail.com>
1 parent da1ab75 commit 53e3bca

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/ReadmeQuickstartTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
// SPDX-FileCopyrightText: 2026 Xquik contributors
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
namespace Tests;
8+
9+
use Http\Discovery\Psr17FactoryDiscovery;
10+
use Http\Mock\Client as MockClient;
11+
use PHPUnit\Framework\TestCase;
12+
use XTwitterScraper\Client;
13+
14+
/**
15+
* @internal
16+
*/
17+
final class ReadmeQuickstartTest extends TestCase
18+
{
19+
public function testReadmeQuickstartWithFakeTransport(): void
20+
{
21+
$transport = new MockClient;
22+
$response = Psr17FactoryDiscovery::findResponseFactory()
23+
->createResponse()
24+
->withHeader('Content-Type', 'application/json')
25+
->withBody(Psr17FactoryDiscovery::findStreamFactory()->createStream(
26+
'{"has_next_page":false,"next_cursor":"","tweets":[]}',
27+
))
28+
;
29+
$transport->setDefaultResponse($response);
30+
31+
$client = new Client(
32+
apiKey: 'My API Key',
33+
requestOptions: ['transporter' => $transport],
34+
);
35+
36+
$client->x->tweets->search(q: 'from:elonmusk', limit: 10);
37+
38+
$requests = $transport->getRequests();
39+
$this->assertCount(1, $requests);
40+
41+
parse_str($requests[0]->getUri()->getQuery(), $query);
42+
$this->assertSame('from:elonmusk', $query['q'] ?? null);
43+
$this->assertSame('10', $query['limit'] ?? null);
44+
}
45+
}

0 commit comments

Comments
 (0)