Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"symfony/serializer": "^5.4|^6.0|^7.0"
},
"require-dev": {
"devedge/sami-github": "^1.0.6",
"keboola/coding-standard": "^15.0.1",
"keboola/php-temp": "^2.0.1",
"phpstan/phpstan": "^1.12.24",
Expand Down
20 changes: 18 additions & 2 deletions src/Manifest/ManifestManager/Options/OutTable/ManifestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@

class ManifestOptions
{
private const ALLOWED_MANIFEST_TYPES = [self::MANIFEST_TYPE_OUTPUT];
public const MANIFEST_TYPE_OUTPUT = 'output';
public const MANIFEST_TYPE_INPUT = 'input';
public const MANIFEST_TYPE_OUT = 'out';
public const MANIFEST_TYPE_IN = 'in';

private const ALLOWED_MANIFEST_TYPES = [
self::MANIFEST_TYPE_OUTPUT,
self::MANIFEST_TYPE_INPUT,
self::MANIFEST_TYPE_OUT,
self::MANIFEST_TYPE_IN,
];

// The Python SDK writes the stage value ("in"/"out") into manifest_type, while the canonical
// values are "input"/"output". Accept the stage aliases and normalize them to the canonical form.
private const MANIFEST_TYPE_NORMALIZATION_MAP = [
self::MANIFEST_TYPE_OUT => self::MANIFEST_TYPE_OUTPUT,
self::MANIFEST_TYPE_IN => self::MANIFEST_TYPE_INPUT,
];
private ?string $destination = null;

private ?bool $incremental = null;
Expand Down Expand Up @@ -158,7 +174,7 @@ public function setManifestType(string $manifestType): ManifestOptions
));
}

$this->manifestType = $manifestType;
$this->manifestType = self::MANIFEST_TYPE_NORMALIZATION_MAP[$manifestType] ?? $manifestType;
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,80 @@ public function provideOptions(): array
];
}

public function testFromArrayWithPythonSdkManifestType(): void
{
$options = ManifestOptions::fromArray([
'delimiter' => ',',
'enclosure' => '"',
'manifest_type' => 'out',
'schema' => [
[
'name' => 'id',
'nullable' => true,
'primary_key' => false,
],
],
]);

$this->assertSame(ManifestOptions::MANIFEST_TYPE_OUTPUT, $options->getManifestType());

$array = $options->toArray(false);
$this->assertSame('output', $array['manifest_type']);
}

public function testSetManifestTypeOutIsNormalized(): void
{
$options = (new ManifestOptions())->setManifestType('out');
$this->assertSame(ManifestOptions::MANIFEST_TYPE_OUTPUT, $options->getManifestType());
}

public function testFromArrayWithPythonSdkInputManifestType(): void
{
$options = ManifestOptions::fromArray([
'delimiter' => ',',
'enclosure' => '"',
'manifest_type' => 'in',
'schema' => [
[
'name' => 'id',
'nullable' => true,
'primary_key' => false,
],
],
]);

$this->assertSame(ManifestOptions::MANIFEST_TYPE_INPUT, $options->getManifestType());

$array = $options->toArray(false);
$this->assertSame('input', $array['manifest_type']);
}

public function testSetManifestTypeInIsNormalized(): void
{
$options = (new ManifestOptions())->setManifestType('in');
$this->assertSame(ManifestOptions::MANIFEST_TYPE_INPUT, $options->getManifestType());
}

public function testSetManifestTypeCanonicalValuesArePreserved(): void
{
$this->assertSame(
ManifestOptions::MANIFEST_TYPE_OUTPUT,
(new ManifestOptions())->setManifestType('output')->getManifestType(),
);
$this->assertSame(
ManifestOptions::MANIFEST_TYPE_INPUT,
(new ManifestOptions())->setManifestType('input')->getManifestType(),
);
}

public function testSetManifestTypeRejectsUnknownValue(): void
{
$this->expectException(OptionsValidationException::class);
$this->expectExceptionMessage('Manifest type "invalid" is not allowed');

(new ManifestOptions())->setManifestType('invalid');
}

/** @dataProvider validNamesProvider */
public function testManifestOptionsSchemaValidNames(string $name): void
{
Expand Down
Loading