1 | <?php |
||
21 | class AwsS3V3AdapterTest extends FilesystemAdapterTestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | private $shouldCleanUp = false; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private static $adapterPrefix = 'test-prefix'; |
||
32 | |||
33 | /** |
||
34 | * @var S3ClientInterface|null |
||
35 | */ |
||
36 | private static $s3Client; |
||
37 | |||
38 | /** |
||
39 | * @var S3ClientStub |
||
40 | */ |
||
41 | private static $stubS3Client; |
||
42 | |||
43 | public static function setUpBeforeClass(): void |
||
44 | { |
||
45 | static::$adapterPrefix = 'travis-ci/' . bin2hex(random_bytes(10)); |
||
|
|||
46 | } |
||
47 | |||
48 | protected function tearDown(): void |
||
49 | { |
||
50 | if ( ! $this->shouldCleanUp) { |
||
51 | return; |
||
52 | } |
||
53 | |||
54 | $adapter = $this->adapter(); |
||
55 | /** @var StorageAttributes[] $listing */ |
||
56 | $listing = $adapter->listContents('', false); |
||
57 | |||
58 | foreach ($listing as $item) { |
||
59 | if ($item->isFile()) { |
||
60 | $adapter->delete($item->path()); |
||
61 | } else { |
||
62 | $adapter->deleteDirectory($item->path()); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | |||
67 | private static function s3Client(): S3ClientInterface |
||
68 | { |
||
69 | if (static::$s3Client instanceof S3ClientInterface) { |
||
70 | return static::$s3Client; |
||
71 | } |
||
72 | |||
73 | $key = getenv('FLYSYSTEM_AWS_S3_KEY'); |
||
74 | $secret = getenv('FLYSYSTEM_AWS_S3_SECRET'); |
||
75 | $bucket = getenv('FLYSYSTEM_AWS_S3_BUCKET'); |
||
76 | $region = getenv('FLYSYSTEM_AWS_S3_REGION') ?: 'eu-central-1'; |
||
77 | |||
78 | if ( ! $key || ! $secret || ! $bucket) { |
||
79 | self::markTestSkipped('No AWS credentials present for testing.'); |
||
80 | } |
||
81 | |||
82 | $options = ['version' => 'latest', 'credentials' => compact('key', 'secret'), 'region' => $region]; |
||
83 | |||
84 | return static::$s3Client = new S3Client($options); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | */ |
||
90 | public function writing_with_a_specific_mime_type(): void |
||
97 | |||
98 | /** |
||
99 | * @test |
||
100 | */ |
||
101 | public function listing_contents_recursive(): void |
||
118 | |||
119 | /** |
||
120 | * @test |
||
121 | */ |
||
122 | public function failing_to_delete_while_moving(): void |
||
132 | |||
133 | /** |
||
134 | * @test |
||
135 | */ |
||
136 | public function failing_to_delete_a_file(): void |
||
145 | |||
146 | /** |
||
147 | * @test |
||
148 | * @dataProvider casesWhereHttpStreamingInfluencesSeekability |
||
149 | */ |
||
150 | public function streaming_reads_are_not_seekable_and_non_streaming_are(bool $streaming, bool $seekable): void |
||
165 | |||
166 | public function casesWhereHttpStreamingInfluencesSeekability(): Generator |
||
171 | |||
172 | /** |
||
173 | * @test |
||
174 | * @dataProvider casesWhereHttpStreamingInfluencesSeekability |
||
175 | */ |
||
176 | public function configuring_http_streaming_via_options(bool $streaming): void |
||
187 | |||
188 | protected static function createFilesystemAdapter(bool $streaming = true, array $options = []): FilesystemAdapter |
||
197 | } |
||
198 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: