From 20c093a332f9a7e275adb2a4d2f97327ec290731 Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:02:16 -0600 Subject: [PATCH 1/9] Ignore phpstorm metadata --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 25c7983ce79728d380a91dfa8f289df0c5cabc9d Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:02:41 -0600 Subject: [PATCH 2/9] Delete blacklist node, since it is not required --- phpunit.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index b2870d2..2982c61 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,9 +10,6 @@ - - ./vendor - ./src From 401f2e91a16c0caf58d407c81c67815692d23804 Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:03:05 -0600 Subject: [PATCH 3/9] Add mixin annotation for better support to facades --- src/Facades/PDF.php | 3 +++ src/Facades/Screenshot.php | 3 +++ 2 files changed, 6 insertions(+) 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 { /** From 85b831b4ed224766a19d6a97c378fbc7dbf80800 Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:04:00 -0600 Subject: [PATCH 4/9] Call setScreenshotType directly on browsershot --- src/Screenshot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From c68e44b353415731511f5315aa0d8e4f960da9ab Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:04:59 -0600 Subject: [PATCH 5/9] Fix docblock --- src/Traits/ContentLoadable.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 { From 8e60c781190466d02e6355be14047351947e622a Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:06:12 -0600 Subject: [PATCH 6/9] Add mixin annotations for chaining methods in browsershot --- src/Wrapper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Wrapper.php b/src/Wrapper.php index 677b92d..b8ab4f3 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; From 4217e2666dac730e458dc70efe63775f32adf061 Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:06:46 -0600 Subject: [PATCH 7/9] Remove nullable string param since it has a default --- src/Wrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wrapper.php b/src/Wrapper.php index b8ab4f3..8c4a1aa 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -30,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')) From 1d95b3c75668ad26eeeaccef297ddbfeafcfb4fc Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:07:18 -0600 Subject: [PATCH 8/9] Add ability to call methods on underlying image manipulations class --- src/Wrapper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Wrapper.php b/src/Wrapper.php index 8c4a1aa..1b2e9ce 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -117,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'); } /** From 8a289cfb5287bb0a2a9f3065f906d0bbb3bfabe4 Mon Sep 17 00:00:00 2001 From: David Angulo Date: Tue, 11 Dec 2018 23:07:43 -0600 Subject: [PATCH 9/9] Test calling of methods in Spatie\Manipulations --- tests/ScreenshotTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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); + } }