mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-31 04:28:03 +00:00
updated tests
This commit is contained in:
@@ -11,8 +11,9 @@ namespace chillerlan\QRCodeTest;
|
||||
|
||||
use chillerlan\QRCode\BitBuffer;
|
||||
use chillerlan\QRCode\QRConst;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BitBufferTest extends \PHPUnit_Framework_TestCase{
|
||||
class BitBufferTest extends TestCase{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\BitBuffer
|
||||
|
||||
+20
-5
@@ -16,8 +16,9 @@ use chillerlan\QRCode\Data\AlphaNum;
|
||||
use chillerlan\QRCode\Data\Byte;
|
||||
use chillerlan\QRCode\Data\Kanji;
|
||||
use chillerlan\QRCode\Data\Number;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DataTest extends \PHPUnit_Framework_TestCase{
|
||||
class DataTest extends TestCase{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\BitBuffer
|
||||
@@ -29,7 +30,7 @@ class DataTest extends \PHPUnit_Framework_TestCase{
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
public function bitProvider(){
|
||||
public function bitProviderMode(){
|
||||
return [
|
||||
[QRConst::MODE_NUMBER, Number::class, '123456789'],
|
||||
[QRConst::MODE_NUMBER, Number::class, '1234567890'],
|
||||
@@ -45,20 +46,34 @@ class DataTest extends \PHPUnit_Framework_TestCase{
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider bitProvider
|
||||
* @dataProvider bitProviderMode
|
||||
*/
|
||||
public function testMode($mode, $class, $data){
|
||||
$this->module = new $class($data);
|
||||
$this->assertEquals($mode, $this->module->mode);
|
||||
}
|
||||
|
||||
|
||||
public function bitProviderWrite(){
|
||||
return [
|
||||
[Number::class, '123456789', [30, 220, 140, 84]],
|
||||
[Number::class, '1234567890', [30, 220, 140, 84, 0]],
|
||||
[Number::class, '12345678901', [30, 220, 140, 84, 8]],
|
||||
[AlphaNum::class, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', [57, 168, 165, 66, 174, 22, 122, 230, 95, 172, 81, 149, 180, 38, 178, 220, 28, 58, 11, 196, 88, 231, 40, 102, 87, 60, 237, 94, 99, 227, 108]],
|
||||
[Byte::class, '#\\', [35, 92]],
|
||||
[Kanji::class, '茗荷', [236, 100, 74, 18, 238]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider bitProvider
|
||||
* @dataProvider bitProviderWrite
|
||||
*/
|
||||
public function testWrite($mode, $class, $data){
|
||||
public function testWrite($class, $data, $expected){
|
||||
$this->bitBuffer->clear();
|
||||
$this->module = new $class($data);
|
||||
$this->module->write($this->bitBuffer);
|
||||
|
||||
$this->assertSame($expected, $this->bitBuffer->buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,10 @@ class ImageTest extends OutputTestAbstract{
|
||||
$this->options->type = $type;
|
||||
$output = (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output();
|
||||
// jpeg test is causing trouble
|
||||
if($type !== QRCode::OUTPUT_IMAGE_JPG){
|
||||
if($type === QRCode::OUTPUT_IMAGE_JPG){
|
||||
$this->markTestSkipped('jpeg test skipped');
|
||||
}
|
||||
else{
|
||||
$this->assertEquals(file_get_contents(__DIR__.'/image/'.$expected), $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
|
||||
namespace chillerlan\QRCodeTest\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class OutputTestAbstract
|
||||
*/
|
||||
abstract class OutputTestAbstract extends \PHPUnit_Framework_TestCase{
|
||||
abstract class OutputTestAbstract extends TestCase{
|
||||
|
||||
protected $outputInterfaceClass;
|
||||
protected $outputOptionsClass;
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
namespace chillerlan\QRCodeTest;
|
||||
|
||||
use chillerlan\QRCode\Polynomial;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PolynomialTest extends \PHPUnit_Framework_TestCase{
|
||||
class PolynomialTest extends TestCase{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\Polynomial
|
||||
|
||||
+40
-27
@@ -16,8 +16,9 @@ use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QRConst;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use ReflectionClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
||||
class QRCodeTest extends TestCase{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\QROptions
|
||||
@@ -48,10 +49,10 @@ class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
||||
|
||||
public function stringDataProvider(){
|
||||
return [
|
||||
['1234567890'],
|
||||
['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
|
||||
['#\\'],
|
||||
['茗荷'],
|
||||
['1234567890', QRCode::TYPE_01],
|
||||
['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', QRCode::TYPE_03],
|
||||
['#\\', QRCode::TYPE_01],
|
||||
['茗荷', QRCode::TYPE_01],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
||||
*/
|
||||
public function testDataCoverage($data){
|
||||
(new QRCode($data, $this->output))->getRawData();
|
||||
$this->markTestSkipped('code coverage');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,43 +80,54 @@ class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
||||
/**
|
||||
* @dataProvider stringDataProvider
|
||||
*/
|
||||
public function testTypeAutoOverride($data){
|
||||
public function testTypeAutoOverride($data, $type){
|
||||
|
||||
$property = $this->reflectionClass->getProperty('typeNumber');
|
||||
$property->setAccessible(true);
|
||||
|
||||
$this->options->typeNumber = 'foo';
|
||||
$this->assertSame($type, $property->getValue($this->reflectionClass->newInstanceArgs([$data, $this->output, $this->options])));
|
||||
|
||||
$this->options->typeNumber = 42;
|
||||
$this->assertSame($type, $property->getValue($this->reflectionClass->newInstanceArgs([$data, $this->output, $this->options])));
|
||||
|
||||
$this->options->typeNumber = QRCode::TYPE_05;
|
||||
new QRCode($data, $this->output, $this->options);
|
||||
$this->assertSame(QRCode::TYPE_05, $property->getValue($this->reflectionClass->newInstanceArgs([$data, $this->output, $this->options])));
|
||||
}
|
||||
|
||||
|
||||
public function getTypeNumberDataProvider(){
|
||||
public function getMatrixDataProvider(){
|
||||
return [
|
||||
[true, QRCode::TYPE_05, 'foobar'],
|
||||
[false, QRCode::TYPE_05, 'foobar'],
|
||||
[true, QRCode::TYPE_10, 'foobar'],
|
||||
[false, QRCode::TYPE_10, 'foobar'],
|
||||
[true, QRCode::TYPE_05, '1234567890'],
|
||||
[false, QRCode::TYPE_05, '1234567890'],
|
||||
[true, QRCode::TYPE_10, '1234567890'],
|
||||
[false, QRCode::TYPE_10, '1234567890'],
|
||||
[true, QRCode::TYPE_05, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
|
||||
[false, QRCode::TYPE_05, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
|
||||
[true, QRCode::TYPE_10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
|
||||
[false, QRCode::TYPE_10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
|
||||
[true, QRCode::TYPE_05, '茗荷'],
|
||||
[false, QRCode::TYPE_05, '茗荷'],
|
||||
[true, QRCode::TYPE_10, '茗荷'],
|
||||
[false, QRCode::TYPE_10, '茗荷'],
|
||||
[QRCode::TYPE_01, 'foobar', 21],
|
||||
[QRCode::TYPE_05, 'foobar', 37],
|
||||
[QRCode::TYPE_10, 'foobar', 57],
|
||||
[QRCode::TYPE_05, '1234567890', 37],
|
||||
[QRCode::TYPE_10, '1234567890', 57],
|
||||
[QRCode::TYPE_03, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', 29],
|
||||
[QRCode::TYPE_05, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', 37],
|
||||
[QRCode::TYPE_10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', 57],
|
||||
[QRCode::TYPE_05, '茗荷', 37],
|
||||
[QRCode::TYPE_10, '茗荷', 57],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTypeNumberDataProvider
|
||||
* @dataProvider getMatrixDataProvider
|
||||
*/
|
||||
public function testInternalGetTypeNumber($test, $type, $data){
|
||||
public function testInternalGetMatrix($type, $data, $pixelCount){
|
||||
$method = $this->reflectionClass->getMethod('getMatrix');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$property = $this->reflectionClass->getProperty('pixelCount');
|
||||
$property->setAccessible(true);
|
||||
|
||||
$this->options->typeNumber = $type;
|
||||
|
||||
for($i = 0; $i <= 7; $i++){
|
||||
$method->invokeArgs($this->reflectionClass->newInstanceArgs([$data, $this->output, $this->options]), [$test, $i]);
|
||||
$qrcode = $this->reflectionClass->newInstanceArgs([$data, $this->output, $this->options]);
|
||||
$method->invokeArgs($qrcode, [false, $i]);
|
||||
|
||||
$this->assertSame($pixelCount, $property->getValue($qrcode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -12,8 +12,9 @@ namespace chillerlan\QRCodeTest;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QRConst;
|
||||
use chillerlan\QRCode\Util;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UtilTest extends \PHPUnit_Framework_TestCase{
|
||||
class UtilTest extends TestCase{
|
||||
|
||||
public function testIsNumber(){
|
||||
$this->assertEquals(true, Util::isNumber('1234567890'));
|
||||
|
||||
Reference in New Issue
Block a user