|
@@ -16,8 +16,9 @@ use chillerlan\QRCode\QRCode;
|
|
|
use chillerlan\QRCode\QRConst;
|
|
use chillerlan\QRCode\QRConst;
|
|
|
use chillerlan\QRCode\QROptions;
|
|
use chillerlan\QRCode\QROptions;
|
|
|
use ReflectionClass;
|
|
use ReflectionClass;
|
|
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
-class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
|
|
|
|
|
|
+class QRCodeTest extends TestCase{
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @var \chillerlan\QRCode\QROptions
|
|
* @var \chillerlan\QRCode\QROptions
|
|
@@ -48,10 +49,10 @@ class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
|
|
|
|
|
|
|
public function stringDataProvider(){
|
|
public function stringDataProvider(){
|
|
|
return [
|
|
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){
|
|
public function testDataCoverage($data){
|
|
|
(new QRCode($data, $this->output))->getRawData();
|
|
(new QRCode($data, $this->output))->getRawData();
|
|
|
|
|
+ $this->markTestSkipped('code coverage');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -78,43 +80,54 @@ class QRCodeTest extends \PHPUnit_Framework_TestCase{
|
|
|
/**
|
|
/**
|
|
|
* @dataProvider stringDataProvider
|
|
* @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;
|
|
$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 [
|
|
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 = $this->reflectionClass->getMethod('getMatrix');
|
|
|
$method->setAccessible(true);
|
|
$method->setAccessible(true);
|
|
|
|
|
+
|
|
|
|
|
+ $property = $this->reflectionClass->getProperty('pixelCount');
|
|
|
|
|
+ $property->setAccessible(true);
|
|
|
|
|
+
|
|
|
$this->options->typeNumber = $type;
|
|
$this->options->typeNumber = $type;
|
|
|
|
|
|
|
|
for($i = 0; $i <= 7; $i++){
|
|
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));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|