2021-02-26 16:16:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class BitBufferTest
|
|
|
|
*
|
|
|
|
* @filesource BitBufferTest.php
|
|
|
|
* @created 08.02.2016
|
|
|
|
* @package chillerlan\QRCodeTest\Helpers
|
|
|
|
* @author Smiley <smiley@chillerlan.net>
|
|
|
|
* @copyright 2015 Smiley
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace chillerlan\QRCodeTest\Helpers;
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
use chillerlan\QRCode\QRCode;
|
|
|
|
use chillerlan\QRCode\Helpers\BitBuffer;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-02-26 16:16:17 +00:00
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
/**
|
|
|
|
* BitBuffer coverage test
|
|
|
|
*/
|
|
|
|
final class BitBufferTest extends TestCase{
|
2021-02-26 16:16:17 +00:00
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
protected BitBuffer $bitBuffer;
|
2021-02-26 16:16:17 +00:00
|
|
|
|
|
|
|
protected function setUp():void{
|
|
|
|
$this->bitBuffer = new BitBuffer;
|
|
|
|
}
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
public function bitProvider():array{
|
2021-02-26 16:16:17 +00:00
|
|
|
return [
|
|
|
|
'number' => [QRCode::DATA_NUMBER, 16],
|
|
|
|
'alphanum' => [QRCode::DATA_ALPHANUM, 32],
|
|
|
|
'byte' => [QRCode::DATA_BYTE, 64],
|
|
|
|
'kanji' => [QRCode::DATA_KANJI, 128],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider bitProvider
|
|
|
|
*/
|
2022-07-02 14:01:51 +00:00
|
|
|
public function testPut(int $data, int $value):void{
|
2021-02-26 16:16:17 +00:00
|
|
|
$this->bitBuffer->put($data, 4);
|
2022-07-02 14:01:51 +00:00
|
|
|
$this::assertSame($value, $this->bitBuffer->getBuffer()[0]);
|
|
|
|
$this::assertSame(4, $this->bitBuffer->getLength());
|
2021-02-26 16:16:17 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
public function testClear():void{
|
2021-02-26 16:16:17 +00:00
|
|
|
$this->bitBuffer->clear();
|
2022-07-02 14:01:51 +00:00
|
|
|
$this::assertSame([], $this->bitBuffer->getBuffer());
|
|
|
|
$this::assertSame(0, $this->bitBuffer->getLength());
|
2021-02-26 16:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|