use Mockery;
use Tests\TestCase;
use Aws\S3\S3Client;
use App\Services\S3Service;
class S3ServiceTest extends TestCase
{
private $service;
private $client;
protected function setUp() : void
{
$this->client = Mockery::mock('overload:'.S3Client::class);
$this->service = new S3Service();
}
/** @test */
public function can_generate_pre_signed_url()
{
$this->client->shouldReceive('getCommand')->once();
$this->service->generatePreSinedUrl('putObject', [
'Bucket' => config('filesystems.disks.s3.bucket'),
'Key' => 'testKey',
]);
}
}
我正在尝试将我的课程S3Service
与S3Client
集成
use Aws\S3\S3Client;
class AwsS3Service
{
private $client;
public function __construct()
{
$this->client = new S3Client([
'version' => '2006-03-01',
'region' => config('filesystems.disks.s3.region'),
'signature_version' => 'v4',
'credentials'=> [
'key' => config('filesystems.disks.s3.key'),
'secret' => config('filesystems.disks.s3.secret'),
],
]);
}
public function generatePreSinedUrl(string $action, array $options, $expireAfter = '+5 minutes')
{
$command = $this->client->getCommand($action, $options);
return $this->client->createPresignedRequest($command, $expireAfter);
}
}
但我收到此错误:
Mockery\Exception\BadMethodCallException: Method Aws\S3\S3Client::getCommand() does not exist on this mock object
,我认为它与我使用的overload
关键字有关,但我不确定。
如何使用AwsS3Service
作为供应商软件包来测试Aws\S3\S3Client
?