Skip to content

Commit 3db1675

Browse files
committed
fix char is int
1 parent ec518fa commit 3db1675

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/DataConverter/Field/DBase/CharConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public function toBinaryString($value): string
2727
$value = $this->encoder->encode($value, 'utf-8', $outCharset);
2828
}
2929

30-
return str_pad($value ?? '', $this->column->length);
30+
return str_pad((string) $value, $this->column->length);
3131
}
3232
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace XBase\Tests\DataConverter\Field\DBase;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use XBase\DataConverter\Encoder\EncoderInterface;
9+
use XBase\DataConverter\Field\DBase\CharConverter;
10+
use XBase\Header\Column;
11+
use XBase\Table\Table;
12+
13+
/**
14+
* @coversDefaultClass \XBase\DataConverter\Field\DBase\CharConverter
15+
*/
16+
class CharConverterTest extends TestCase
17+
{
18+
public function testNullValue(): void
19+
{
20+
$table = $this->createMock(Table::class);
21+
$column = new Column(['length' => 1]);
22+
$encoder = $this->createMock(EncoderInterface::class);
23+
$c = new CharConverter($table, $column, $encoder);
24+
self::assertSame(' ', $c->toBinaryString(null));
25+
}
26+
27+
public function testIntValue(): void
28+
{
29+
$table = $this->createMock(Table::class);
30+
$column = new Column(['length' => 1]);
31+
$encoder = $this->createMock(EncoderInterface::class);
32+
$c = new CharConverter($table, $column, $encoder);
33+
self::assertSame('1', $c->toBinaryString(1));
34+
}
35+
}

0 commit comments

Comments
 (0)