s3Client = Mockery::mock(S3ClientInterface::class); $this->cache = Mockery::mock(Cache::class); $this->metadataService = Mockery::mock(MediaMetadataService::class); $this->songRepository = Mockery::mock(SongRepository::class); $this->helper = Mockery::mock(Helper::class); $this->s3Service = new S3Service( $this->s3Client, $this->cache, $this->metadataService, $this->songRepository, $this->helper ); } public function testGetSongPublicUrl(): void { /** @var Song $song */ $song = Song::factory()->create(['path' => 's3://foo/bar']); $cmd = Mockery::mock(CommandInterface::class); $this->s3Client->shouldReceive('getCommand') ->with('GetObject', [ 'Bucket' => 'foo', 'Key' => 'bar', ]) ->andReturn($cmd); $request = Mockery::mock(Request::class, ['getUri' => 'https://aws.com/foo.mp3']); $this->s3Client->shouldReceive('createPresignedRequest') ->with($cmd, '+1 hour') ->andReturn($request); $this->cache->shouldReceive('remember') ->once() ->andReturn('https://aws.com/foo.mp3'); self::assertSame('https://aws.com/foo.mp3', $this->s3Service->getSongPublicUrl($song)); } }