Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Allow Image::remove to be called on a "null" image #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Eloquent/Image.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
44 changes: 44 additions & 0 deletions tests/Unit/Eloquent/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace ZiffDavis\Laravel\EloquentImagery\Test\Unit\Eloquent;

use App\Console\Kernel;
use PHPUnit\Framework\TestCase;

class EloquentImageryObserverTest extends TestCase
{
public function setup()
{
$app = require __DIR__ . '/../../../vendor/laravel/laravel/bootstrap/app.php';
$app->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());
}
}