diff --git a/.gitignore b/.gitignore index c97adfb..f6113e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -.php_cs.cache \ No newline at end of file +.php_cs.cache +.idea/ \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index b2870d2..2982c61 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,9 +10,6 @@ - - ./vendor - ./src diff --git a/src/Facades/PDF.php b/src/Facades/PDF.php index 5403dfd..085816f 100644 --- a/src/Facades/PDF.php +++ b/src/Facades/PDF.php @@ -4,6 +4,9 @@ use Illuminate\Support\Facades\Facade; +/** + * @mixin \VerumConsilium\Browsershot\PDF + */ class PDF extends Facade { /** diff --git a/src/Facades/Screenshot.php b/src/Facades/Screenshot.php index a9b77c4..c25df2f 100644 --- a/src/Facades/Screenshot.php +++ b/src/Facades/Screenshot.php @@ -4,6 +4,9 @@ use Illuminate\Support\Facades\Facade; +/** + * @mixin \VerumConsilium\Browsershot\Screenshot + */ class Screenshot extends Facade { /** diff --git a/src/Screenshot.php b/src/Screenshot.php index 3c00e24..bb3714c 100644 --- a/src/Screenshot.php +++ b/src/Screenshot.php @@ -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; } diff --git a/src/Traits/ContentLoadable.php b/src/Traits/ContentLoadable.php index 83815ca..083d2f3 100644 --- a/src/Traits/ContentLoadable.php +++ b/src/Traits/ContentLoadable.php @@ -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 { diff --git a/src/Wrapper.php b/src/Wrapper.php index 677b92d..1b2e9ce 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -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; @@ -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')) @@ -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'); } /** diff --git a/tests/ScreenshotTest.php b/tests/ScreenshotTest.php index 2428388..41d4e9e 100644 --- a/tests/ScreenshotTest.php +++ b/tests/ScreenshotTest.php @@ -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); + } }