From f262146ad157342a568887962573ebda6e8f515d Mon Sep 17 00:00:00 2001 From: Ondrej Popelka Date: Tue, 16 Sep 2025 15:20:00 +0200 Subject: [PATCH] - fix tests broken due to storage update - fix tests namespaces & more unified setup with other libraries --- .gitignore | 3 ++- README.md | 2 +- composer.json | 5 +++-- docker-compose.yml | 3 +++ phpunit.xml.dist | 4 ++-- tests/{phpunit => }/ActionDataTest.php | 0 tests/{phpunit => }/ClientFunctionalTest.php | 10 +++++----- tests/{phpunit => }/ClientTest.php | 0 tests/bootstrap.php | 19 +++++++++++++++++++ tests/phpunit/bootstrap.php | 5 ----- 10 files changed, 35 insertions(+), 16 deletions(-) rename tests/{phpunit => }/ActionDataTest.php (100%) rename tests/{phpunit => }/ClientFunctionalTest.php (85%) rename tests/{phpunit => }/ClientTest.php (100%) create mode 100644 tests/bootstrap.php delete mode 100644 tests/phpunit/bootstrap.php diff --git a/.gitignore b/.gitignore index 839c63b..09cbbfe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /data .phpunit.result.cache composer.lock -.env \ No newline at end of file +.env +/.env.local diff --git a/README.md b/README.md index 2a476ae..a45a6a0 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ docker-compose build docker-compose run --rm dev composer install --no-scripts ``` -Create `.env` file with following contents: +Create `.env.local` file with following contents: ```shell KBC_SYNC_ACTIONS_URL=https://sync-actions.keboola.com/ diff --git a/composer.json b/composer.json index d4cc451..6e81457 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "keboola/php-temp": "^2.0", "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^9.5", - "symfony/process": "^5.0" + "symfony/process": "^5.0", + "symfony/dotenv": "^5.0" }, "autoload": { "psr-4": { @@ -25,7 +26,7 @@ }, "autoload-dev": { "psr-4": { - "Keboola\\SyncActionsClient\\Tests\\": "tests/phpunit/" + "Keboola\\SyncActionsClient\\Tests\\": "tests/" } }, "scripts": { diff --git a/docker-compose.yml b/docker-compose.yml index f25274f..20069dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,3 +7,6 @@ services: environment: - KBC_SYNC_ACTIONS_URL - KBC_TOKEN + env_file: + - .env + - .env.local diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ee73999..ac3e5c6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,8 +7,8 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - bootstrap="tests/phpunit/bootstrap.php"> + bootstrap="tests/bootstrap.php"> - tests/phpunit + tests diff --git a/tests/phpunit/ActionDataTest.php b/tests/ActionDataTest.php similarity index 100% rename from tests/phpunit/ActionDataTest.php rename to tests/ActionDataTest.php diff --git a/tests/phpunit/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php similarity index 85% rename from tests/phpunit/ClientFunctionalTest.php rename to tests/ClientFunctionalTest.php index 54b9692..c937e02 100644 --- a/tests/phpunit/ClientFunctionalTest.php +++ b/tests/ClientFunctionalTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Keboola\ExDbSnowflake\Tests; +namespace Keboola\SyncActionsClient\Tests; use Keboola\SyncActionsClient\ActionData; use Keboola\SyncActionsClient\Client; @@ -56,8 +56,8 @@ public function testInvalidComponent(): void $client = $this->getClient(); self::expectException(ClientException::class); - self::expectExceptionMessage('Component unexistComponent not found'); - $client->callAction(new ActionData('unexistComponent', 'unexistAction', [])); + self::expectExceptionMessage('Component \"non-existent-component\" not found'); + $client->callAction(new ActionData('non-existent-component', 'unexistAction', [])); } public function testInvalidAction(): void @@ -66,10 +66,10 @@ public function testInvalidAction(): void self::expectException(ClientException::class); self::expectExceptionMessage(sprintf( - 'Action \"unexistAction\" not defined for component \"%s\".', + 'Action \"non-existent-action\" not defined for component \"%s\".', self::COMPONENT_ID, )); - $client->callAction(new ActionData(self::COMPONENT_ID, 'unexistAction', [])); + $client->callAction(new ActionData(self::COMPONENT_ID, 'non-existent-action', [])); } private function getClient(): Client diff --git a/tests/phpunit/ClientTest.php b/tests/ClientTest.php similarity index 100% rename from tests/phpunit/ClientTest.php rename to tests/ClientTest.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..c350ce4 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,19 @@ +usePutenv(true)->bootEnv(dirname(__DIR__).'/.env.local', 'dev', []); +} + +$requiredEnvs = ['KBC_SYNC_ACTIONS_URL', 'KBC_TOKEN']; + +foreach ($requiredEnvs as $env) { + if (empty(getenv($env))) { + throw new Exception(sprintf('The "%s" environment variable is empty.', $env)); + } +} diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php deleted file mode 100644 index 7d169dc..0000000 --- a/tests/phpunit/bootstrap.php +++ /dev/null @@ -1,5 +0,0 @@ -