Ver código fonte

:octocat: correct treatment of VERSION_AUTO

codemasher 7 anos atrás
pai
commit
826c3ace45
2 arquivos alterados com 4 adições e 1 exclusões
  1. 3 1
      src/QROptionsTrait.php
  2. 1 0
      tests/QROptionsTest.php

+ 3 - 1
src/QROptionsTrait.php

@@ -246,7 +246,9 @@ trait QROptionsTrait{
 			$this->clampRGBValues();
 			$this->clampRGBValues();
 		}
 		}
 
 
-		$this->version = max(1, min(40, (int)$this->version));
+		if($this->version !== QRCode::VERSION_AUTO){
+			$this->version = max(1, min(40, (int)$this->version));
+		}
 
 
 		// clamp min/max version number
 		// clamp min/max version number
 		$min = max(1, min(40, (int)$this->versionMin));
 		$min = max(1, min(40, (int)$this->versionMin));

+ 1 - 0
tests/QROptionsTest.php

@@ -26,6 +26,7 @@ class QROptionsTest extends TestCase{
 		$this->assertSame(40, (new QROptions(['version' => 42]))->version);
 		$this->assertSame(40, (new QROptions(['version' => 42]))->version);
 		$this->assertSame(1, (new QROptions(['version' => -42]))->version);
 		$this->assertSame(1, (new QROptions(['version' => -42]))->version);
 		$this->assertSame(21, (new QROptions(['version' => 21]))->version);
 		$this->assertSame(21, (new QROptions(['version' => 21]))->version);
+		$this->assertSame(QRCode::VERSION_AUTO, (new QROptions(['version' => QRCode::VERSION_AUTO]))->version); // -1
 	}
 	}
 
 
 	public function testVersionMinMaxClamp(){
 	public function testVersionMinMaxClamp(){