Skip to content

Commit af7b637

Browse files
add tests
1 parent ae673af commit af7b637

18 files changed

Lines changed: 520 additions & 89 deletions

.github/workflows/_test-code-samples.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/_test-integrations.yml

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
matrix:
3030
php-version:
3131
- 8.1
32-
- 8.4
32+
- 8.5
3333
runs-on: "ubuntu-latest"
3434
steps:
3535
- uses: actions/checkout@v4
@@ -55,37 +55,36 @@ jobs:
5555
run: |
5656
./vendor/bin/phpunit -c tests/functional.xml
5757
58-
# MacOS testing disabled because of capricious GS/ImageMagick/Homebrew behaviors
59-
# integration-tests-macos:
60-
# name: Run Integration Tests on MacOS
61-
# timeout-minutes: 30
62-
# strategy:
63-
# max-parallel: 2
64-
# matrix:
65-
# php-version:
66-
# - 8.1
67-
# - 8.4
68-
# runs-on: "macos-latest"
69-
# steps:
70-
# - uses: actions/checkout@v4
71-
# with:
72-
# submodules: recursive
73-
# - name: Set up php ${{ matrix.php-version }}
74-
# uses: shivammathur/setup-php@v2
75-
# env:
76-
# phpts: zts
77-
# with:
78-
# php-version: ${{ matrix.php-version }}
79-
# extensions: curl, fileinfo, json, imagick
80-
# - name: Install ImageMagick
81-
# run: |
82-
# brew update
83-
# brew install imagemagick
84-
# - uses: ramsey/composer-install@v2
85-
# - name: Unit testing with phpunit
86-
# run: |
87-
# ./vendor/bin/phpunit -c tests/functional.xml
88-
#
58+
integration-tests-macos:
59+
name: Run Integration Tests on MacOS
60+
timeout-minutes: 30
61+
strategy:
62+
max-parallel: 2
63+
matrix:
64+
php-version:
65+
- 8.1
66+
- 8.5
67+
runs-on: "macos-latest"
68+
steps:
69+
- uses: actions/checkout@v4
70+
with:
71+
submodules: recursive
72+
- name: Set up php ${{ matrix.php-version }}
73+
uses: shivammathur/setup-php@v2
74+
env:
75+
phpts: zts
76+
with:
77+
php-version: ${{ matrix.php-version }}
78+
extensions: curl, fileinfo, json, imagick
79+
- name: Install ImageMagick
80+
run: |
81+
brew update
82+
brew install imagemagick
83+
- uses: ramsey/composer-install@v2
84+
- name: Unit testing with phpunit
85+
run: |
86+
./vendor/bin/phpunit -c tests/functional.xml
87+
8988
9089
integration-tests-windows:
9190
name: Run Integration Tests on Windows
@@ -95,7 +94,7 @@ jobs:
9594
matrix:
9695
php-version:
9796
- 8.1
98-
- 8.4
97+
- 8.5
9998
runs-on: "windows-latest"
10099
steps:
101100
- uses: actions/checkout@v4

.github/workflows/_test-smoke.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Smoke tests
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
MINDEE_ACCOUNT_SE_TESTS: ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }}
9+
MINDEE_ENDPOINT_SE_TESTS: ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}
10+
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
11+
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
12+
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
13+
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
14+
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
15+
MINDEE_V2_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
16+
MINDEE_V2_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
17+
MINDEE_V2_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
18+
MINDEE_V2_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
19+
20+
jobs:
21+
test:
22+
name: Run Code Samples
23+
timeout-minutes: 30
24+
strategy:
25+
max-parallel: 2
26+
matrix:
27+
php-version:
28+
- "8.1"
29+
- "8.5"
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
submodules: recursive
35+
36+
- name: Set up Php ${{ matrix.php-version }}
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php-version }}
40+
- uses: ramsey/composer-install@v2
41+
42+
- name: Tests V1 code samples
43+
run: |
44+
./tests/test_v1_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}
45+
46+
- name: Tests V2 code samples
47+
run: |
48+
./tests/test_v2_code_samples.sh

.github/workflows/_test-units.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- 8.2
1515
- 8.3
1616
- 8.4
17+
- 8.5
1718
runs-on: "ubuntu-latest"
1819
steps:
1920
- uses: actions/checkout@v4

.github/workflows/cron.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ on:
66

