BaconQrCodeGeneratorTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. use Mockery as m;
  3. use SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  4. class BaconQrCodeGeneratorTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function tearDown()
  7. {
  8. m::close();
  9. }
  10. public function setUp()
  11. {
  12. $this->writer = m::mock('\BaconQrCode\Writer');
  13. $this->format = m::mock('\BaconQrCode\Renderer\Image\RendererInterface');
  14. $this->qrCode = new BaconQrCodeGenerator($this->writer, $this->format);
  15. }
  16. public function test_it_sets_the_margin()
  17. {
  18. $this->format->shouldReceive('setMargin')
  19. ->with('50')
  20. ->once();
  21. $this->writer->shouldReceive('getRenderer')
  22. ->once()
  23. ->andReturn($this->format);
  24. $this->qrCode->margin(50);
  25. }
  26. public function test_it_sets_the_background_color()
  27. {
  28. $this->format->shouldReceive('setBackgroundColor')
  29. ->once();
  30. $this->writer->shouldReceive('getRenderer')
  31. ->once()
  32. ->andReturn($this->format);
  33. $this->qrCode->backgroundColor(255, 255, 255);
  34. }
  35. public function test_it_sets_the_foreground_color()
  36. {
  37. $this->format->shouldReceive('setForegroundColor')
  38. ->once();
  39. $this->writer->shouldReceive('getRenderer')
  40. ->once()
  41. ->andReturn($this->format);
  42. $this->qrCode->color(255, 255, 255);
  43. }
  44. public function test_it_sets_the_size()
  45. {
  46. $this->format->shouldReceive('setHeight')
  47. ->with(50)
  48. ->once();
  49. $this->format->shouldReceive('setWidth')
  50. ->with(50)
  51. ->once();
  52. $this->writer->shouldReceive('getRenderer')
  53. ->twice()
  54. ->andReturn($this->format);
  55. $this->qrCode->size(50);
  56. }
  57. public function test_it_sets_a_png_format()
  58. {
  59. $this->writer->shouldReceive('setRenderer')
  60. ->with('BaconQrCode\Renderer\Image\Png')
  61. ->once();
  62. $this->qrCode->format('png');
  63. }
  64. public function test_it_sets_a_eps_format()
  65. {
  66. $this->writer->shouldReceive('setRenderer')
  67. ->with('BaconQrCode\Renderer\Image\Eps')
  68. ->once();
  69. $this->qrCode->format('eps');
  70. }
  71. public function test_it_sets_a_svg_format()
  72. {
  73. $this->writer->shouldReceive('setRenderer')
  74. ->with('BaconQrCode\Renderer\Image\Svg')
  75. ->once();
  76. $this->qrCode->format('svg');
  77. }
  78. /**
  79. * @expectedException \InvalidArgumentException
  80. */
  81. public function test_it_throws_an_exception_with_an_invalid_format()
  82. {
  83. $this->qrCode->format('random');
  84. }
  85. public function test_it_generates_a_string()
  86. {
  87. $this->writer->shouldReceive('writeString')
  88. ->with('qrCode', m::type('string'), m::type('int'))
  89. ->once();
  90. $this->qrCode->generate('qrCode');
  91. }
  92. public function test_it_calls_a_valid_dynamic_method_and_generates_a_qrcode()
  93. {
  94. $this->writer->shouldReceive('writeString')
  95. ->once();
  96. $this->qrCode->phoneNumber('555-555-5555');
  97. }
  98. /**
  99. * @expectedException \BadMethodCallException
  100. */
  101. public function test_it_throws_an_exception_if_datatype_is_not_found()
  102. {
  103. $this->qrCode->notReal('foo');
  104. }
  105. }