FilePrintConnectorTest.php 946 B

123456789101112131415161718192021222324252627
  1. <?php
  2. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  3. class FilePrintConnectorTest extends PHPUnit\Framework\TestCase
  4. {
  5. public function testTmpfile()
  6. {
  7. // Should attempt to send data to the local printer by writing to it
  8. $tmpfname = tempnam("/tmp", "php");
  9. $connector = new FilePrintConnector($tmpfname);
  10. $connector -> finalize();
  11. $connector -> finalize(); // Silently do nothing if printer already closed
  12. $this -> assertEquals("", file_get_contents($tmpfname));
  13. unlink($tmpfname);
  14. }
  15. public function testReadAfterClose()
  16. {
  17. // Should attempt to send data to the local printer by writing to it
  18. $this -> expectException(Exception::class);
  19. $tmpfname = tempnam("/tmp", "php");
  20. $connector = new FilePrintConnector($tmpfname);
  21. $connector -> finalize();
  22. $connector -> write("Test");
  23. unlink($tmpfname);
  24. }
  25. }