Skip to content

Commit

Permalink
Merge pull request #266 from mikehaertl/264-tmpdir-in-constructor
Browse files Browse the repository at this point in the history
Issue #264 Make tmpDir configurable via constructor
  • Loading branch information
mikehaertl authored Feb 18, 2018
2 parents 844f289 + c11bb8d commit 45974cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ public function toString()
*/
public function setOptions($options = array())
{
// #264 tmpDir must be set before calling processOptions
if (isset($options['tmpDir'])) {
$this->tmpDir = $options['tmpDir'];
unset($options['tmpDir']);
}
$options = $this->processOptions($options);
foreach ($options as $key => $val) {
if (is_int($key)) {
Expand Down
9 changes: 6 additions & 3 deletions tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ public function testCanPassGlobalOptionsInConstructor()
$inFile = $this->getHtmlAsset();
$outFile = $this->getOutFile();
$binary = $this->getBinary();
$tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . uniqid();
mkdir($tmpDir);

$pdf = new Pdf(array(
'binary' => $binary,
'tmpDir' => $tmpDir,
'header-html' => '<p>header</p>',
'no-outline',
'margin-top' => 0,
'allow' => array(
Expand All @@ -266,11 +270,11 @@ public function testCanPassGlobalOptionsInConstructor()
),
));
$this->assertInstanceOf('mikehaertl\wkhtmlto\Pdf', $pdf->addPage($inFile));
$this->assertEquals($tmpDir, $pdf->tmpDir);
$this->assertTrue($pdf->saveAs($outFile));

$tmpFile = $pdf->getPdfFilename();
$this->assertFileExists($outFile);
$this->assertEquals("$binary --no-outline --margin-top '0' --allow '/tmp' --allow '/test' '$inFile' '$tmpFile'", (string) $pdf->getCommand());
$this->assertRegExp("#$binary --header-html '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.html' --no-outline --margin-top '0' --allow '/tmp' --allow '/test' '$inFile' '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.pdf'#", (string) $pdf->getCommand());
unlink($outFile);
}
public function testCanSetGlobalOptions()
Expand Down Expand Up @@ -402,7 +406,6 @@ public function testCanUseXvfbRun()
}



protected function getBinary()
{
return '/usr/local/bin/wkhtmltopdf';
Expand Down

0 comments on commit 45974cc

Please sign in to comment.