-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplesTest.php
More file actions
66 lines (60 loc) · 2.01 KB
/
Copy pathExamplesTest.php
File metadata and controls
66 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Apify\Client\Tests\Examples;
use Apify\Client\ApifyClient;
use PHPUnit\Framework\TestCase;
use Throwable;
/**
* Runs each documentation example end-to-end against the live API, proving the snippets in the docs
* actually work. Skipped when {@code APIFY_TOKEN} is not set. This is the "Test examples" CI step.
*/
final class ExamplesTest extends TestCase
{
private function client(): ApifyClient
{
$token = getenv('APIFY_TOKEN');
if ($token === false || $token === '') {
self::markTestSkipped('skipping: APIFY_TOKEN is not set');
}
$apiUrl = getenv('APIFY_API_URL');
$baseUrl = ($apiUrl === false || $apiUrl === '') ? 'https://api.apify.com' : rtrim($apiUrl, '/');
if (str_ends_with($baseUrl, '/v2')) {
$baseUrl = substr($baseUrl, 0, -3);
}
return new ApifyClient(token: $token, baseUrl: $baseUrl);
}
/**
* @return array<string,array{class-string}>
*/
public static function exampleProvider(): array
{
return [
'RunStoreActor' => [RunStoreActor::class],
'Storages' => [Storages::class],
'GetAccount' => [GetAccount::class],
'CreateBuildRunActor' => [CreateBuildRunActor::class],
'RunAndLastRunStorages' => [RunAndLastRunStorages::class],
'IterateStore' => [IterateStore::class],
'LogRedirection' => [LogRedirection::class],
];
}
/**
* @param class-string $exampleClass
* @dataProvider exampleProvider
*/
public function testExampleRuns(string $exampleClass): void
{
$client = $this->client();
ob_start();
try {
/** @var callable $runner */
$runner = [$exampleClass, 'run'];
$runner($client);
} catch (Throwable $e) {
ob_end_clean();
self::fail($exampleClass . ' failed: ' . $e->getMessage());
}
ob_end_clean();
self::assertTrue(true);
}
}