Skip to content

Commit

Permalink
fix: typed property Gaufrette\Adapter\AwsS3:: must not be accessed be…
Browse files Browse the repository at this point in the history
…fore initialization
  • Loading branch information
PedroTroller committed Feb 26, 2024
1 parent 30fd641 commit 1d6f39e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
54 changes: 50 additions & 4 deletions spec/Gaufrette/Adapter/AwsS3Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace spec\Gaufrette\Adapter;

use ArrayIterator;
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 +21,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

0 comments on commit 1d6f39e

Please sign in to comment.