diff --git a/tests/QROptionsTest.php b/tests/QROptionsTest.php new file mode 100644 index 000000000..d6208bfda --- /dev/null +++ b/tests/QROptionsTest.php @@ -0,0 +1,69 @@ + + * @copyright 2018 smiley + * @license MIT + */ + +namespace chillerlan\QRCodeTest; + +use chillerlan\QRCode\{QRCode,QROptions}; +use PHPUnit\Framework\TestCase; + +class QROptionsTest extends TestCase{ + + /** + * @var \chillerlan\QRCode\QROptions + */ + protected $options; + + public function testVersionClamp(){ + $this->assertSame(40, (new QROptions(['version' => 42]))->version); + $this->assertSame(1, (new QROptions(['version' => -42]))->version); + $this->assertSame(21, (new QROptions(['version' => 21]))->version); + } + + public function testVersionMinMaxClamp(){ + // normal clamp + $o = new QROptions(['versionMin' => 5, 'versionMax' => 10]); + $this->assertSame(5, $o->versionMin); + $this->assertSame(10, $o->versionMax); + // exceeding values + $o = new QROptions(['versionMin' => -42, 'versionMax' => 42]); + $this->assertSame(1, $o->versionMin); + $this->assertSame(40, $o->versionMax); + + // min > max + $o = new QROptions(['versionMin' => 10, 'versionMax' => 5]); + $this->assertSame(5, $o->versionMin); + $this->assertSame(10, $o->versionMax); + + $o = new QROptions(['versionMin' => 42, 'versionMax' => -42]); + $this->assertSame(1, $o->versionMin); + $this->assertSame(40, $o->versionMax); + } + + public function testMaskPatternClamp(){ + $o = new QROptions(['maskPattern' => 42]); + $this->assertSame(7, $o->maskPattern); + + $o = new QROptions(['maskPattern' => -42]); + $this->assertSame(0, $o->maskPattern); + + $o = new QROptions(['maskPattern' => QRCode::MASK_PATTERN_AUTO]); // -1 + $this->assertSame(QRCode::MASK_PATTERN_AUTO, $o->maskPattern); + } + + /** + * @expectedException \chillerlan\QRCode\QRCodeException + * @expectedExceptionMessage Invalid error correct level: 42 + */ + public function testInvalidEccLevelException(){ + new QROptions(['eccLevel' => 42]); + } +}