diff --git a/CHANGELOG.md b/CHANGELOG.md index ffe3c38..2866d63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 5b94c8b..daf06d1 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "ext-mbstring": "*", "ext-pdo": "*", "brick/math": "^0.19", - "openstatspec/spss-sav": "^3.2" + "openstatspec/spss-sav": "^3.2.1" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index e45d2de..983d6f3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bf5a0e31daabf051cf31dcd0b0a0080d", + "content-hash": "37e04a9f480f66ac21199079ae642387", "packages": [ { "name": "brick/math", @@ -67,16 +67,16 @@ }, { "name": "openstatspec/spss-sav", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/OpenStatSpec/php-spss.git", - "reference": "a8a6d744d424eb43182f5402ca669f1fd2c45ee9" + "reference": "19fed388ef1858c109555660b3be050f8d364701" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/OpenStatSpec/php-spss/zipball/a8a6d744d424eb43182f5402ca669f1fd2c45ee9", - "reference": "a8a6d744d424eb43182f5402ca669f1fd2c45ee9", + "url": "https://api.github.com/repos/OpenStatSpec/php-spss/zipball/19fed388ef1858c109555660b3be050f8d364701", + "reference": "19fed388ef1858c109555660b3be050f8d364701", "shasum": "" }, "require": { @@ -213,7 +213,7 @@ "issues": "https://github.com/OpenStatSpec/php-spss/issues", "source": "https://github.com/OpenStatSpec/php-spss" }, - "time": "2026-11-09T16:44:14+00:00" + "time": "2026-12-01T14:20:36+00:00" } ], "packages-dev": [ diff --git a/src/Spss/PhpSpssEngine.php b/src/Spss/PhpSpssEngine.php index fcf860b..5ec9178 100644 --- a/src/Spss/PhpSpssEngine.php +++ b/src/Spss/PhpSpssEngine.php @@ -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 { @@ -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 */ diff --git a/tests/Core/CapabilityDeclarationTest.php b/tests/Core/CapabilityDeclarationTest.php index fe0c116..29e3395 100644 --- a/tests/Core/CapabilityDeclarationTest.php +++ b/tests/Core/CapabilityDeclarationTest.php @@ -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) { diff --git a/tests/Integration/OfficialSpssConformanceManifestTest.php b/tests/Integration/OfficialSpssConformanceManifestTest.php index ecfa5e2..dae1a26 100644 --- a/tests/Integration/OfficialSpssConformanceManifestTest.php +++ b/tests/Integration/OfficialSpssConformanceManifestTest.php @@ -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'] ?? []); diff --git a/tests/Spss/SpssAdapterTest.php b/tests/Spss/SpssAdapterTest.php index b48aa55..374a1f6 100644 --- a/tests/Spss/SpssAdapterTest.php +++ b/tests/Spss/SpssAdapterTest.php @@ -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 @@ -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';