diff --git a/src/DataConverter/Field/VisualFoxpro/IgnoreConverter.php b/src/DataConverter/Field/VisualFoxpro/IgnoreConverter.php index d75316d..a8a20ff 100644 --- a/src/DataConverter/Field/VisualFoxpro/IgnoreConverter.php +++ b/src/DataConverter/Field/VisualFoxpro/IgnoreConverter.php @@ -19,6 +19,6 @@ public function fromBinaryString(string $value): string public function toBinaryString($value): string { - return $value ?? chr(0x20).chr(0x0a); + return str_pad((string) $value, $this->column->length, chr(0x20)); } } diff --git a/tests/Resources/foxpro/issue115.cdx b/tests/Resources/foxpro/issue115.cdx new file mode 100644 index 0000000..d35bc1e Binary files /dev/null and b/tests/Resources/foxpro/issue115.cdx differ diff --git a/tests/Resources/foxpro/issue115.dbf b/tests/Resources/foxpro/issue115.dbf new file mode 100644 index 0000000..2d4c150 Binary files /dev/null and b/tests/Resources/foxpro/issue115.dbf differ diff --git a/tests/TableEditor/VisualFoxproTest.php b/tests/TableEditor/VisualFoxproTest.php index ecbab0f..80afb40 100644 --- a/tests/TableEditor/VisualFoxproTest.php +++ b/tests/TableEditor/VisualFoxproTest.php @@ -3,6 +3,7 @@ namespace XBase\Tests\TableEditor; use PHPUnit\Framework\TestCase; +use XBase\Column\ColumnInterface; use XBase\Enum\TableType; use XBase\Memo\MemoObject; use XBase\Record\VisualFoxproRecord; @@ -314,4 +315,46 @@ public function testIssue91(): void } self::assertEquals($data, $actual); } + + public function testIssue115(): void + { + $filename = __DIR__.'/../Resources/foxpro/issue115.dbf'; + $table = new TableEditor($filename); + + $record = $table->appendRecord(); + $record->cod = 'a'; + $record->denumire = 'b'; + $record->cont_van = 'c'; + $record->tel = 'd'; + $record->bi_serie = 'e'; + $record->bi_numar = 'f'; + $record->bi_pol = 'g'; + $record->masina = 'h'; + $record->blocat = 1; + + $table + ->writeRecord() + ->save() + ->close(); + unset($record, $table); + + $table = new TableReader($filename); + self::assertSame( + $table->getRecordByteLength(), + array_reduce($table->getColumns(), static function (int $carry, ColumnInterface $c) { + return $carry + $c->getLength(); + }, 1) + ); + + $record = $table->pickRecord($table->getRecordCount() - 1); + self::assertSame($record->cod, 'a'); + self::assertSame($record->denumire, 'b'); + self::assertSame($record->cont_van, 'c'); + self::assertSame($record->tel, 'd'); + self::assertSame($record->bi_serie, 'e'); + self::assertSame($record->bi_numar, 'f'); + self::assertSame($record->bi_pol, 'g'); + self::assertSame($record->masina, 'h'); + self::assertSame($record->blocat, 1); + } }