QRCodeTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Output\{QRCodeOutputException, QROutputInterface};
  13. use PHPUnit\Framework\TestCase;
  14. use stdClass;
  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 module');
  34. $this->options->outputType = 'foo';
  35. (new QRCode($this->options))->render('test');
  36. }
  37. /**
  38. * tests if an exception is thrown if the given output class does not exist
  39. */
  40. public function testInitCustomOutputInterfaceNotExistsException():void{
  41. $this->expectException(QRCodeOutputException::class);
  42. $this->expectExceptionMessage('invalid output module');
  43. $this->options->outputType = QROutputInterface::CUSTOM;
  44. (new QRCode($this->options))->render('test');
  45. }
  46. /**
  47. * tests if an exception is thrown if the given output class does not implement QROutputInterface
  48. */
  49. public function testInitCustomOutputInterfaceNotImplementsException():void{
  50. $this->expectException(QRCodeOutputException::class);
  51. $this->expectExceptionMessage('output module does not implement QROutputInterface');
  52. $this->options->outputType = QROutputInterface::CUSTOM;
  53. $this->options->outputInterface = stdClass::class;
  54. (new QRCode($this->options))->render('test');
  55. }
  56. }