mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-31 12:38:22 +00:00
🚿
This commit is contained in:
@@ -137,15 +137,15 @@ final class MaskPattern{
|
||||
*/
|
||||
private static function applyRule1(array $matrix, int $height, int $width, bool $isHorizontal):int{
|
||||
$penalty = 0;
|
||||
$iLimit = $isHorizontal ? $height : $width;
|
||||
$jLimit = $isHorizontal ? $width : $height;
|
||||
$yLimit = $isHorizontal ? $height : $width;
|
||||
$xLimit = $isHorizontal ? $width : $height;
|
||||
|
||||
for($i = 0; $i < $iLimit; $i++){
|
||||
for($y = 0; $y < $yLimit; $y++){
|
||||
$numSameBitCells = 0;
|
||||
$prevBit = -1;
|
||||
$prevBit = null;
|
||||
|
||||
for($j = 0; $j < $jLimit; $j++){
|
||||
$bit = $isHorizontal ? $matrix[$i][$j] : $matrix[$j][$i];
|
||||
for($x = 0; $x < $xLimit; $x++){
|
||||
$bit = $isHorizontal ? $matrix[$y][$x] : $matrix[$x][$y];
|
||||
|
||||
if($bit === $prevBit){
|
||||
$numSameBitCells++;
|
||||
|
||||
@@ -370,11 +370,7 @@ trait QROptionsTrait{
|
||||
* sets/clamps the version number
|
||||
*/
|
||||
protected function set_version(int $version):void{
|
||||
|
||||
if($version !== Version::AUTO){
|
||||
$this->version = max(1, min(40, $version));
|
||||
}
|
||||
|
||||
$this->version = $version !== Version::AUTO ? max(1, min(40, $version)) : Version::AUTO; // @todo
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,6 +92,8 @@ final class MaskPatternTest extends TestCase{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the mask function generates the correct pattern
|
||||
*
|
||||
* @dataProvider maskPatternProvider
|
||||
*/
|
||||
public function testMask(int $pattern, array $expected):void{
|
||||
@@ -104,7 +106,7 @@ final class MaskPatternTest extends TestCase{
|
||||
|
||||
for($x = 0; $x < 6; $x++){
|
||||
for($y = 0; $y < 6; $y++){
|
||||
if(($expected[$y][$x] === 1) !== $mask($x, $y)){
|
||||
if($mask($x, $y) !== ($expected[$y][$x] === 1)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -113,6 +115,9 @@ final class MaskPatternTest extends TestCase{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if an exception is thrown on an incorrect mask pattern
|
||||
*/
|
||||
public function testInvalidMaskPatternException():void{
|
||||
$this->expectException(QRCodeException::class);
|
||||
$this->expectExceptionMessage('invalid mask pattern');
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace chillerlan\QRCodeTest\Data;
|
||||
use chillerlan\QRCode\Common\{MaskPattern, Version};
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRMatrix};
|
||||
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
|
||||
use ReflectionClass;
|
||||
|
||||
use function str_repeat;
|
||||
@@ -34,12 +34,21 @@ abstract class DatainterfaceTestAbstract extends TestCase{
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the data interface instance
|
||||
* Verifies the QRData instance
|
||||
*/
|
||||
public function testInstance():void{
|
||||
$this::assertInstanceOf(QRData::class, $this->QRData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the QRDataModeInterface instance
|
||||
*/
|
||||
public function testDataModeInstance():void{
|
||||
$datamode = new $this->FQN($this->testdata);
|
||||
|
||||
$this::assertInstanceOf(QRDataModeInterface::class, $datamode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see testInitMatrix()
|
||||
* @return int[][]
|
||||
@@ -77,6 +86,8 @@ abstract class DatainterfaceTestAbstract extends TestCase{
|
||||
abstract public function stringValidateProvider():array;
|
||||
|
||||
/**
|
||||
* Tests if a string is properly validated for the respective data mode
|
||||
*
|
||||
* @dataProvider stringValidateProvider
|
||||
*/
|
||||
public function testValidateString(string $string, bool $expected):void{
|
||||
|
||||
@@ -228,13 +228,10 @@ final class QRMatrixTest extends TestCase{
|
||||
|
||||
foreach($alignmentPattern as $py){
|
||||
foreach($alignmentPattern as $px){
|
||||
|
||||
if($matrix->checkType($px, $py, QRMatrix::M_FINDER)){
|
||||
// skip finder pattern
|
||||
continue;
|
||||
// skip finder pattern
|
||||
if($matrix->checkTypeNotIn($px, $py, [QRMatrix::M_FINDER, QRMatrix::M_FINDER_DOT])){
|
||||
$this::assertSame(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK, $matrix->get($px, $py));
|
||||
}
|
||||
|
||||
$this::assertSame(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK, $matrix->get($px, $py));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,14 +255,11 @@ final class QRMatrixTest extends TestCase{
|
||||
|
||||
for($i = 7; $i < $size - 7; $i++){
|
||||
if($i % 2 === 0){
|
||||
|
||||
if($matrix->checkType(6, $i, QRMatrix::M_ALIGNMENT)){
|
||||
// skip alignment pattern
|
||||
continue;
|
||||
// skip alignment pattern
|
||||
if($matrix->checkTypeNotIn(6, $i, [QRMatrix::M_ALIGNMENT])){
|
||||
$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get(6, $i));
|
||||
$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get($i, 6));
|
||||
}
|
||||
|
||||
$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get(6, $i));
|
||||
$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get($i, 6));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ final class QRCodeTest extends TestCase{
|
||||
/**
|
||||
* tests if an exception is thrown when an invalid (built-in) output type is specified
|
||||
*/
|
||||
public function testInitDataInterfaceException():void{
|
||||
public function testInitOutputInterfaceException():void{
|
||||
$this->expectException(QRCodeOutputException::class);
|
||||
$this->expectExceptionMessage('invalid output type');
|
||||
|
||||
|
||||
@@ -191,6 +191,8 @@ final class QROptionsTest extends TestCase{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests clamping of the circle radius
|
||||
*
|
||||
* @dataProvider circleRadiusProvider
|
||||
*/
|
||||
public function testClampCircleRadius(float $value, float $expected):void{
|
||||
|
||||
Reference in New Issue
Block a user