Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typed property Gaufrette\Adapter\AwsS3:: must not be accessed before initialization #716

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions spec/Gaufrette/Adapter/AwsS3Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace spec\Gaufrette\Adapter;

use Aws\Result;
use Aws\S3\S3Client;
use Gaufrette\Adapter;
use Gaufrette\Adapter\AwsS3;
use Gaufrette\Adapter\MetadataSupporter;
use Gaufrette\Adapter\MimeTypeProvider;
use Gaufrette\Adapter\SizeCalculator;
use PhpSpec\ObjectBehavior;

class AwsS3Spec extends ObjectBehavior
Expand All @@ -15,26 +20,66 @@ function let(S3Client $service)

function it_is_initializable()
{
$this->shouldHaveType('Gaufrette\Adapter\AwsS3');
$this->shouldHaveType(AwsS3::class);
}

function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
$this->shouldHaveType(Adapter::class);
}

function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
$this->shouldHaveType(MetadataSupporter::class);
}

function it_supports_sizecalculator()
{
$this->shouldHaveType('Gaufrette\Adapter\SizeCalculator');
$this->shouldHaveType(SizeCalculator::class);
}

function it_provides_mime_type()
{
$this->shouldHaveType(MimeTypeProvider::class);
}

function it_creates_bucket_if_it_does_not_exists(S3Client $service)
{
$this->beConstructedWith(
$service,
'bucketName',
['create' => true]
);

$service
->doesBucketExist('bucketName')
->shouldBeCalledTimes(1)
->willReturn(false)
;

$service
->getRegion()
->shouldBeCalledTimes(1)
->willReturn('eu-west-3')
;

$service
->createBucket(
[
'Bucket' => 'bucketName',
'LocationConstraint' => 'eu-west-3',
]
)
->shouldBeCalledTimes(1)
->willReturn(new Result)
;

$service
->getIterator('ListObjects', ['Bucket' => 'bucketName'])
->shouldBeCalledTimes(1)
->willReturn([])
;

$this->listKeys();
}
}
5 changes: 2 additions & 3 deletions src/Gaufrette/Adapter/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator
protected S3Client $service;
protected string $bucket;
protected array $options;
protected bool $bucketExists;
protected bool $bucketExists = false;
protected array $metadata = [];
protected bool $detectContentType;

Expand Down Expand Up @@ -278,9 +278,8 @@ protected function ensureBucketExists(): bool
'Bucket' => $this->bucket,
'LocationConstraint' => $this->service->getRegion(),
]);
$this->bucketExists = true;

return true;
return $this->bucketExists = true;
}

protected function getOptions(string $key, array $options = []): array
Expand Down
Loading