Skip to content

Commit

Permalink
Merge pull request #251 from martinssipenko/int-options
Browse files Browse the repository at this point in the history
image-dpi and image-quality must be passed as integers
  • Loading branch information
Albin Kerouanton authored Jul 3, 2017
2 parents 8941f12 + 7782ffc commit 3ba15a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ protected function buildCommand($binary, $input, $output, array $options = array
// Dont't add '--' if option is "cover" or "toc".
if (in_array($key, array('toc', 'cover'))) {
$command .= ' '.$key.' '.escapeshellarg($option);
} elseif (in_array($key, ['image-dpi', 'image-quality'])) {
$command .= ' --'.$key.' '. (int) $option;
} else {
$command .= ' --'.$key.' '.escapeshellarg($option);
}
Expand Down
26 changes: 18 additions & 8 deletions test/Knp/Snappy/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ public function dataForBuildCommand()
),
$theBinary . ' --allow ' . escapeshellarg('/path1') . ' --allow ' . escapeshellarg('/path2') . ' --no-background ' . escapeshellarg('1') . ' ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
[
$theBinary,
'http://the.url/',
'/the/path',
[
'image-dpi' => 100,
'image-quality' => 50,
],
$theBinary . ' ' . '--image-dpi 100 --image-quality 50 ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
],
);
}

Expand Down Expand Up @@ -756,7 +766,7 @@ public function dataForIsAssociativeArray()
),
);
}

public function testCleanupEmptyTemporaryFiles()
{
$generator = $this->getMock(
Expand All @@ -772,20 +782,20 @@ public function testCleanupEmptyTemporaryFiles()
$generator
->expects($this->once())
->method('unlink');

$create = new \ReflectionMethod($generator, 'createTemporaryFile');
$create->setAccessible(true);
$create->invoke($generator, null, null);

$files = new \ReflectionProperty($generator, 'temporaryFiles');
$files->setAccessible(true);
$this->assertCount(1, $files->getValue($generator));

$remove = new \ReflectionMethod($generator, 'removeTemporaryFiles');
$remove->setAccessible(true);
$remove->invoke($generator);
}

public function testleanupTemporaryFiles()
{
$generator = $this->getMock(
Expand All @@ -801,15 +811,15 @@ public function testleanupTemporaryFiles()
$generator
->expects($this->once())
->method('unlink');

$create = new \ReflectionMethod($generator, 'createTemporaryFile');
$create->setAccessible(true);
$create->invoke($generator, '<html/>', 'html');

$files = new \ReflectionProperty($generator, 'temporaryFiles');
$files->setAccessible(true);
$this->assertCount(1, $files->getValue($generator));

$remove = new \ReflectionMethod($generator, 'removeTemporaryFiles');
$remove->setAccessible(true);
$remove->invoke($generator);
Expand Down

0 comments on commit 3ba15a0

Please sign in to comment.