Skip to content

Commit

Permalink
Merge pull request #10 from verumconsilium/issue/9
Browse files Browse the repository at this point in the history
Call methods on Spatie\Image\Manipulations
  • Loading branch information
sgtpepper9907 committed Dec 12, 2018
2 parents 8b70a67 + 8a289cf commit 8876de7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
.php_cs.cache
.php_cs.cache
.idea/
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">./vendor</directory>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
Expand Down
3 changes: 3 additions & 0 deletions src/Facades/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Support\Facades\Facade;

/**
* @mixin \VerumConsilium\Browsershot\PDF
*/
class PDF extends Facade
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Facades/Screenshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Support\Facades\Facade;

/**
* @mixin \VerumConsilium\Browsershot\Screenshot
*/
class Screenshot extends Facade
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Screenshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function getMimeType(): string
public function useJPG(): Screenshot
{
$this->fileExtension = 'jpeg';
$this->setScreenshotType('jpeg', 100);
$this->browsershot()->setScreenshotType('jpeg', 100);

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/ContentLoadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ trait ContentLoadable
/**
* Renders and loads a given view browsershot
*
* @param string $view
* @param string $view
* @param array|null $data
* @param array|null $mergeData
* @return \VerumConsilium\Browsershot\Wrapper
* @throws \Throwable
*/
public function loadView(string $view, ?array $data = [], ?array $mergeData = []): Wrapper
{
Expand Down
14 changes: 9 additions & 5 deletions src/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
namespace VerumConsilium\Browsershot;

use Spatie\Browsershot\Browsershot;
use Spatie\Image\Manipulations;
use VerumConsilium\Browsershot\Traits\Responsable;
use VerumConsilium\Browsershot\Traits\ContentLoadable;
use VerumConsilium\Browsershot\Traits\Storable;

/**
* @mixin Browsershot
* @mixin Manipulations
*/
abstract class Wrapper
{
use Responsable, ContentLoadable, Storable;
Expand All @@ -25,7 +30,7 @@ abstract class Wrapper
*/
protected $tempFile;

public function __construct(?string $url = 'http://github.com/verumconsilium/laravel-browsershot')
public function __construct(string $url = 'http://github.com/verumconsilium/laravel-browsershot')
{
$browsershot = new Browsershot($url);
$browsershot->setNodeBinary(config('browsershot.nodeBinary'))
Expand Down Expand Up @@ -112,13 +117,12 @@ protected function generateTempFile(): Wrapper
*/
public function __call($name, $arguments): Wrapper
{
if (method_exists($this->browsershot(), $name) && is_callable([$this->browsershot(), $name])) {
try {
$this->browsershot()->$name(...$arguments);

return $this;
} catch (\Error $e) {
throw new \BadMethodCallException('Method ' . static::class . '::' . $name . '() does not exists');
}

throw new \BadMethodCallException('Method ' . static::class . '::' . $name . '() does not exists');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/ScreenshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ public function it_stores_a_jpg_screenshot_with_custom_name()

Storage::assertExists($path);
}

/** @test */
public function it_calls_methods_on_image_manipulation_class()
{
$screenshot = new Screenshot();
$url = 'https://verumconsilium.com';

Storage::fake();

$path = $screenshot->loadUrl($url)
->fit('contain', 12, 32)
->storeAs('public/', 'screenshot-filename.jpg');

Storage::assertExists($path);
}
}

0 comments on commit 8876de7

Please sign in to comment.