:octocat: allow overriding data mode detection

This commit is contained in:
codemasher
2019-12-04 22:31:05 +01:00
parent c5da58e3e5
commit df33b38b63
4 changed files with 61 additions and 14 deletions
+27 -1
View File
@@ -13,10 +13,12 @@
namespace chillerlan\QRCodeTest;
use chillerlan\QRCode\{QROptions, QRCode};
use chillerlan\QRCode\Data\QRCodeDataException;
use chillerlan\QRCode\Data\{AlphaNum, Byte, Number, QRCodeDataException};
use chillerlan\QRCode\Output\QRCodeOutputException;
use chillerlan\QRCodeExamples\MyCustomOutput;
use function random_bytes;
class QRCodeTest extends QRTestAbstract{
protected $FQCN = QRCode::class;
@@ -111,4 +113,28 @@ class QRCodeTest extends QRTestAbstract{
$this->assertSame($expected, $this->reflection->newInstanceArgs([$options])->render('test'));
}
public function testDataModeOverride(){
$this->qrcode = $this->reflection->newInstance();
$this->assertInstanceOf(Number::class, $this->qrcode->initDataInterface('123'));
$this->assertInstanceOf(AlphaNum::class, $this->qrcode->initDataInterface('ABC123'));
$this->assertInstanceOf(Byte::class, $this->qrcode->initDataInterface(random_bytes(32)));
$this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['dataMode' => 'Byte'])]);
$this->assertInstanceOf(Byte::class, $this->qrcode->initDataInterface('123'));
$this->assertInstanceOf(Byte::class, $this->qrcode->initDataInterface('ABC123'));
$this->assertInstanceOf(Byte::class, $this->qrcode->initDataInterface(random_bytes(32)));
}
public function testDataModeOverrideError(){
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('illegal char:');
$this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['dataMode' => 'AlphaNum'])]);
$this->qrcode->initDataInterface(random_bytes(32));
}
}