diff --git a/src/Data/MaskPatternTester.php b/src/Data/MaskPatternTester.php index 609f12dec..86ad374e5 100644 --- a/src/Data/MaskPatternTester.php +++ b/src/Data/MaskPatternTester.php @@ -46,10 +46,7 @@ final class MaskPatternTester{ $penalties = []; for($pattern = 0; $pattern < 8; $pattern++){ - $this->matrix = $this->dataInterface->initMatrix($pattern, true); - $this->moduleCount = $this->matrix->size(); - - $penalties[$pattern] = $this->testPattern(); + $penalties[$pattern] = $this->testPattern($pattern); } return array_search(min($penalties), $penalties, true); @@ -61,8 +58,10 @@ final class MaskPatternTester{ * @see \chillerlan\QRCode\QROptions::$maskPattern * @see \chillerlan\QRCode\Data\QRMatrix::$maskPattern */ - protected function testPattern():int{ - $penalty = 0; + public function testPattern(int $pattern):int{ + $this->matrix = $this->dataInterface->initMatrix($pattern, true); + $this->moduleCount = $this->matrix->size(); + $penalty = 0; for($level = 1; $level <= 4; $level++){ $penalty += call_user_func([$this, 'testLevel'.$level]); diff --git a/tests/Data/MaskPatternTesterTest.php b/tests/Data/MaskPatternTesterTest.php index 03dd4f8f8..3856d497d 100644 --- a/tests/Data/MaskPatternTesterTest.php +++ b/tests/Data/MaskPatternTesterTest.php @@ -21,10 +21,15 @@ class MaskPatternTesterTest extends QRTestAbstract{ // coverage public function testMaskpattern():void{ - $matrix = (new Byte(new QROptions(['version' => 10]), 'test'))->initMatrix(0, true); + $dataInterface = new Byte(new QROptions(['version' => 10]), 'test'); - $this::assertSame(6178, (new MaskPatternTester($matrix))->testPattern()); + $this::assertSame(4, (new MaskPatternTester($dataInterface))->getBestMaskPattern()); } + public function testMaskpatternID():void{ + $dataInterface = new Byte(new QROptions(['version' => 10]), 'test'); + + $this::assertSame(6178, (new MaskPatternTester($dataInterface))->testPattern(0)); + } }