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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## [Unreleased]

## [0.8.4] - 2026-12-01

### Fixed

- SPSS export keeps the weight variable when a string wider than 8 bytes comes
before it. The SAV writer stored the weight as a logical position instead of
the 8-byte slot SPSS expects, so the weight was lost on reading. Requires
`openstatspec/spss-sav` 3.2.1, which counts the slots itself; it is now the
CI-tested engine version and the lower bound of the claimed engine range
(`>=3.2.1 <4.0.0`). Found in Datuno.

## [0.8.3] - 2026-11-22

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-mbstring": "*",
"ext-pdo": "*",
"brick/math": "^0.19",
"openstatspec/spss-sav": "^3.2"
"openstatspec/spss-sav": "^3.2.1"
},
"repositories": [
{
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/Spss/PhpSpssEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ final class PhpSpssEngine implements SpssEngine
public const PACKAGE = 'openstatspec/spss-sav';
public const READER_CLASS = 'SPSS\\Sav\\Reader';
public const WRITER_CLASS = 'SPSS\\Sav\\Writer';
public const CLAIMED_VERSION_RANGE = '>=3.0.0 <4.0.0';
public const CI_TESTED_VERSIONS = ['3.2.0'];
public const CLAIMED_VERSION_RANGE = '>=3.2.1 <4.0.0';
public const CI_TESTED_VERSIONS = ['3.2.1'];

public function isAvailable(): bool
{
Expand All @@ -42,7 +42,10 @@ public function identity(): array

public static function isClaimedVersionSupported(?string $version): bool
{
return is_string($version) && preg_match('/^v?3\.\d+\.\d+(?:[-+].*)?$/', $version) === 1;
// 3.2.1 is the first release that writes the weight index as the physical slot.
return is_string($version)
&& preg_match('/^v?(3\.\d+\.\d+)(?:[-+].*)?$/', $version, $match) === 1
&& version_compare($match[1], '3.2.1', '>=');
}

/** @return array<string, bool> */
Expand Down
6 changes: 3 additions & 3 deletions tests/Core/CapabilityDeclarationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function testDeclarationIsMachineReadableAndIncludesEveryProfileLimit():
], $contracts['opt_in_frontend_contracts']);
self::assertArrayNotHasKey('legacy_plan_contracts', $contracts);
self::assertFalse(class_exists(\OpenStatSpec\Transformation\Model\TransformationPlan::class));
self::assertSame('3.2.0', $declaration['engine']['active_version']);
self::assertSame('>=3.0.0 <4.0.0', $declaration['engine']['claimed_version_range']);
self::assertSame(['3.2.0'], $declaration['engine']['ci_tested_versions']);
self::assertSame('3.2.1', $declaration['engine']['active_version']);
self::assertSame('>=3.2.1 <4.0.0', $declaration['engine']['claimed_version_range']);
self::assertSame(['3.2.1'], $declaration['engine']['ci_tested_versions']);
self::assertTrue($declaration['engine']['claimed_supported']);
self::assertNotEmpty($declaration['required_capabilities']);
foreach ($declaration['required_capabilities'] as $supported) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/OfficialSpssConformanceManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private function assertRequiredCapabilities(array $manifest, SpssAdapter $adapte
self::assertTrue($declaration['active_connection']['claimed_supported'], $profile . ': active server version is outside the claimed profile');
self::assertSame($declaration['sql_profiles'][$profile]['claimed_server_versions'], $declaration['active_connection']['matched_claim']);
self::assertTrue($declaration['engine']['claimed_supported']);
self::assertSame(['3.2.0'], $declaration['engine']['ci_tested_versions']);
self::assertSame(['3.2.1'], $declaration['engine']['ci_tested_versions']);
self::assertContains($profile, array_keys($declaration['sql_profiles'] ?? []));
self::assertContains('import', $declaration['directions'] ?? []);
self::assertContains('export', $declaration['directions'] ?? []);
Expand Down
38 changes: 34 additions & 4 deletions tests/Spss/SpssAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ public function testComposerInstallsTheOfficialPhpSpssV3Engine(): void
self::assertTrue(class_exists(Dataset::class));
self::assertSame([
'package' => 'openstatspec/spss-sav',
'version' => '3.2.0',
'active_version' => '3.2.0',
'claimed_version_range' => '>=3.0.0 <4.0.0',
'ci_tested_versions' => ['3.2.0'],
'version' => '3.2.1',
'active_version' => '3.2.1',
'claimed_version_range' => '>=3.2.1 <4.0.0',
'ci_tested_versions' => ['3.2.1'],
'claimed_supported' => true,
], (new PhpSpssEngine())->identity());
self::assertTrue(PhpSpssEngine::isClaimedVersionSupported('v3.10.0'));
self::assertFalse(PhpSpssEngine::isClaimedVersionSupported('3.2.0'));
self::assertFalse(PhpSpssEngine::isClaimedVersionSupported('4.0.0'));
}

public function testSuccessfulMigrationAdvancesOlderIdentityVersion(): void
Expand Down Expand Up @@ -813,6 +816,33 @@ public function testRealExportAfterTransformation(array $operations, ?Measure $m
}
}

public function testRealExportKeepsWeightAfterLongString(): void
{
$source = sys_get_temp_dir() . '/oss-weight-' . bin2hex(random_bytes(8)) . '.sav';
$target = $source . '.out.sav';
$engine = new PhpSpssEngine();
$adapter = new SpssAdapter(new PDO('sqlite::memory:'), $engine);
$numeric = new VariableFormat(5, 8, 2);
try {
// A 20-byte string takes three 8-byte slots, so the weight is slot 4, not ordinal 2.
$engine->write($source, new Dataset(
new VariableDictionary([
new VariableMetadata('Comment', VariableType::STRING, 20, new VariableFormat(1, 20), new VariableFormat(1, 20)),
new VariableMetadata('Weight', VariableType::NUMERIC, 0, $numeric, $numeric),
]),
[['abc', 1.5]],
new FileMetadata(weightVariableName: 'Weight'),
));
$adapter->import($source, 'weighted');
$adapter->export('weighted', $target);

self::assertSame('Weight', $engine->read($target)->metadata->weightVariableName);
} finally {
@unlink($source);
@unlink($target);
}
}

public function testPhpSpssEngineWritesAndReadsTypedDataset(): void
{
$target = sys_get_temp_dir() . '/openstatspec-v3-' . uniqid('', true) . '.sav';
Expand Down