File: WaiterTest.php

package info (click to toggle)
php-async-aws-core 1.27.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 988 kB
  • sloc: php: 6,837; makefile: 32
file content (83 lines) | stat: -rw-r--r-- 2,626 bytes parent folder | download | duplicates (3)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

declare(strict_types=1);

namespace AsyncAws\Core\Tests\Integration;

use AsyncAws\Core\Exception\Http\NetworkException;
use AsyncAws\S3\S3Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\HttpClient;

class WaiterTest extends TestCase
{
    public function testWaiterException(): void
    {
        if (!class_exists(S3Client::class)) {
            self::markTestSkipped('This test needs a client with waiter endpoints');
        }

        $client = new S3Client(['endpoint' => 'http://127.0.0.1:10'], null, HttpClient::create(['timeout' => 5]));
        $result = $client->bucketExists(['Bucket' => 'test']);

        $this->expectException(NetworkException::class);
        $result->isSuccess();
    }

    public function testWaiterThrowOnce(): void
    {
        if (!class_exists(S3Client::class)) {
            self::markTestSkipped('This test needs a client with waiter endpoints');
        }

        $client = new S3Client(['endpoint' => 'http://127.0.0.1:10'], null, HttpClient::create(['timeout' => 5]));
        $result = $client->bucketExists(['Bucket' => 'test']);

        try {
            $result->isSuccess();
            self::fail('An exception should have been triggered');
        } catch (NetworkException $e) {
        }

        unset($result);
        self::expectNotToPerformAssertions();
    }

    public function testWaiterThrowOnRetry(): void
    {
        if (!class_exists(S3Client::class)) {
            self::markTestSkipped('This test needs a client with waiter endpoints');
        }

        $client = new S3Client(['endpoint' => 'http://127.0.0.1:10'], null, HttpClient::create(['timeout' => 5]));
        $result = $client->bucketExists(['Bucket' => 'test']);

        try {
            $result->isSuccess();
            self::fail('An exception should have been triggered');
        } catch (NetworkException $e) {
        }

        $this->expectException(NetworkException::class);
        $result->isSuccess();
    }

    public function testWaiterThrowOnWait(): void
    {
        if (!class_exists(S3Client::class)) {
            self::markTestSkipped('This test needs a client with waiter endpoints');
        }

        $client = new S3Client(['endpoint' => 'http://127.0.0.1:10'], null, HttpClient::create(['timeout' => 5]));
        $result = $client->bucketExists(['Bucket' => 'test']);

        try {
            $result->isSuccess();
            self::fail('An exception should have been triggered');
        } catch (NetworkException $e) {
        }

        $this->expectException(NetworkException::class);
        $result->wait();
    }
}