Skip to content

Commit 8c4eb65

Browse files
committed
WIP
1 parent b9c4a66 commit 8c4eb65

File tree

9 files changed

+84
-31
lines changed

9 files changed

+84
-31
lines changed

databox/api/src/Border/UploaderClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use Symfony\Contracts\HttpClient\HttpClientInterface;
88

9-
readonly class UploaderClient
9+
class UploaderClient
1010
{
11-
public function __construct(private HttpClientInterface $client)
11+
public function __construct(private readonly HttpClientInterface $client)
1212
{
1313
}
1414

databox/api/src/Border/UploaderClientMock.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,42 @@
77

88
#[When('test')]
99
#[AsAlias(id: UploaderClient::class)]
10-
readonly class UploaderClientMock extends UploaderClient
10+
class UploaderClientMock extends UploaderClient
1111
{
12+
private array $acknowledgedAssets = [];
13+
1214
public function getCommit(string $baseUrl, string $id, string $token): array
1315
{
1416
return [
1517
'id' => $id,
1618
'userId' => 'test_user',
17-
'assets' => [],
19+
'assets' => [
20+
'42',
21+
],
22+
];
23+
}
24+
25+
public function getAsset(string $baseUrl, string $id, string $token): array
26+
{
27+
return [
28+
'originalName' => 'test_file.txt',
29+
'mimeType' => 'text/plain',
30+
'size' => 42,
31+
'url' => 'http://localhost/path/to/test_file.txt',
32+
'data' => [
33+
],
34+
'formData' => [
35+
],
1836
];
1937
}
38+
39+
public function ackAsset(string $baseUrl, string $id, string $token): void
40+
{
41+
$this->acknowledgedAssets[] = $id;
42+
}
43+
44+
public function getAcknowledgedAssets(): array
45+
{
46+
return $this->acknowledgedAssets;
47+
}
2048
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Border;
6+
7+
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
8+
use Symfony\Component\DependencyInjection\Attribute\When;
9+
10+
#[When('test')]
11+
#[AsAlias(id: UriDownloader::class)]
12+
readonly class UriDownloaderMock extends UriDownloader
13+
{
14+
/**
15+
* @return string The temporary file path
16+
*/
17+
public function download(string $uri, array &$headers = []): string
18+
{
19+
$tmpFile = sys_get_temp_dir().'/'.uniqid('incoming-file');
20+
$fileHandler = fopen($tmpFile, 'w');
21+
fwrite($fileHandler, 'foo');
22+
fclose($fileHandler);
23+
24+
return $tmpFile;
25+
}
26+
}

databox/api/tests/AbstractDataboxTestCase.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ abstract class AbstractDataboxTestCase extends ApiTestCase
1717

1818
protected static function bootKernel(array $options = []): KernelInterface
1919
{
20-
if (static::$kernel) {
21-
return static::$kernel;
22-
}
23-
static::bootKernelWithFixtures($options);
24-
25-
return static::$kernel;
20+
return static::bootKernelWithFixtures($options);
2621
}
2722
}

databox/api/tests/Integration/Aws/Transcribe/AwsTranscribeEventTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ private function assertHasData(string $integrationId, string $name, int $expecte
108108

109109
protected static function bootKernel(array $options = []): KernelInterface
110110
{
111-
if (static::$kernel) {
112-
return static::$kernel;
113-
}
114-
static::bootKernelWithFixtures($options);
115-
116-
return static::$kernel;
111+
return static::bootKernelWithFixtures($options);
117112
}
118113

119114
public function testNotificationWillBeHandled(): void

databox/api/tests/Integration/Phrasea/Uploader/UploaderIntegrationTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
use Alchemy\TestBundle\Helper\FixturesTrait;
66
use Alchemy\TestBundle\Helper\TestServicesTrait;
77
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
8+
use App\Border\UploaderClient;
9+
use App\Border\UploaderClientMock;
810
use App\Entity\Core\Workspace;
911
use App\Entity\Integration\WorkspaceIntegration;
1012
use App\Integration\Phrasea\Uploader\UploaderIntegration;
13+
use App\Repository\Core\AssetRepository;
1114
use App\Tests\FileUploadTrait;
1215
use App\Tests\Rendition\Phraseanet\PhraseanetApiClientFactoryMock;
1316
use Doctrine\ORM\EntityManagerInterface;
17+
use Symfony\Component\HttpKernel\KernelInterface;
1418

1519
class UploaderIntegrationTest extends ApiTestCase
1620
{
@@ -23,8 +27,6 @@ public function testUploaderCanTriggerIntegrationEndpoint(): void
2327
self::enableFixtures();
2428
$apiClient = static::createClient();
2529

26-
$queueName = 'p2';
27-
$inMemoryTransport = $this->interceptMessengerEvents($queueName);
2830
$em = self::getService(EntityManagerInterface::class);
2931
/** @var PhraseanetApiClientFactoryMock $clientFactory */
3032

@@ -65,5 +67,22 @@ public function testUploaderCanTriggerIntegrationEndpoint(): void
6567
'json' => $payload,
6668
]);
6769
$this->assertEquals(200, $response->getStatusCode());
70+
71+
$em->clear();
72+
$assetRepo = $this->getService(AssetRepository::class);
73+
$asset = $assetRepo->findOneBy([
74+
'title' => 'test_file.txt',
75+
]);
76+
$this->assertNotNull($asset);
77+
$this->assertEquals('test_file.txt', $asset->getTitle());
78+
79+
/** @var UploaderClientMock $uploadClient */
80+
$uploadClient = $this->getService(UploaderClient::class);
81+
$this->assertCount(1, $uploadClient->getAcknowledgedAssets());
82+
}
83+
84+
protected static function bootKernel(array $options = []): KernelInterface
85+
{
86+
return static::bootKernelWithFixtures($options);
6887
}
6988
}

databox/api/tests/Rendition/Phraseanet/PhraseanetRenditionApiV3SubDefMethodTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ class PhraseanetRenditionApiV3SubDefMethodTest extends ApiTestCase
2626

2727
protected static function bootKernel(array $options = []): KernelInterface
2828
{
29-
if (static::$kernel) {
30-
return static::$kernel;
31-
}
32-
static::bootKernelWithFixtures($options);
33-
34-
return static::$kernel;
29+
return static::bootKernelWithFixtures($options);
3530
}
3631

3732
public function testApiV3SubDefIsTriggered(): void

databox/api/tests/Rendition/Phraseanet/PhraseanetRenditionEnqueueMethodTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ class PhraseanetRenditionEnqueueMethodTest extends ApiTestCase
2828

2929
protected static function bootKernel(array $options = []): KernelInterface
3030
{
31-
if (static::$kernel) {
32-
return static::$kernel;
33-
}
34-
static::bootKernelWithFixtures($options);
35-
36-
return static::$kernel;
31+
return static::bootKernelWithFixtures($options);
3732
}
3833

3934
public function testEnqueueIsTriggered(): void

databox/api/tests/Search/SearchTestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait SearchTestTrait
2020

2121
protected static function bootSearch(KernelInterface $kernel): void
2222
{
23-
$container = static::getContainer() ?? static::$kernel->getContainer();
23+
$container = static::getContainer() ?? $kernel->getContainer();
2424

2525
$indexes = [
2626
'asset',

0 commit comments

Comments
 (0)