diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 8170f99..d3d90b8 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -15,11 +15,8 @@ jobs: strategy: fail-fast: false matrix: - phpVersion: [7.4, 8.0, 8.1] + phpVersion: [8.1, 8.2, 8.3] symfonyVersion: ["5.4.*", "6.1.*"] - exclude: - - phpVersion: 7.4 - symfonyVersion: "6.1.*" steps: - diff --git a/composer.json b/composer.json index f395685..44b084e 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ } }, "require": { - "php": "^7.4|^8.0", + "php": ">=8.1", "ext-json": "*", "keboola/common-exceptions": "^1.2", "monolog/monolog": "^2.3", diff --git a/src/Config/BaseConfig.php b/src/Config/BaseConfig.php index 27a1d56..c30ca55 100644 --- a/src/Config/BaseConfig.php +++ b/src/Config/BaseConfig.php @@ -289,4 +289,19 @@ public function getEnvKbcUrl(): string } return (string) $env; } + + public function getDataTypeSupport(): DatatypeSupport + { + $env = getenv('KBC_DATA_TYPE_SUPPORT'); + if (!$env) { + return DatatypeSupport::NONE; + } + $datatypeSupport = DatatypeSupport::tryFrom($this->getStringValue([ + 'storage', + 'output', + 'data_type_support', + ], (string) $env)); + + return $datatypeSupport ?? DatatypeSupport::from((string) $env); + } } diff --git a/src/Config/DatatypeSupport.php b/src/Config/DatatypeSupport.php new file mode 100644 index 0000000..9858aaf --- /dev/null +++ b/src/Config/DatatypeSupport.php @@ -0,0 +1,17 @@ +deleteWhereColumn; + } + + public function getDeleteWhereValues(): ?array + { + return $this->deleteWhereValues; + } + + public function getDeleteWhereOperator(): ?string + { + return $this->deleteWhereOperator; + } + + public function setDeleteWhereColumn(?string $deleteWhereColumn): ManifestOptions + { + $this->deleteWhereColumn = $deleteWhereColumn; + return $this; + } + + public function setDeleteWhereValues(?array $deleteWhereValues): ManifestOptions + { + $this->deleteWhereValues = $deleteWhereValues; + return $this; + } + + public function setDeleteWhereOperator(?string $deleteWhereOperator): ManifestOptions + { + $this->deleteWhereOperator = $deleteWhereOperator; + return $this; + } } diff --git a/tests/Config/BaseConfigTest.php b/tests/Config/BaseConfigTest.php index 269064d..77cf779 100644 --- a/tests/Config/BaseConfigTest.php +++ b/tests/Config/BaseConfigTest.php @@ -7,6 +7,7 @@ use Generator; use Keboola\Component\Config\BaseConfig; use Keboola\Component\Config\BaseConfigDefinition; +use Keboola\Component\Config\DatatypeSupport; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -155,6 +156,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition return $nodeDefinition; } }; + putenv('KBC_DATA_TYPE_SUPPORT=authoritative'); $config = new BaseConfig([ 'parameters' => [ 'ipsum' => [ @@ -177,6 +179,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition 'tables' => [], ], 'output' => [ + 'data_type_support' => DatatypeSupport::HINTS->value, 'files' => [], ], ], @@ -227,6 +230,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition 'tables' => [], ], 'output' => [ + 'data_type_support' => DatatypeSupport::HINTS->value, 'files' => [], ], ], @@ -236,6 +240,46 @@ protected function getParametersDefinition(): ArrayNodeDefinition 'value', $config->getValue(['parameters', 'ipsum', 'dolor']), ); + $this->assertEquals( + DatatypeSupport::HINTS, + $config->getDataTypeSupport(), + ); + } + + public function testGetDataTypeSupportUserInvalidInput(): void + { + putenv('KBC_DATA_TYPE_SUPPORT=authoritative'); + $config = new BaseConfig([ + 'storage' => [ + 'output' => [ + 'data_type_support' => 'I\'m invalid', + 'files' => [], + ], + ], + ], new BaseConfigDefinition); + + $this->assertEquals( + DatatypeSupport::AUTHORITATIVE, // from env + $config->getDataTypeSupport(), + ); + } + + public function testGetDataTypeSupportNoEnvUserInvalidInput(): void + { + putenv('KBC_DATA_TYPE_SUPPORT='); + $config = new BaseConfig([ + 'storage' => [ + 'output' => [ + 'data_type_support' => 'I\'m invalid', + 'files' => [], + ], + ], + ], new BaseConfigDefinition); + + $this->assertEquals( + DatatypeSupport::NONE, // default when env not set + $config->getDataTypeSupport(), + ); } /** @@ -244,7 +288,11 @@ protected function getParametersDefinition(): ArrayNodeDefinition public function testEnvGetters(array $envs): void { foreach ($envs as $env => $value) { - putenv(sprintf('%s=%s', $env, $value)); + if ($value === null) { + putenv($env); + } else { + putenv(sprintf('%s=%s', $env, $value)); + } } $config = new BaseConfig([], new BaseConfigDefinition()); @@ -313,6 +361,12 @@ public function testEnvGetters(array $envs): void Assert::assertEquals($envs['KBC_URL'], $config->getEnvKbcUrl()); } + if (!isset($envs['KBC_DATA_TYPE_SUPPORT'])) { + Assert::assertEquals(DatatypeSupport::NONE, $config->getDataTypeSupport()); + } else { + Assert::assertEquals(DatatypeSupport::from($envs['KBC_DATA_TYPE_SUPPORT']), $config->getDataTypeSupport()); + } + foreach ($envs as $env => $value) { putenv(sprintf('%s', $env)); } @@ -328,8 +382,9 @@ public function envGettersDataProvider(): Generator 'KBC_CONFIGID' => 'configId', 'KBC_CONFIGROWID' => 'configRowId', 'KBC_COMPONENTID' => 'componentId', - 'KBC_BRANCHID' => 'brancId', + 'KBC_BRANCHID' => 'branchId', 'KBC_STAGING_FILE_PROVIDER' => 'staging_file_provider', + 'KBC_DATA_TYPE_SUPPORT' => null, ], ]; @@ -341,13 +396,14 @@ public function envGettersDataProvider(): Generator 'KBC_CONFIGID' => 'configId', 'KBC_CONFIGROWID' => 'configRowId', 'KBC_COMPONENTID' => 'componentId', - 'KBC_BRANCHID' => 'brancId', + 'KBC_BRANCHID' => 'branchId', 'KBC_STAGING_FILE_PROVIDER' => 'staging_file_provider', 'KBC_PROJECTNAME' => 'projectName', 'KBC_TOKENID' => 'tokenId', 'KBC_TOKENDESC' => 'tokenDesc', 'KBC_TOKEN' => 'token', 'KBC_URL' => 'url', + 'KBC_DATA_TYPE_SUPPORT' => DatatypeSupport::AUTHORITATIVE->value, ], ]; } diff --git a/tests/Manifest/ManifestManager/Options/OutTableManifestOptionsTest.php b/tests/Manifest/ManifestManager/Options/OutTableManifestOptionsTest.php index 95c4245..c314025 100644 --- a/tests/Manifest/ManifestManager/Options/OutTableManifestOptionsTest.php +++ b/tests/Manifest/ManifestManager/Options/OutTableManifestOptionsTest.php @@ -51,6 +51,9 @@ public function provideOptions(): array [ 'destination' => 'my.table', 'manifest_type' => ManifestOptions::MANIFEST_TYPE_OUTPUT, + 'delete_where_column' => 'column1', + 'delete_where_values' => ['value1'], + 'delete_where_operator' => 'eq', 'delimiter' => '|', 'enclosure' => '_', 'incremental' => true, @@ -78,6 +81,9 @@ public function provideOptions(): array ], (new ManifestOptions()) ->setManifestType(ManifestOptions::MANIFEST_TYPE_OUTPUT) + ->setDeleteWhereColumn('column1') + ->setDeleteWhereValues(['value1']) + ->setDeleteWhereOperator('eq') ->setEnclosure('_') ->setDelimiter('|') ->setColumns(['id', 'number', 'other_column'])