-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add guards for closed file before fopen, fwrite, fread, fclose. Closes …
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
use Mike42\Escpos\PrintConnectors\FilePrintConnector; | ||
|
||
class FilePrintConnectorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testTmpfile() | ||
{ | ||
// Should attempt to send data to the local printer by writing to it | ||
$tmpfname = tempnam("/tmp", "php"); | ||
$connector = new FilePrintConnector($tmpfname); | ||
$connector -> finalize(); | ||
$connector -> finalize(); // Silently do nothing if printer already closed | ||
unlink($tmpfname); | ||
} | ||
|
||
public function testReadAfterClose() | ||
{ | ||
// Should attempt to send data to the local printer by writing to it | ||
$this -> setExpectedException('Exception'); | ||
$tmpfname = tempnam("/tmp", "php"); | ||
try { | ||
$connector = new FilePrintConnector($tmpfname); | ||
$connector -> finalize(); | ||
$connector -> write("Test"); | ||
} finally { | ||
unlink($tmpfname); | ||
} | ||
} | ||
} |