Skip to content

Commit

Permalink
Failing test for #131 (#134)
Browse files Browse the repository at this point in the history
* Failing test for #131

* Code style

* add exception
  • Loading branch information
Synchro authored and freekmurze committed Nov 18, 2017
1 parent 7234b6a commit 782a4ef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

All notable changes to `Browsershot` will be documented in this file


### 3.11.1 - 2017-11-18

- improve error handling for when no extension is provided

### 3.11.0 - 2017-11-16

- add `setOption`
- refactor internals


### 3.10.0 - 2017-11-13

- add `setProxyServer`
Expand Down
8 changes: 7 additions & 1 deletion src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ public function __call($name, $arguments)

public function save(string $targetPath)
{
if (strtolower(pathinfo($targetPath, PATHINFO_EXTENSION)) === 'pdf') {
$extension = strtolower(pathinfo($targetPath, PATHINFO_EXTENSION));

if ($extension === '') {
throw CouldNotTakeBrowsershot::outputFileDidNotHaveAnExtension($targetPath);
}

if ($extension === 'pdf') {
return $this->savePdf($targetPath);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Exceptions/CouldNotTakeBrowsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public static function chromeOutputEmpty(string $screenShotPath)
{
return new static("For some reason Chrome did not write a file at `{$screenShotPath}`.");
}

public static function outputFileDidNotHaveAnExtension(string $path)
{
return new static("The given path `{$path}` did not contain an extension. Please append an extension.");
}
}
12 changes: 12 additions & 0 deletions tests/BrowsershotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Browsershot\Test;

use Spatie\Browsershot\Browsershot;
use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot;
use Symfony\Component\Process\Exception\ProcessFailedException;

class BrowsershotTest extends TestCase
Expand Down Expand Up @@ -55,6 +56,17 @@ public function it_can_take_a_high_density_screenshot()
$this->assertFileExists($targetPath);
}

/** @test */
public function it_cannot_save_without_an_extension()
{
$this->expectException(CouldNotTakeBrowsershot::class);

$targetPath = __DIR__.'/temp/testScreenshot';

Browsershot::url('https://example.com')
->save($targetPath);
}

/** @test */
public function it_can_take_a_full_page_screenshot()
{
Expand Down

0 comments on commit 782a4ef

Please sign in to comment.