77
jobs:
88
test-code-samples:
9-
uses: mindee/mindee-api-php/.github/workflows/_test-code-samples.yml@main
9+
uses: mindee/mindee-api-php/.github/workflows/_test-smoke.yml@main
1010
secrets: inherit

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ jobs:
2222
needs: test-units
2323
secrets: inherit
2424
test-code-samples:
25-
uses: ./.github/workflows/_test-code-samples.yml
25+
uses: ./.github/workflows/_test-smoke.yml
2626
needs: test-units
2727
secrets: inherit
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Mindee\ClientV2;
4+
use Mindee\V2\Product\Classification\Params\ClassificationParameters;
5+
use Mindee\V2\Product\Classification\ClassificationResponse;
6+
use Mindee\Input\PathInput;
7+
8+
$apiKey = "MY_API_KEY";
9+
$filePath = "/path/to/the/file.ext";
10+
$modelId = "MY_MODEL_ID";
11+
12+
// Init a new client
13+
$mindeeClient = new ClientV2($apiKey);
14+
15+
// Set classification parameters
16+
// Note: modelId is mandatory.
17+
$classificationParams = new ClassificationParameters(
18+
// ID of the model, required.
19+
$modelId,
20+
);
21+
22+
// Load a file from disk
23+
$inputSource = new PathInput($filePath);
24+
25+
// Upload the file
26+
$response = $mindeeClient->enqueueAndGetResult(
27+
ClassificationResponse::class,
28+
$inputSource,
29+
$classificationParams
30+
);
31+
32+
// Print a summary of the response
33+
echo strval($response->inference);
34+
35+
36+
// Access the classification results
37+
$classification = $response->inference->result->classification;

docs/code_samples/v2_crop.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Mindee\ClientV2;
4+
use Mindee\V2\Product\Crop\Params\CropParameters;
5+
use Mindee\V2\Product\Crop\CropResponse;
6+
use Mindee\Input\PathInput;
7+
8+
$apiKey = "MY_API_KEY";
9+
$filePath = "/path/to/the/file.ext";
10+
$modelId = "MY_MODEL_ID";
11+
12+
// Init a new client
13+
$mindeeClient = new ClientV2($apiKey);
14+
15+
// Set crop parameters
16+
// Note: modelId is mandatory.
17+
$cropParams = new CropParameters(
18+
// ID of the model, required.
19+
$modelId,
20+
);
21+
22+
// Load a file from disk
23+
$inputSource = new PathInput($filePath);
24+
25+
// Upload the file
26+
$response = $mindeeClient->enqueueAndGetResult(
27+
CropResponse::class,
28+
$inputSource,
29+
$cropParams
30+
);
31+
32+
// Print a summary of the response
33+
echo strval($response->inference);
34+
35+
36+
// Access the crop results
37+
$crops = $response->inference->result->crops;
File renamed without changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use Mindee\ClientV2;
4+
use Mindee\Input\InferenceParameters;
5+
use Mindee\Input\PathInput;
6+
7+
$apiKey = "MY_API_KEY";
8+
$filePath = "/path/to/the/file.ext";
9+
$modelId = "MY_MODEL_ID";
10+
11+
// Init a new client
12+
$mindeeClient = new ClientV2($apiKey);
13+
14+
// Set inference parameters
15+
// Note: modelId is mandatory.
16+
$inferenceParams = new InferenceParameters(
17+
// ID of the model, required.
18+
$modelId,
19+
20+
// Options: set to `true` or `false` to override defaults
21+
22+
// Enhance extraction accuracy with Retrieval-Augmented Generation.
23+
rag: null,
24+
// Extract the full text content from the document as strings.
25+
rawText: null,
26+
// Calculate bounding box polygons for all fields.
27+
polygon: null,
28+
// Boost the precision and accuracy of all extractions.
29+
// Calculate confidence scores for all fields.
30+
confidence: null
31+
);
32+
33+
// Load a file from disk
34+
$inputSource = new PathInput($filePath);
35+
36+
// Upload the file
37+
$response = $mindeeClient->enqueueInference(
38+
$inputSource,
39+
$inferenceParams
40+
);
41+
42+
// Print the job ID
43+
echo strval($response->job->id);
44+
45+
// IMPORTANT: save a record of which job ID corresponds to which file.

0 commit comments

Comments
 (0)