Skip to content

Commit af6030c

Browse files
🐛 fix curl lib not registering webhooks correctly
1 parent 9b5b056 commit af6030c

6 files changed

Lines changed: 84 additions & 12 deletions

File tree

.github/workflows/_test-integrations.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ env:
1313
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
1414
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
1515
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
16-
MINDEE_V2_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
16+
MINDEE_V2_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_WEBHOOK_ID }}
17+
MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
1718
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
1819
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
1920
MINDEE_V2_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}

src/V2/ClientOptions/BaseParameters.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,9 @@ public function asHash(): array
6363
$outHash['alias'] = $this->alias;
6464
}
6565

66+
6667
if (isset($this->webhooksIds) && count($this->webhooksIds) > 0) {
67-
if (PHP_VERSION_ID < 80200 && count($this->webhooksIds) > 1) {
68-
// NOTE: see https://bugs.php.net/bug.php?id=51634
69-
error_log("PHP version is too low to support webbook array destructuring.
70-
\nOnly the first webhook ID will be sent to the server.");
71-
$outHash['webhook_ids'] = $this->webhooksIds[0];
72-
} else {
73-
foreach ($this->webhooksIds as $webhookId) {
74-
$outHash['webhook_ids[]'] = $webhookId;
75-
}
76-
}
68+
$outHash['webhook_ids'] = implode(',', $this->webhooksIds);
7769
}
7870
return $outHash;
7971
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace V2\ClientOptions;
4+
5+
use Mindee\V2\ClientOptions\BaseParameters;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class BaseParametersTest extends TestCase
9+
{
10+
public function testAsHashShouldSerializeMultipleWebhookIdsAsIndexedFields(): void
11+
{
12+
$params = new class ('model-id', null, ['first-id', 'second-id'], null) extends BaseParameters {
13+
public static string $slug = 'test';
14+
};
15+
16+
$hash = $params->asHash();
17+
18+
$this->assertArrayHasKey('model_id', $hash);
19+
$this->assertArrayHasKey('webhook_ids[0]', $hash);
20+
$this->assertArrayHasKey('webhook_ids[1]', $hash);
21+
$this->assertSame('model-id', $hash['model_id']);
22+
$this->assertSame('first-id', $hash['webhook_ids[0]']);
23+
$this->assertSame('second-id', $hash['webhook_ids[1]']);
24+
}
25+
}

tests/V2/ClientV2TestFunctional.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ public function testUrlInputSourceMustNotRaiseErrors(): void
177177
$this->assertNotNull($result);
178178
}
179179

180-
public function testDataSchemaMustSucceed(): void {
180+
public function testDataSchemaMustSucceed(): void
181+
{
181182

182183
$source = new PathInput(
183184
TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'
@@ -214,4 +215,18 @@ public function testDataSchemaMustSucceed(): void {
214215
$result->fields['test_replace']->value
215216
);
216217
}
218+
219+
public function testMultipleWebhooksMustSucceed(): void
220+
{
221+
$source = new PathInput(
222+
TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'
223+
);
224+
225+
$inferenceParams = new InferenceParameters($this->modelId, webhooksIds: [
226+
getenv('MINDEE_V2_FAILURE_WEBHOOK_ID'),
227+
getenv('MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID')]
228+
);
229+
$response = $this->mindeeClient->enqueue($source, $inferenceParams);
230+
$this->assertEquals(2, count($response->job->webhooks));
231+
}
217232
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace V2\Http;
4+
5+
use Mindee\Http\MindeeApiV2;
6+
use PHPUnit\Framework\TestCase;
7+
use ReflectionClass;
8+
9+
class MindeeApiV2MultipartTest extends TestCase
10+
{
11+
public function testMultipartPayloadShouldRepeatWebhookIdsKeyForEachWebhook(): void
12+
{
13+
$api = new MindeeApiV2('dummy-api-key');
14+
$reflectionClass = new ReflectionClass($api);
15+
$method = $reflectionClass->getMethod('buildMultipartPayload');
16+
$method->setAccessible(true);
17+
18+
$payload = $method->invoke(
19+
$api,
20+
[
21+
'model_id' => 'model-id',
22+
'file' => new \CURLFile(
23+
__DIR__ . '/../../resources/file_types/pdf/blank_1.pdf',
24+
'application/pdf',
25+
'blank_1.pdf'
26+
),
27+
],
28+
['webhook-1', 'webhook-2']
29+
);
30+
31+
$this->assertIsArray($payload);
32+
$this->assertNotEmpty($payload['boundary']);
33+
$this->assertStringContainsString('webhook-1', $payload['body']);
34+
$this->assertStringContainsString('webhook-2', $payload['body']);
35+
$this->assertSame(1, substr_count($payload['body'], 'name="webhook_ids"'));
36+
}
37+
}

tests/V2/Parsing/JobResponseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function testShouldLoadWhenStatusIsProcessing(): void
3939
$this->assertSame('Processing', $response->job->status);
4040
$this->assertNull($response->job->completedAt);
4141
$this->assertNull($response->job->error);
42+
$this->assertIsArray($response->job->webhooks);
43+
$this->assertCount(0, $response->job->webhooks);
4244
}
4345

4446
/**

0 commit comments

Comments
 (0)