diff --git a/src/Browser.php b/src/Browser.php index 747ab3e..674bc71 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -216,6 +216,10 @@ final public function selectFieldOptions(string $selector, array $values): self */ final public function attachFile(string $selector, string $path): self { + if (!\file_exists($path)) { + throw new \InvalidArgumentException(\sprintf('File "%s" does not exist.', $path)); + } + $this->documentElement()->attachFileToField($selector, $path); return $this; diff --git a/tests/BrowserTests.php b/tests/BrowserTests.php index a0251cd..a076e4c 100644 --- a/tests/BrowserTests.php +++ b/tests/BrowserTests.php @@ -386,6 +386,19 @@ public function form_actions_by_field_name(): void ; } + /** + * @test + */ + public function cannot_attach_file_that_does_not_exist(): void + { + $this->expectException(\InvalidArgumentException::class); + + $this->browser() + ->visit('/page1') + ->attachFile('Input 5', '/invalid/file') + ; + } + /** * @test */