Skip to content

Commit

Permalink
add layor method test
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jun 15, 2017
1 parent 28adc0e commit df7e0e3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/Exceptions/InvalidFormat.php
Expand Up @@ -2,6 +2,8 @@

namespace Spatie\PdfToImage\Exceptions;

class InvalidFormat extends \Exception
use Exception;

class InvalidFormat extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/InvalidLayerMethod.php
Expand Up @@ -2,6 +2,8 @@

namespace Spatie\PdfToImage\Exceptions;

class InvalidLayerMethod extends \Exception
use Exception;

class InvalidLayerMethod extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/PageDoesNotExist.php
Expand Up @@ -2,6 +2,8 @@

namespace Spatie\PdfToImage\Exceptions;

class PageDoesNotExist extends \Exception
use Exception;

class PageDoesNotExist extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/PdfDoesNotExist.php
Expand Up @@ -2,6 +2,8 @@

namespace Spatie\PdfToImage\Exceptions;

class PdfDoesNotExist extends \Exception
use Exception;

class PdfDoesNotExist extends Exception
{
}
19 changes: 9 additions & 10 deletions src/Pdf.php
Expand Up @@ -64,7 +64,7 @@ public function setResolution($resolution)
public function setOutputFormat($outputFormat)
{
if (! $this->isValidOutputFormat($outputFormat)) {
throw new InvalidFormat('Format '.$outputFormat.' is not supported');
throw new InvalidFormat("Format {$outputFormat} is not supported");
}

$this->outputFormat = $outputFormat;
Expand All @@ -73,9 +73,9 @@ public function setOutputFormat($outputFormat)
}

/**
* Sets the layer method for \Imagicl::mergeImageLayers()
* Sets the layer method for Imagick::mergeImageLayers()
* If int, should correspond to a predefined LAYERMETHOD constant.
* If null, \Imagicl::mergeImageLayers() will not be called.
* If null, Imagick::mergeImageLayers() will not be called.
*
* @param int|null
*
Expand All @@ -88,14 +88,13 @@ public function setOutputFormat($outputFormat)
*/
public function setLayerMethod($layerMethod)
{
if (
is_int($layerMethod) === false &&
is_null($layerMethod) === false
) {
throw new InvalidLayerMethod('LayerMethod must be integer or null');
if (! is_int($layerMethod)) {
throw new InvalidLayerMethod('LayerMethod must be an integer');
}

$this->layerMethod = $layerMethod;

return $this;
}

/**
Expand All @@ -122,7 +121,7 @@ public function isValidOutputFormat($outputFormat)
public function setPage($page)
{
if ($page > $this->getNumberOfPages()) {
throw new PageDoesNotExist('Page '.$page.' does not exist');
throw new PageDoesNotExist("Page {$page} does not exist");
}

$this->page = $page;
Expand Down Expand Up @@ -151,7 +150,7 @@ public function saveImage($pathToImage)
{
$imageData = $this->getImageData($pathToImage);

return file_put_contents($pathToImage, $imageData) === false ? false : true;
return file_put_contents($pathToImage, $imageData) !== false;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/PdfTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\PdfToImage\Test;

use Imagick;
use PHPUnit\Framework\TestCase;
use Spatie\PdfToImage\Pdf;
use Spatie\PdfToImage\Exceptions\InvalidFormat;
Expand Down Expand Up @@ -94,4 +95,19 @@ public function it_will_accept_a_specified_file_type_and_convert_to_it()
$this->assertSame($imagick->getFormat(), 'png');
$this->assertNotSame($imagick->getFormat(), 'jpg');
}

/** @test */
public function it_can_accept_a_layer()
{
$image = (new Pdf($this->testFile))
->setLayerMethod(Imagick::LAYERMETHOD_FLATTEN)
->setResolution(72)
->getImageData('test.jpg')
->getImageResolution();

$this->assertEquals($image['x'], 72);
$this->assertEquals($image['y'], 72);
$this->assertNotEquals($image['x'], 144);
$this->assertNotEquals($image['y'], 144);
}
}

0 comments on commit df7e0e3

Please sign in to comment.