QRCodeTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *
  4. * @filesource QRCodeTest.php
  5. * @created 08.02.2016
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2015 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest;
  11. use chillerlan\QRCode\QRCode;
  12. use chillerlan\QRCode\QRConst;
  13. use chillerlan\QRCode\QROptions;
  14. use chillerlan\QRCode\Output\QRImage;
  15. use chillerlan\QRCode\Output\QRImageOptions;
  16. use chillerlan\QRCode\Output\QRString;
  17. use chillerlan\QRCode\Output\QRStringOptions;
  18. class QRCodeTest extends \PHPUnit_Framework_TestCase{
  19. /**
  20. * @var \chillerlan\QRCode\QROptions
  21. */
  22. protected $options;
  23. /**
  24. * @var \chillerlan\QRCode\Output\QROutputInterface
  25. */
  26. protected $output;
  27. protected function setUp(){
  28. $this->options = new QROptions;
  29. $this->output = new QRString;
  30. }
  31. public function testInstance(){
  32. $this->assertInstanceOf(QRString::class, $this->output);
  33. $this->assertInstanceOf(QROptions::class, $this->options);
  34. $this->assertInstanceOf(QRCode::class, new QRCode('foobar', $this->output, $this->options));
  35. }
  36. public function stringDataProvider(){
  37. return [
  38. ['1234567890'],
  39. ['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
  40. ['#\\'],
  41. ['茗荷'],
  42. ];
  43. }
  44. /**
  45. * @dataProvider stringDataProvider
  46. */
  47. public function testDataCoverage($data){
  48. (new QRCode($data, new QRString))->getRawData();
  49. }
  50. /**
  51. * @dataProvider stringDataProvider
  52. */
  53. public function testTypeAndErrorcorrectlevelCoverage($data){
  54. foreach(QRConst::MAX_BITS as $type => $x){
  55. foreach(QRConst::RSBLOCK as $eclevel => $y){
  56. $this->options->typeNumber = $type;
  57. $this->options->errorCorrectLevel = $eclevel;
  58. $this->assertInstanceOf(QRCode::class, new QRCode($data, new QRString, $this->options));
  59. }
  60. }
  61. }
  62. public function testTypeAutoOverride(){
  63. $this->options->typeNumber = QRCode::TYPE_05;
  64. new QRCode('foobar', new QRString, $this->options);
  65. }
  66. /**
  67. * @expectedException \chillerlan\QRCode\QRCodeException
  68. * @expectedExceptionMessage No data given.
  69. */
  70. public function testNoDataException(){
  71. new QRCode('', new QRString);
  72. }
  73. /**
  74. * @expectedException \chillerlan\QRCode\QRCodeException
  75. * @expectedExceptionMessage Invalid error correct level: 42
  76. */
  77. public function testErrorCorrectLevelException(){
  78. $this->options->errorCorrectLevel = 42;
  79. new QRCode('foobar', new QRString, $this->options);
  80. }
  81. }