QRCodeTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Class QRCodeTest
  4. *
  5. * @created 17.11.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest;
  11. use chillerlan\QRCode\{QROptions, QRCode};
  12. use chillerlan\QRCode\Data\QRCodeDataException;
  13. use chillerlan\QRCode\Output\QRCodeOutputException;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * Tests basic functions of the QRCode class
  17. */
  18. final class QRCodeTest extends TestCase{
  19. private QRCode $qrcode;
  20. private QROptions $options;
  21. /**
  22. * invoke test instances
  23. */
  24. protected function setUp():void{
  25. $this->qrcode = new QRCode;
  26. $this->options = new QROptions;
  27. }
  28. /**
  29. * tests if an exception is thrown when an invalid (built-in) output type is specified
  30. */
  31. public function testInitOutputInterfaceException():void{
  32. $this->expectException(QRCodeOutputException::class);
  33. $this->expectExceptionMessage('invalid output type');
  34. $this->options->outputType = 'foo';
  35. (new QRCode($this->options))->render('test');
  36. }
  37. /**
  38. * tests if an exception is thrown when trying to call getMatrix() without data (empty string, no data set)
  39. */
  40. public function testGetMatrixException():void{
  41. $this->expectException(QRCodeDataException::class);
  42. $this->expectExceptionMessage('QRCode::getMatrix() No data given.');
  43. $this->qrcode->getMatrix();
  44. }
  45. }