CupsPrintConnectorTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
  3. class CupsPrintConnectorTest extends PHPUnit\Framework\TestCase
  4. {
  5. private $connector;
  6. public function testPrinterExists()
  7. {
  8. $connector = $this->getMockConnector("FooPrinter", array("FooPrinter"));
  9. $connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
  10. $connector->finalize();
  11. }
  12. public function testPrinterDoesntExist()
  13. {
  14. $this -> expectException(BadMethodCallException::class);
  15. $connector = $this->getMockConnector("FooPrinter", array("OtherPrinter"));
  16. $connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
  17. $connector->finalize();
  18. }
  19. public function testNoPrinter()
  20. {
  21. $this -> expectException(BadMethodCallException::class);
  22. $connector = $this->getMockConnector("FooPrinter", array(""));
  23. }
  24. private function getMockConnector($path, array $printers)
  25. {
  26. $stub = $this->getMockBuilder('Mike42\Escpos\PrintConnectors\CupsPrintConnector')->setMethods(array (
  27. 'getCmdOutput',
  28. 'getLocalPrinters'
  29. ))->disableOriginalConstructor()->getMock();
  30. $stub->method('getCmdOutput')->willReturn("");
  31. $stub->method('getLocalPrinters')->willReturn($printers);
  32. $stub->__construct($path);
  33. return $stub;
  34. }
  35. }