From 5312e70034c9e59c24dfc2df421797d89ef7f290 Mon Sep 17 00:00:00 2001 From: Dennis Heckman Date: Fri, 19 Oct 2018 15:00:02 -0500 Subject: [PATCH 1/2] test that Image::remove can be called multiple times --- tests/Unit/Eloquent/ImageTest.php | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/Unit/Eloquent/ImageTest.php diff --git a/tests/Unit/Eloquent/ImageTest.php b/tests/Unit/Eloquent/ImageTest.php new file mode 100644 index 0000000..79f885f --- /dev/null +++ b/tests/Unit/Eloquent/ImageTest.php @@ -0,0 +1,44 @@ +make(Kernel::class)->bootstrap(); + } + + public function testRemoveCanBeCalledMultipleTimes() + { + $foo = new TestAssets\FooModel(); + $foo->image->setStateProperties([ + 'path' => 'foo/bar.jpg', + 'extension' => 'jpg', + 'width' => 1, + 'height' => 1, + 'hash' => '1234', + 'timestamp' => 12345, + 'metadata' => [] + ]); + $foo->image->remove(); + $foo->image->remove(); + + $expected = [ + "path" => "", + "extension" => "", + "width" => null, + "height" => null, + "hash" => "", + "timestamp" => 0, + "metadata" => [] + ]; + + $this->assertSame($expected, $foo->image->getStateProperties()); + } +} + From 704a75de457cb8ef7ebd2201c088c5db2b98114f Mon Sep 17 00:00:00 2001 From: Dennis Heckman Date: Fri, 19 Oct 2018 15:01:41 -0500 Subject: [PATCH 2/2] remove throw when calling remove multiple times --- src/Eloquent/Image.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Eloquent/Image.php b/src/Eloquent/Image.php index d4cf5c8..55ae639 100644 --- a/src/Eloquent/Image.php +++ b/src/Eloquent/Image.php @@ -208,9 +208,6 @@ public function isFullyRemoved() public function remove() { - if ($this->path == '') { - throw new \RuntimeException('Called remove on an image that has no path'); - } $this->exists = false; $this->flush = true; $this->removeAtPathOnFlush = $this->path; @@ -286,4 +283,4 @@ public function __clone() { $this->metadata = clone $this->metadata; } -} \ No newline at end of file +}