From e818e3526102a20b7d9c7e1b14feef686c973a5d Mon Sep 17 00:00:00 2001 From: gam6itko Date: Tue, 7 Jun 2022 13:51:07 +0300 Subject: [PATCH] fix #115: VisualFoxproTest fix for Ignore colunm --- .../Field/VisualFoxpro/IgnoreConverter.php | 2 +- tests/Resources/foxpro/issue115.cdx | Bin 0 -> 4608 bytes tests/Resources/foxpro/issue115.dbf | Bin 0 -> 1724 bytes tests/TableEditor/VisualFoxproTest.php | 43 ++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/Resources/foxpro/issue115.cdx create mode 100644 tests/Resources/foxpro/issue115.dbf 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 0000000000000000000000000000000000000000..d35bc1e193df84617091dc8491bfc2985c9b26d3 GIT binary patch literal 4608 zcmZQzVSoWfE`|q;FwQ7FyhDJI0Tk7v(LKClnXvDe8JHOUL&0^%|Nj{n`1u7`SeO}j z3K-ZF2Qu9i4GmBD( zwP!~?hcg7&f$0EN{@-Wh2dcBTXJKPwVl2U_WmIA~gn*;Ft6xZ{4}$>0Gb{`_qvby$ zIEFQgg#nb;Ss0S@QyBF8{6q9yTzylp0m=LnPl>d(X?@8sj}>=*);_p1a_jA-V^`<3S8xaB0K7c&@C zf#pG=fB?M7`FSPrNr_d7dMQcC2=S4|QZO(uFm!Zx^$Q90Q6LoXLdnp>Efnvtp# zsGb32wGkN_sinot)Wp=xgj%K%ZB8OkB?uD&*wmnlB_f%GDTiuappendRecord(); + $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); + } }