Skip to content

Commit 8876de7

Browse files
Merge pull request #10 from verumconsilium/issue/9
Call methods on Spatie\Image\Manipulations
2 parents 8b70a67 + 8a289cf commit 8876de7

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
2-
.php_cs.cache
2+
.php_cs.cache
3+
.idea/

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
</testsuite>
1111
</testsuites>
1212
<filter>
13-
<blacklist>
14-
<directory suffix=".php">./vendor</directory>
15-
</blacklist>
1613
<whitelist processUncoveredFilesFromWhitelist="true">
1714
<directory suffix=".php">./src</directory>
1815
</whitelist>

src/Facades/PDF.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Support\Facades\Facade;
66

7+
/**
8+
* @mixin \VerumConsilium\Browsershot\PDF
9+
*/
710
class PDF extends Facade
811
{
912
/**

src/Facades/Screenshot.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Support\Facades\Facade;
66

7+
/**
8+
* @mixin \VerumConsilium\Browsershot\Screenshot
9+
*/
710
class Screenshot extends Facade
811
{
912
/**

src/Screenshot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function getMimeType(): string
3434
public function useJPG(): Screenshot
3535
{
3636
$this->fileExtension = 'jpeg';
37-
$this->setScreenshotType('jpeg', 100);
37+
$this->browsershot()->setScreenshotType('jpeg', 100);
3838

3939
return $this;
4040
}

src/Traits/ContentLoadable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ trait ContentLoadable
1010
/**
1111
* Renders and loads a given view browsershot
1212
*
13-
* @param string $view
13+
* @param string $view
1414
* @param array|null $data
1515
* @param array|null $mergeData
1616
* @return \VerumConsilium\Browsershot\Wrapper
17+
* @throws \Throwable
1718
*/
1819
public function loadView(string $view, ?array $data = [], ?array $mergeData = []): Wrapper
1920
{

src/Wrapper.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
namespace VerumConsilium\Browsershot;
44

55
use Spatie\Browsershot\Browsershot;
6+
use Spatie\Image\Manipulations;
67
use VerumConsilium\Browsershot\Traits\Responsable;
78
use VerumConsilium\Browsershot\Traits\ContentLoadable;
89
use VerumConsilium\Browsershot\Traits\Storable;
910

11+
/**
12+
* @mixin Browsershot
13+
* @mixin Manipulations
14+
*/
1015
abstract class Wrapper
1116
{
1217
use Responsable, ContentLoadable, Storable;
@@ -25,7 +30,7 @@ abstract class Wrapper
2530
*/
2631
protected $tempFile;
2732

28-
public function __construct(?string $url = 'http://github.com/verumconsilium/laravel-browsershot')
33+
public function __construct(string $url = 'http://github.com/verumconsilium/laravel-browsershot')
2934
{
3035
$browsershot = new Browsershot($url);
3136
$browsershot->setNodeBinary(config('browsershot.nodeBinary'))
@@ -112,13 +117,12 @@ protected function generateTempFile(): Wrapper
112117
*/
113118
public function __call($name, $arguments): Wrapper
114119
{
115-
if (method_exists($this->browsershot(), $name) && is_callable([$this->browsershot(), $name])) {
120+
try {
116121
$this->browsershot()->$name(...$arguments);
117-
118122
return $this;
123+
} catch (\Error $e) {
124+
throw new \BadMethodCallException('Method ' . static::class . '::' . $name . '() does not exists');
119125
}
120-
121-
throw new \BadMethodCallException('Method ' . static::class . '::' . $name . '() does not exists');
122126
}
123127

124128
/**

tests/ScreenshotTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ public function it_stores_a_jpg_screenshot_with_custom_name()
5151

5252
Storage::assertExists($path);
5353
}
54+
55+
/** @test */
56+
public function it_calls_methods_on_image_manipulation_class()
57+
{
58+
$screenshot = new Screenshot();
59+
$url = 'https://verumconsilium.com';
60+
61+
Storage::fake();
62+
63+
$path = $screenshot->loadUrl($url)
64+
->fit('contain', 12, 32)
65+
->storeAs('public/', 'screenshot-filename.jpg');
66+
67+
Storage::assertExists($path);
68+
}
5469
}

0 commit comments

Comments
 (0)