-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Transloadit\Factory; | ||
|
||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
use Transloadit\Model\Contracts\AuthInterface; | ||
use Transloadit\Service\AssemblyResourceService; | ||
use Transloadit\Service\AssemblyWaitForResourceService; | ||
use Transloadit\Service\Contracts\AssemblyResourceServiceInterface; | ||
|
||
class AssemblyWaitForResourceServiceFactory | ||
{ | ||
public static function create( | ||
AuthInterface $auth, | ||
HttpClientInterface $client = null, | ||
SerializerInterface $serializer = null | ||
): AssemblyResourceServiceInterface { | ||
$client = $client ?? TransloaditHttpClientFactory::create(); | ||
$serializer = $serializer ?? SerializerFactory::create(); | ||
|
||
return new AssemblyWaitForResourceService($auth, $client, $serializer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Transloadit\Service; | ||
|
||
use Transloadit\Enum\Status; | ||
use Transloadit\Model\Resource\Contracts\AssemblyInterface; | ||
use Transloadit\Model\Resource\Contracts\ResourceInterface; | ||
|
||
class AssemblyWaitForResourceService extends AssemblyResourceService | ||
{ | ||
public function create(AssemblyInterface $assembly): ResourceInterface | ||
{ | ||
$assembly = parent::create($assembly); | ||
|
||
while (in_array($assembly->getStatus(), [Status::ASSEMBLY_EXECUTING, Status::ASSEMBLY_UPLOADING])) { | ||
sleep(1); | ||
$assembly = $this->getById($assembly->getId()); | ||
} | ||
|
||
return $assembly; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/Functional/Service/AssemblyWaitForResourceServiceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Transloadit\Tests\Functional\Service; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
use Transloadit\Enum\Status; | ||
use Transloadit\Factory\AssemblyWaitForResourceServiceFactory; | ||
use Transloadit\Model\Contracts\AuthInterface; | ||
use Transloadit\Model\Resource\Contracts\AssemblyInterface; | ||
use Transloadit\Service\AssemblyWaitForResourceService; | ||
|
||
class AssemblyWaitForResourceServiceTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provider | ||
* @param string $firstAssemblyStatus | ||
* @param string $secondAssemblyStatus | ||
* @param $execution | ||
*/ | ||
public function testCanCreateAnAssembly(string $firstAssemblyStatus, string $secondAssemblyStatus, $execution) | ||
{ | ||
$auth = $this->createMock(AuthInterface::class); | ||
$client = $this->createMock(HttpClientInterface::class); | ||
$serializer = $this->createMock(SerializerInterface::class); | ||
|
||
$assembly1 = $this->createMock(AssemblyInterface::class); | ||
$assembly1 | ||
->method('getStatus') | ||
->willReturn($firstAssemblyStatus); | ||
|
||
$assembly2 = $this->createMock(AssemblyInterface::class); | ||
$assembly2 | ||
->method('getStatus') | ||
->willReturn($secondAssemblyStatus); | ||
|
||
$assemblyService = $this | ||
->getMockBuilder(AssemblyWaitForResourceService::class) | ||
->setConstructorArgs([$auth, $client, $serializer]) | ||
->onlyMethods(['getById', 'requestResource', 'deserializeResource']) | ||
->getMock() | ||
; | ||
$assemblyService | ||
->expects($execution) | ||
->method('getById') | ||
->willReturn($assembly2) | ||
; | ||
$assemblyService | ||
->method('deserializeResource') | ||
->willReturn($assembly1); | ||
|
||
$assemblyService->create($assembly1); | ||
} | ||
|
||
public function testFactory() | ||
{ | ||
$auth = $this->createMock(AuthInterface::class); | ||
$assemblyService = AssemblyWaitForResourceServiceFactory::create($auth); | ||
|
||
$this->assertInstanceOf(AssemblyWaitForResourceService::class, $assemblyService); | ||
} | ||
|
||
public function provider() | ||
{ | ||
yield [Status::ASSEMBLY_EXECUTING, Status::ASSEMBLY_COMPLETED, $this->once()]; | ||
yield [Status::ASSEMBLY_UPLOADING, Status::ASSEMBLY_COMPLETED, $this->once()]; | ||
yield [Status::ASSEMBLY_COMPLETED, Status::ASSEMBLY_COMPLETED, $this->never()]; | ||
} | ||
} |