diff --git a/.github/workflows/_static-analysis.yml b/.github/workflows/_static-analysis.yml index aaadd839..3058f84a 100644 --- a/.github/workflows/_static-analysis.yml +++ b/.github/workflows/_static-analysis.yml @@ -34,11 +34,3 @@ jobs: - name: Run lint run: | composer lint - - - name: Run PHPStan - run: | - composer phpstan - - - name: Run Rector - run: | - composer rector:check diff --git a/bin/MindeeCLICommand.php b/bin/MindeeCliCommand.php similarity index 99% rename from bin/MindeeCLICommand.php rename to bin/MindeeCliCommand.php index c2e0636d..3476f4e8 100644 --- a/bin/MindeeCLICommand.php +++ b/bin/MindeeCliCommand.php @@ -33,7 +33,7 @@ /** * Configuration Class for CLI. */ -class MindeeCLICommand extends Command +class MindeeCliCommand extends Command { /** * @var array $documentList Array of document configurations. diff --git a/bin/MindeeCLIDocuments.php b/bin/MindeeCliDocuments.php similarity index 99% rename from bin/MindeeCLIDocuments.php rename to bin/MindeeCliDocuments.php index 5ce217ab..20d72da3 100644 --- a/bin/MindeeCLIDocuments.php +++ b/bin/MindeeCliDocuments.php @@ -34,7 +34,7 @@ /** * Document specifications for CLI usage. */ -class MindeeCLIDocuments +class MindeeCliDocuments { /** * @return array Specifications for each Mindee Document, for CLI usage. diff --git a/bin/cli.php b/bin/cli.php index 859d9766..c64c6ea8 100755 --- a/bin/cli.php +++ b/bin/cli.php @@ -5,14 +5,14 @@ namespace Mindee\Cli; require __DIR__ . '/../vendor/autoload.php'; -require __DIR__ . '/MindeeCLIDocuments.php'; -require __DIR__ . '/MindeeCLICommand.php'; +require __DIR__ . '/MindeeCliDocuments.php'; +require __DIR__ . '/MindeeCliCommand.php'; use Symfony\Component\Console\Application; use Exception; $cli = new Application(); -$mindeeCommand = new MindeeCLICommand(MindeeCLIDocuments::getSpecs()); +$mindeeCommand = new MindeeCliCommand(MindeeCliDocuments::getSpecs()); $cli->add($mindeeCommand); try { $cli->add($mindeeCommand); diff --git a/composer.json b/composer.json index f18cb53b..6cdf6d7e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "madewithlove/license-checker": "^v1.0", "phpstan/phpstan": "^2.1", "phpstan/phpstan-deprecation-rules": "^2.0", - "rector/rector": "^2.4" + "rector/rector": "^2.4", + "projektgopher/whisky": "^0.7.4" }, "suggest": { "ext-imagick": "Required for PDF rasterization and image processing features", @@ -35,10 +36,23 @@ "bin/cli.php" ], "scripts": { - "lint": "php-cs-fixer fix --dry-run --diff", - "phpstan": "phpstan analyse src --level 6", - "format": "php-cs-fixer fix", - "rector": "rector process src tests", - "rector:check": "rector process src tests --dry-run" + "lint:cs-fixer": "php-cs-fixer fix --dry-run --diff", + "lint:rector": "rector process src tests --dry-run", + "lint:phpstan": "phpstan analyse", + "lint": [ + "@lint:phpstan", + "@lint:cs-fixer", + "@lint:rector" + ], + "format:cs-fixer": "php-cs-fixer fix", + "format:rector": "rector process src tests", + "format": [ + "@format:cs-fixer", + "@format:rector" + ], + "test:unit": "phpunit -c tests/phpunit.xml", + "test:functional": "phpunit -c tests/functional.xml", + "test:smoke:v1": "./tests/test_v1_code_samples.sh", + "test:smoke:v2": "./tests/test_v2_code_samples.sh" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..6e451faa --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 6 + paths: + - src diff --git a/src/V1/Http/BaseApi.php b/src/V1/Http/BaseApi.php index fafb1b4f..a16a91c8 100644 --- a/src/V1/Http/BaseApi.php +++ b/src/V1/Http/BaseApi.php @@ -21,7 +21,7 @@ /** * Default URL prefix for API calls. */ -const BASE_URL_DEFAULT = 'https://api.mindee.net/v1'; +const BASE_URL_DEFAULT = 'https://api.mindee.net'; /** * Default key name for CURL request timeout in environment variables. diff --git a/src/V1/Http/BaseEndpoint.php b/src/V1/Http/BaseEndpoint.php index 1439f57e..da2b61d6 100644 --- a/src/V1/Http/BaseEndpoint.php +++ b/src/V1/Http/BaseEndpoint.php @@ -64,7 +64,7 @@ public function setFinalCurlOpts( ?string $workflowId = null ): array { if (isset($workflowId)) { - $url = $this->settings->baseUrl . "/workflows/" . $workflowId . $suffix; + $url = $this->settings->baseUrl . "/v1/workflows/" . $workflowId . $suffix; } else { $url = $this->settings->urlRoot . $suffix; } diff --git a/src/V1/Http/MindeeApi.php b/src/V1/Http/MindeeApi.php index af0b7f06..57983b22 100644 --- a/src/V1/Http/MindeeApi.php +++ b/src/V1/Http/MindeeApi.php @@ -58,6 +58,6 @@ public function __construct( $this->urlRoot = rtrim( $this->baseUrl, "/" - ) . "/products/$this->accountName/$this->endpointName/v$this->version"; + ) . "/v1/products/$this->accountName/$this->endpointName/v$this->version"; } } diff --git a/src/V1/Http/MindeeWorkflowApi.php b/src/V1/Http/MindeeWorkflowApi.php index bff07d07..d74f271e 100644 --- a/src/V1/Http/MindeeWorkflowApi.php +++ b/src/V1/Http/MindeeWorkflowApi.php @@ -36,6 +36,6 @@ public function __construct( $this->urlRoot = rtrim( $this->baseUrl, "/" - ) . "/workflows/$this->workflowId/executions"; + ) . "/v1/workflows/$this->workflowId/executions"; } } diff --git a/src/V2/Http/MindeeApiV2.php b/src/V2/Http/MindeeApiV2.php index 2d3fbfa1..4aa728c1 100644 --- a/src/V2/Http/MindeeApiV2.php +++ b/src/V2/Http/MindeeApiV2.php @@ -50,7 +50,7 @@ /** * Default URL prefix for API calls. */ -const API_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net/v2'; +const API_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net'; /** * Default key name for CURL request timeout in environment variables. @@ -241,7 +241,7 @@ private function processJobResponse(array $result): JobResponse */ public function reqGetJob(string $jobId): JobResponse { - $response = $this->sendGetRequest($this->baseUrl . "/jobs/$jobId"); + $response = $this->sendGetRequest($this->baseUrl . "/v2/jobs/$jobId"); return $this->processJobResponse($response); } @@ -268,7 +268,7 @@ public function reqGetResult( $e ); } - $url = $this->baseUrl . "/products/{$slugProperty->getValue()}/results/$resultId"; + $url = $this->baseUrl . "/v2/products/{$slugProperty->getValue()}/results/$resultId"; $response = $this->sendGetRequest($url); return $this->processResponse($responseClass, $response); } @@ -352,7 +352,7 @@ private function documentEnqueuePost( $inputSource->checkNeedsFix(); $postFields['file'] = $inputSource->fileObject; } - $url = $this->baseUrl . "/products/{$params::$slug}/enqueue"; + $url = $this->baseUrl . "/v2/products/{$params::$slug}/enqueue"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $resp = [ diff --git a/tests/V1/CLI/MindeeCLICommandTest.php b/tests/V1/Cli/MindeeCliCommandTest.php similarity index 79% rename from tests/V1/CLI/MindeeCLICommandTest.php rename to tests/V1/Cli/MindeeCliCommandTest.php index 9d9cde6e..f88b449e 100644 --- a/tests/V1/CLI/MindeeCLICommandTest.php +++ b/tests/V1/Cli/MindeeCliCommandTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace V1\CLI; +namespace V1\Cli; use PHPUnit\Framework\TestCase; use TestingUtilities; -require_once(__DIR__ . "/MindeeCLITestingUtilities.php"); +require_once(__DIR__ . "/MindeeCliTestingUtilities.php"); -class MindeeCLICommandTest extends TestCase +class MindeeCliCommandTest extends TestCase { private string $apiKey; private string $filePath; @@ -22,21 +22,21 @@ protected function setUp(): void public function testInvalidFilePath(): void { - $cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]); + $cmdOutput = MindeeCliTestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]); self::assertSame(1, $cmdOutput["code"]); self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid path or url provided 'invalid-file-path'.")); } public function testInvalidKey(): void { - $cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", $this->filePath, "-k", "invalid-key"]); + $cmdOutput = MindeeCliTestingUtilities::executeTest(["financial-document", $this->filePath, "-k", "invalid-key"]); self::assertSame(1, $cmdOutput["code"]); self::assertTrue(str_contains(implode(" ", $cmdOutput["output"]), "Invalid token provided")); } public function testInvalidProduct(): void { - $cmdOutput = MindeeCLITestingUtilities::executeTest(["invalid-product", $this->filePath, "-k", "invalid-key", "-D"]); + $cmdOutput = MindeeCliTestingUtilities::executeTest(["invalid-product", $this->filePath, "-k", "invalid-key", "-D"]); self::assertSame(1, $cmdOutput["code"]); self::assertTrue(str_contains((string) $cmdOutput["output"][0], "Invalid product: invalid-product")); } diff --git a/tests/V1/CLI/MindeeCLICommandTestFunctional.php b/tests/V1/Cli/MindeeCliCommandTestFunctional.php similarity index 84% rename from tests/V1/CLI/MindeeCLICommandTestFunctional.php rename to tests/V1/Cli/MindeeCliCommandTestFunctional.php index f5169c14..59b6de26 100644 --- a/tests/V1/CLI/MindeeCLICommandTestFunctional.php +++ b/tests/V1/Cli/MindeeCliCommandTestFunctional.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace V1\CLI; +namespace V1\Cli; require_once(__DIR__ . "/../../../vendor/autoload.php"); -require_once(__DIR__ . "/../../../bin/MindeeCLIDocuments.php"); +require_once(__DIR__ . "/../../../bin/MindeeCliDocuments.php"); require_once(__DIR__ . "/../../TestingUtilities.php"); -require_once(__DIR__ . "/MindeeCLITestingUtilities.php"); +require_once(__DIR__ . "/MindeeCliTestingUtilities.php"); -use Mindee\Cli\MindeeCLIDocuments; +use Mindee\Cli\MindeeCliDocuments; use PHPUnit\Framework\TestCase; use TestingUtilities; -class MindeeCLICommandTestFunctional extends TestCase +class MindeeCliCommandTestFunctional extends TestCase { private string $apiKey; @@ -32,7 +32,7 @@ private function runValidCall($productName, $async = false, $initialArgs = []): if ($async) { $args[] = "-A"; } - return MindeeCLITestingUtilities::executeTest($args); + return MindeeCliTestingUtilities::executeTest($args); } @@ -41,7 +41,7 @@ public static function provideProductCases(): iterable $data = []; $data[] = ["generated", true, ["-a", "mindee", "-e", "invoice_splitter", "-d", "1"]]; /** @phpstan-ignore-next-line */ - foreach (MindeeCLIDocuments::getSpecs() as $productName => $productSpecs) { + foreach (MindeeCliDocuments::getSpecs() as $productName => $productSpecs) { if ($productName !== "custom" && $productName !== "generated") { if ($productSpecs->isSync) { $data[] = [$productName, false]; diff --git a/tests/V1/CLI/MindeeCLITestingUtilities.php b/tests/V1/Cli/MindeeCliTestingUtilities.php similarity index 92% rename from tests/V1/CLI/MindeeCLITestingUtilities.php rename to tests/V1/Cli/MindeeCliTestingUtilities.php index b6247db1..34e8a257 100644 --- a/tests/V1/CLI/MindeeCLITestingUtilities.php +++ b/tests/V1/Cli/MindeeCliTestingUtilities.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace V1\CLI; +namespace V1\Cli; -class MindeeCLITestingUtilities +class MindeeCliTestingUtilities { public static function executeTest($args, $mute = false) { diff --git a/whisky.json b/whisky.json new file mode 100644 index 00000000..a601d98e --- /dev/null +++ b/whisky.json @@ -0,0 +1,11 @@ +{ + "disabled": [], + "hooks": { + "pre-commit": [ + "composer lint" + ], + "pre-push": [ + "composer test:unit" + ] + } +}