Skip to content

Commit

Permalink
fix #115: VisualFoxproTest fix for Ignore colunm
Browse files Browse the repository at this point in the history
  • Loading branch information
gam6itko committed Jun 7, 2022
1 parent 3db1675 commit e818e35
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DataConverter/Field/VisualFoxpro/IgnoreConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Binary file added tests/Resources/foxpro/issue115.cdx
Binary file not shown.
Binary file added tests/Resources/foxpro/issue115.dbf
Binary file not shown.
43 changes: 43 additions & 0 deletions tests/TableEditor/VisualFoxproTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e818e35

Please sign in to comment.