QRCodeTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\QROptions;
  13. use chillerlan\QRCode\Output\QRImage;
  14. use chillerlan\QRCode\Output\QRImageOptions;
  15. use chillerlan\QRCode\Output\QRString;
  16. use chillerlan\QRCode\Output\QRStringOptions;
  17. class QRCodeTest extends \PHPUnit_Framework_TestCase{
  18. /**
  19. * @var \chillerlan\QRCode\QROptions
  20. */
  21. protected $options;
  22. /**
  23. * @var \chillerlan\QRCode\Output\QROutputInterface
  24. */
  25. protected $output;
  26. protected function setUp(){
  27. $this->options = new QROptions;
  28. $this->output = new QRString;
  29. }
  30. public function testInstance(){
  31. $this->assertInstanceOf(QRString::class, $this->output);
  32. $this->assertInstanceOf(QROptions::class, $this->options);
  33. $this->assertInstanceOf(QRCode::class, new QRCode('foobar', $this->output, $this->options));
  34. }
  35. public function stringDataProvider(){
  36. return [
  37. ['1234567890'],
  38. ['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
  39. ['#\\'],
  40. ['茗荷'],
  41. ];
  42. }
  43. /**
  44. * @dataProvider stringDataProvider
  45. */
  46. public function testDataCoverage($data){
  47. (new QRCode($data, new QRString))->getRawData();
  48. }
  49. public function testTypeAutoOverride(){
  50. $this->options->typeNumber = QRCode::TYPE_05;
  51. new QRCode('foobar', new QRString, $this->options);
  52. }
  53. /**
  54. * @expectedException \chillerlan\QRCode\QRCodeException
  55. * @expectedExceptionMessage No data given.
  56. */
  57. public function testNoDataException(){
  58. new QRCode('', new QRString);
  59. }
  60. /**
  61. * @expectedException \chillerlan\QRCode\QRCodeException
  62. * @expectedExceptionMessage Invalid error correct level: 42
  63. */
  64. public function testErrorCorrectLevelException(){
  65. $this->options->errorCorrectLevel = 42;
  66. new QRCode('foobar', new QRString, $this->options);
  67. }
  68. }