Skip to content

Commit 45974cc

Browse files
authored
Merge pull request #266 from mikehaertl/264-tmpdir-in-constructor
Issue #264 Make tmpDir configurable via constructor
2 parents 844f289 + c11bb8d commit 45974cc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Pdf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ public function toString()
215215
*/
216216
public function setOptions($options = array())
217217
{
218+
// #264 tmpDir must be set before calling processOptions
219+
if (isset($options['tmpDir'])) {
220+
$this->tmpDir = $options['tmpDir'];
221+
unset($options['tmpDir']);
222+
}
218223
$options = $this->processOptions($options);
219224
foreach ($options as $key => $val) {
220225
if (is_int($key)) {

tests/PdfTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ public function testCanPassGlobalOptionsInConstructor()
255255
$inFile = $this->getHtmlAsset();
256256
$outFile = $this->getOutFile();
257257
$binary = $this->getBinary();
258+
$tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . uniqid();
259+
mkdir($tmpDir);
258260

259261
$pdf = new Pdf(array(
260262
'binary' => $binary,
263+
'tmpDir' => $tmpDir,
264+
'header-html' => '<p>header</p>',
261265
'no-outline',
262266
'margin-top' => 0,
263267
'allow' => array(
@@ -266,11 +270,11 @@ public function testCanPassGlobalOptionsInConstructor()
266270
),
267271
));
268272
$this->assertInstanceOf('mikehaertl\wkhtmlto\Pdf', $pdf->addPage($inFile));
273+
$this->assertEquals($tmpDir, $pdf->tmpDir);
269274
$this->assertTrue($pdf->saveAs($outFile));
270275

271-
$tmpFile = $pdf->getPdfFilename();
272276
$this->assertFileExists($outFile);
273-
$this->assertEquals("$binary --no-outline --margin-top '0' --allow '/tmp' --allow '/test' '$inFile' '$tmpFile'", (string) $pdf->getCommand());
277+
$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());
274278
unlink($outFile);
275279
}
276280
public function testCanSetGlobalOptions()
@@ -402,7 +406,6 @@ public function testCanUseXvfbRun()
402406
}
403407

404408

405-
406409
protected function getBinary()
407410
{
408411
return '/usr/local/bin/wkhtmltopdf';

0 commit comments

Comments
 (0)