QROptionsTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Class QROptionsTest
  4. *
  5. * @filesource QROptionsTest.php
  6. * @created 08.11.2018
  7. * @package chillerlan\QRCodeTest
  8. * @author smiley <smiley@chillerlan.net>
  9. * @copyright 2018 smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest;
  13. use chillerlan\QRCode\{QRCode,QROptions};
  14. use PHPUnit\Framework\TestCase;
  15. class QROptionsTest extends TestCase{
  16. /**
  17. * @var \chillerlan\QRCode\QROptions
  18. */
  19. protected $options;
  20. public function testVersionClamp(){
  21. $this->assertSame(40, (new QROptions(['version' => 42]))->version);
  22. $this->assertSame(1, (new QROptions(['version' => -42]))->version);
  23. $this->assertSame(21, (new QROptions(['version' => 21]))->version);
  24. }
  25. public function testVersionMinMaxClamp(){
  26. // normal clamp
  27. $o = new QROptions(['versionMin' => 5, 'versionMax' => 10]);
  28. $this->assertSame(5, $o->versionMin);
  29. $this->assertSame(10, $o->versionMax);
  30. // exceeding values
  31. $o = new QROptions(['versionMin' => -42, 'versionMax' => 42]);
  32. $this->assertSame(1, $o->versionMin);
  33. $this->assertSame(40, $o->versionMax);
  34. // min > max
  35. $o = new QROptions(['versionMin' => 10, 'versionMax' => 5]);
  36. $this->assertSame(5, $o->versionMin);
  37. $this->assertSame(10, $o->versionMax);
  38. $o = new QROptions(['versionMin' => 42, 'versionMax' => -42]);
  39. $this->assertSame(1, $o->versionMin);
  40. $this->assertSame(40, $o->versionMax);
  41. }
  42. public function testMaskPatternClamp(){
  43. $o = new QROptions(['maskPattern' => 42]);
  44. $this->assertSame(7, $o->maskPattern);
  45. $o = new QROptions(['maskPattern' => -42]);
  46. $this->assertSame(0, $o->maskPattern);
  47. $o = new QROptions(['maskPattern' => QRCode::MASK_PATTERN_AUTO]); // -1
  48. $this->assertSame(QRCode::MASK_PATTERN_AUTO, $o->maskPattern);
  49. }
  50. /**
  51. * @expectedException \chillerlan\QRCode\QRCodeException
  52. * @expectedExceptionMessage Invalid error correct level: 42
  53. */
  54. public function testInvalidEccLevelException(){
  55. new QROptions(['eccLevel' => 42]);
  56. }
  57. }