Skip to content

Commit

Permalink
Merge pull request #27 from darrynten/fix/nullcheckerror
Browse files Browse the repository at this point in the history
OutputPath is not really optional
  • Loading branch information
darrynten committed Apr 3, 2018
2 parents 6c73875 + 120ecfb commit 65aeba0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Pslayers.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function render()
$this->masterCanvas->compositeImage($layer->render(), $layer->composite, $layer->positionX, $layer->positionY);
}

if ($this->config->outputPath !== null) {
if (isset($this->config->outputPath) && $this->config->outputPath !== null) {
$this->masterCanvas->writeImage($this->config->outputPath);
}

Expand Down
54 changes: 54 additions & 0 deletions tests/Pslayers/PslayersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,58 @@ public function testMasterRender()

// $instance->render();
}

//Output path was not really optional
public function testOptionalOutputPath()
{
$width = 830;
$height = 360;

$config = [
'id' => 11,
'width' => $width,
'height' => $height,
];

$instance = new Pslayers($config);

// background layer
$backgroundLayer = new SolidLayer([
'id' => 'master-layer-solid-base',
'width' => $width,
'height' => $height,
'opacity' => 1.0,
'positionX' => 0,
'positionY' => 0,
'composite' => Imagick::COMPOSITE_DEFAULT,
'colour' => '#0F0',
]);

$instance->addLayer($backgroundLayer, 0);

// gradient layer
$gradientLayer = new GradientLayer([
'id' => 'master-layer-gradient',
'width' => $width,
'height' => $height / 2,
'opacity' => 0.9,
'positionX' => 0,
'positionY' => 0,
'composite' => Imagick::COMPOSITE_OVER,
'startColour' => '#F00',
'endColour' => 'transparent',
]);

$instance->addLayer($backgroundLayer, 0);
$instance->addLayer($gradientLayer, 1);
$img = $instance->render();

$this->assertInstanceOf(Pslayers::class, $instance);
$this->assertNotEmpty($instance->layers);
$this->assertInstanceOf(LayerCollection::class, $instance->layers);
$this->assertInstanceOf(Imagick::class, $img);
$this->assertEquals($width, $img->getImageWidth());
$this->assertEquals($height, $img->getImageHeight());
$this->assertEquals('png32', $img->getImageFormat());
}
}

0 comments on commit 65aeba0

Please sign in to comment.