Commit 5789a5e2 authored by Mark Harding's avatar Mark Harding

(feat): spec tests for client upload

1 merge request!263(feat): Client uploader
Pipeline #70279474 passed with stages
in 8 minutes and 3 seconds
......@@ -4,6 +4,13 @@ namespace Minds\Core\Media\ClientUpload;
use Minds\Traits\MagicAttributes;
/**
* Class ClientUploadLease
* @package Minds\Core\Media\ClientUpload
* @method string getGuid()
* @method string getMediaType()
* @method string getPresignedUrl()
*/
class ClientUploadLease
{
use MagicAttributes;
......
......@@ -84,28 +84,6 @@ class FFMpeg implements ServiceInterface
*/
public function getPresignedUrl()
{
/* $bucket = 'cinemr';
$formInputs = [ ];
$options = [
//['acl' => 'public-read'],
['bucket' => $bucket],
['eq', '$key', "$this->dir/$this->key/source" ],
];
$expires = '+20 minutes';
$postObject = new \Aws\S3\PostObjectV4(
$this->s3,
$bucket,
$formInputs,
$options,
$expires
);
$formAttributes = $postObject->getFormAttributes();
$formInputs = $postObject->getFormInputs();
var_dump($formAttributes, $formInputs); exit;
*/
$cmd = $this->s3->getCommand('PutObject', [
'Bucket' => 'cinemr',
'Key' => "$this->dir/$this->key/source",
......
<?php
namespace Spec\Minds\Core\Media\ClientUpload;
use Minds\Core\Media\ClientUpload\Manager;
use Minds\Core\Media\ClientUpload\ClientUploadLease;
use Minds\Core\Media\Services\FFMpeg;
use Minds\Core\GuidBuilder;
use Minds\Core\Entities\Actions\Save;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ManagerSpec extends ObjectBehavior
{
private $ffmpeg;
private $guid;
private $save;
function let(FFMpeg $FFMpeg, GuidBuilder $guid, Save $save)
{
$this->beConstructedWith($FFMpeg, $guid, $save);
$this->ffmpeg = $FFMpeg;
$this->guid = $guid;
$this->save = $save;
}
function it_is_initializable()
{
$this->shouldHaveType(Manager::class);
}
function it_should_return_an_upload_lease()
{
$this->guid->build()
->willReturn(123);
$this->ffmpeg->setKey(123)
->shouldBeCalled();
$this->ffmpeg->getPresignedUrl()
->willReturn('s3-url-here');
$lease = $this->prepare('video');
$lease->getMediaType()
->shouldBe('video');
$lease->getGuid()
->shouldBe(123);
$lease->getPresignedUrl()
->shouldBe('s3-url-here');
}
function it_should_complete_an_upload(ClientUploadLease $lease)
{
$lease->getMediaType()
->willReturn('video');
$lease->getGuid()
->willReturn(456);
$this->save->setEntity(Argument::that(function ($video) {
return $video->guid == 456
&& $video->access_id == 0;
}))
->shouldBeCalled()
->willReturn($this->save);
$this->save->save()
->shouldBeCalled();
$this->ffmpeg->setKey(456)
->shouldBeCalled();
$this->ffmpeg->transcode()
->shouldBeCalled();
$this->complete($lease)
->shouldReturn(true);
}
}
<?php
namespace Spec\Minds\Core\Media\Services;
use Minds\Core\Media\Services\FFMpeg;
use FFMpeg\FFMpeg as FFMpegClient;
use FFMpeg\FFProbe as FFProbeClient;
use Minds\Core\Queue\Interfaces\QueueClient;
use Psr\Http\Message\RequestInterface;
use Aws\S3\S3Client;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class FFMpegSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(FFMpeg::class);
}
function it_should_get_a_presigned_urn(
QueueClient $queue,
FFMpegClient $ffmpeg,
FFProbeClient $ffprobe,
S3Client $s3,
\Aws\CommandInterface $cmd,
RequestInterface $request
)
{
$this->beConstructedWith($queue, $ffmpeg, $ffprobe, $s3);
$s3->getCommand('PutObject', [
'Bucket' => 'cinemr',
'Key' => "/123/source",
])
->shouldBeCalled()
->willReturn($cmd);
$s3->createPresignedRequest(Argument::any(), Argument::any())
->willReturn($request);
$request->getUri()
->willReturn('aws-signed-url');
$this->setKey(123);
$this->getPresignedUrl()
->shouldReturn('aws-signed-url');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment