diff --git a/src/Facades/Image.php b/src/Facades/Image.php index 83486f3..39a13ac 100644 --- a/src/Facades/Image.php +++ b/src/Facades/Image.php @@ -31,7 +31,7 @@ * @method static void commit() * @method static void beginTransaction() * @method static self quality(int $quality) - * + * **/ class Image extends Facade { diff --git a/src/Image.php b/src/Image.php index 7c74070..1ae4cd6 100644 --- a/src/Image.php +++ b/src/Image.php @@ -4,8 +4,8 @@ use Illuminate\Http\UploadedFile; use Intervention\Image\Facades\Image as Intervention; -use Symfony\Component\Routing\Exception\InvalidParameterException; use Intervention\Image\Image as InterventionImage; +use Symfony\Component\Routing\Exception\InvalidParameterException; class Image { @@ -16,7 +16,7 @@ class Image /** * Image quality. - * + * * @var int */ public int $quality = 90; @@ -50,7 +50,7 @@ class Image /** * On Transactioning it shows the image is going to be replave. - * + * * @var bool */ private bool $willBeReplace = false; @@ -77,7 +77,7 @@ public function disk(string $disk): self $this->hiddenPath = config("image.disks.{$disk}"); if (!$this->hiddenPath) { - throw new InvalidParameterException('Undefined disk ' . $disk); + throw new InvalidParameterException('Undefined disk '.$disk); } $this->disk = $disk; @@ -86,7 +86,7 @@ public function disk(string $disk): self } /** - * Determines way of saving. $image can be UploadedFile laravel object or intervention. + * Determines way of saving. $image can be UploadedFile laravel object or intervention. * * @param \Illuminate\Http\UploadedFile|Intervention\Image\Image $image * @@ -102,7 +102,7 @@ public function raw($image): self } /** - * Determines way of saving. $image can be UploadedFile laravel object or intervention. + * Determines way of saving. $image can be UploadedFile laravel object or intervention. * * @param \Illuminate\Http\UploadedFile|Intervention\Image\Image $image * @@ -131,7 +131,7 @@ public function fake(): void * Sets image quality. * * @param int $quality - * + * * @return self */ public function quality(int $quality): self @@ -167,14 +167,14 @@ public function save(bool $upsize = false, ?\Closure $closure = null) // saving image if ($this->transactioning) { $this->transactionBag[] = [ - 'image' => $this->image, - 'sizes' => $this->sizes, - 'imagePath' => $this->imagePath, + 'image' => $this->image, + 'sizes' => $this->sizes, + 'imagePath' => $this->imagePath, 'imageDirectory' => $this->imageDirectory, - 'upsize' => $upsize, - 'disk' => $this->disk, - 'willBeReplace' => $this->willBeReplace, - 'quality' => $this->quality, + 'upsize' => $upsize, + 'disk' => $this->disk, + 'willBeReplace' => $this->willBeReplace, + 'quality' => $this->quality, ]; } else { if (!$this->mkdirIfNotExists($this->imageDirectory)) { @@ -226,13 +226,13 @@ public function replace(bool $upsize = false, ?\Closure $closure = null) /** * Stores image(s). - * + * * @param Intervention\Image\Image $image - * @param null|array $sizes - * @param array|string $imagePath - * @param bool $upsize - * @param int $quality - * + * @param null|array $sizes + * @param array|string $imagePath + * @param bool $upsize + * @param int $quality + * * @return void */ private function store(InterventionImage $image, ?array $sizes, $imagePath, bool $upsize, int $quality): void @@ -281,7 +281,7 @@ private function mkdirIfNotExists(string $path): bool */ private function disk_path(string $path): string { - return $this->hiddenPath . DIRECTORY_SEPARATOR . $path; + return $this->hiddenPath.DIRECTORY_SEPARATOR.$path; } /** diff --git a/src/Pathable.php b/src/Pathable.php index 2c451c3..16333dd 100644 --- a/src/Pathable.php +++ b/src/Pathable.php @@ -179,7 +179,7 @@ public function be(string $nameWithFormat): self $name = $nameWithFormat; array_pop($name); - + $this->imageName = trim(implode('.', $name), '.'); return $this; @@ -209,7 +209,7 @@ private function setDefaultsForImagePath(): void private function setRawDefaults(): void { $this->sizesDirectory = $this->random(false); - $this->imageFormat = preg_replace('/image\//', '',$this->image->mime() ?? 'image/png'); + $this->imageFormat = preg_replace('/image\//', '', $this->image->mime() ?? 'image/png'); $this->imageName = $this->random(); $this->hiddenPath = config('image.disks.public'); $this->disk = 'public'; diff --git a/src/Sizeable.php b/src/Sizeable.php index 7346dcb..e27100c 100644 --- a/src/Sizeable.php +++ b/src/Sizeable.php @@ -28,10 +28,12 @@ public function setDefaultSizeFor(array $image, string $sizeName, ?string $pathK if ($pathKeys != 'index') { if (array_key_exists($sizeName, $image[$pathKeys])) { $image['default_size'] = $sizeName; + return $image; } } else { $image['default_size'] = $sizeName; + return $image; } diff --git a/src/Transaction.php b/src/Transaction.php index 9e4283b..ca91df2 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -2,39 +2,37 @@ namespace AmirHossein5\LaravelImage; -use AmirHossein5\LaravelImage\Facades\Image; - trait Transaction { /** * Whether on transaction or not. - * + * * @var bool */ protected bool $transactioning = false; /** * Array of saved images. - * + * * @var array */ protected array $transactionBag = []; /** * Transaction function. - * + * * @param \Closure $closure - * @param int $attempts = 1 - * - * @return void - * + * @param int $attempts = 1 + * * @throws \Throwable + * + * @return void */ public function transaction(\Closure $callback, int $maxAttempts = 1): void { if ($maxAttempts <= 0) { throw new \LogicException('max attempts should be more than 0'); - } + } for ($currentAttempt = 1; $currentAttempt <= $maxAttempts; $currentAttempt++) { $this->beginTransaction(); @@ -56,7 +54,7 @@ public function transaction(\Closure $callback, int $maxAttempts = 1): void $currentAttempt, $maxAttempts ); - + continue; } } @@ -64,7 +62,7 @@ public function transaction(\Closure $callback, int $maxAttempts = 1): void /** * Starts the transaction. - * + * * @return void */ public function beginTransaction(): void @@ -74,7 +72,7 @@ public function beginTransaction(): void /** * Commits the transaction. - * + * * @return void */ public function commit(): void @@ -82,7 +80,7 @@ public function commit(): void if ($this->transactioning === false) { return; } - + foreach ($this->transactionBag as $transactioned) { $this->disk($transactioned['disk']); $this->mkdirIfNotExists($transactioned['imageDirectory']); @@ -106,7 +104,7 @@ public function commit(): void /** * RollBacks the transaction. - * + * * @return void */ public function rollBack(): void @@ -120,20 +118,21 @@ public function rollBack(): void } /** - * Handles the exception - * + * Handles the exception. + * * @param \Throwable $e - * @param int $currentAttempts = 1 - * @param int $maxAttempts = 1 - * - * @return void - * + * @param int $currentAttempts = 1 + * @param int $maxAttempts = 1 + * * @throws \Throwable + * + * @return void */ private function handleTransactionException(\Throwable $e, int $currentAttempt = 1, int $maxAttempts = 1): void { if ($currentAttempt >= $maxAttempts) { $this->rollBack(); + throw $e; } } diff --git a/tests/Feature/BaseTest.php b/tests/Feature/BaseTest.php index 9489753..dff9485 100644 --- a/tests/Feature/BaseTest.php +++ b/tests/Feature/BaseTest.php @@ -4,9 +4,6 @@ use AmirHossein5\LaravelImage\Facades\Image; use AmirHossein5\LaravelImage\Tests\TestCase; -use Illuminate\Filesystem\Filesystem; -use LogicException; -use Symfony\Component\Routing\Exception\InvalidParameterException; use Intervention\Image\Facades\Image as Intervention; class BaseTest extends TestCase @@ -21,7 +18,7 @@ public function test_converts_to_correct_directory_separator() ->save(); $this->assertStringContainsString( - '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . '3' . DIRECTORY_SEPARATOR, + '1'.DIRECTORY_SEPARATOR.'2'.DIRECTORY_SEPARATOR.'3'.DIRECTORY_SEPARATOR, $image['imageDirectory'] ); } @@ -82,7 +79,7 @@ public function test_result_array() foreach ($image['index'] as $img) { $this->assertFileExists(public_path($img)); } - foreach (config('image.' . config('image.use_size')) as $sizeName => $size) { + foreach (config('image.'.config('image.use_size')) as $sizeName => $size) { $this->assertArrayHasKey($sizeName, $image['index']); } @@ -103,9 +100,9 @@ public function test_result_array() $this->assertEquals(3, count($image)); $this->assertTrue(!is_array($image['index'])); $this->assertArrayNotHasKey('default_size', $image); - $this->assertDirectoryExists(storage_path('app/' . $image['imageDirectory'])); + $this->assertDirectoryExists(storage_path('app/'.$image['imageDirectory'])); $this->assertEquals('storage', $image['disk']); - $this->assertFileExists(storage_path('app/' . $image['index'])); + $this->assertFileExists(storage_path('app/'.$image['index'])); $image = Image::raw($this->image)->resize(50, 30)->save(); @@ -123,7 +120,7 @@ public function test_result_array() $this->assertArrayNotHasKey('default_size', $image); $this->assertDirectoryExists(public_path($image['imageDirectory'])); $this->assertEquals('public', $image['disk']); - foreach (config('image.' . config('image.use_size')) as $sizeName => $size) { + foreach (config('image.'.config('image.use_size')) as $sizeName => $size) { $this->assertArrayHasKey($sizeName, $image['index']); } foreach ($image['index'] as $img) { @@ -162,12 +159,12 @@ public function test_result_array_can_be_get_manually() $this->assertEquals( $this->directorySeparator( - config('image.root_directory') . '/' . 'post' . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $this->random(false) + config('image.root_directory').'/'.'post'.'/'.date('Y').'/'.date('m').'/'.date('d').'/'.$this->random(false) ), $image['imageDirectory'] ); - foreach (config('image.' . config('image.use_size')) as $sizeName => $size) { + foreach (config('image.'.config('image.use_size')) as $sizeName => $size) { $this->assertArrayHasKey($sizeName, $image['index']); } } @@ -232,19 +229,19 @@ public function test_manually_way_properties() ->quality(0) ->save(false, function ($image) { return [ - 'image' => $image->image, - 'sizes' => $image->sizes, - 'defaultSize' => $image->defaultSize, - 'imagePath' => $image->imagePath, - 'imageDirectory' => $image->imageDirectory, - 'imageName' => $image->imageName, - 'imageFormat' => $image->imageFormat, - 'disk' => $image->disk, - 'rootDirectory' => $image->rootDirectory, + 'image' => $image->image, + 'sizes' => $image->sizes, + 'defaultSize' => $image->defaultSize, + 'imagePath' => $image->imagePath, + 'imageDirectory' => $image->imageDirectory, + 'imageName' => $image->imageName, + 'imageFormat' => $image->imageFormat, + 'disk' => $image->disk, + 'rootDirectory' => $image->rootDirectory, 'exclusiveDirectory' => $image->exclusiveDirectory, 'archiveDirectories' => $image->archiveDirectories, - 'sizesDirectory' => $image->sizesDirectory, - 'quality' => $image->quality, + 'sizesDirectory' => $image->sizesDirectory, + 'quality' => $image->quality, ]; }); @@ -254,19 +251,19 @@ public function test_manually_way_properties() ->setSizesDirectory($random) ->save(false, function ($image) { return [ - 'image' => $image->image, - 'sizes' => $image->sizes, - 'defaultSize' => $image->defaultSize, - 'imagePath' => $image->imagePath, - 'imageDirectory' => $image->imageDirectory, - 'imageName' => $image->imageName, - 'imageFormat' => $image->imageFormat, - 'disk' => $image->disk, - 'rootDirectory' => $image->rootDirectory, + 'image' => $image->image, + 'sizes' => $image->sizes, + 'defaultSize' => $image->defaultSize, + 'imagePath' => $image->imagePath, + 'imageDirectory' => $image->imageDirectory, + 'imageName' => $image->imageName, + 'imageFormat' => $image->imageFormat, + 'disk' => $image->disk, + 'rootDirectory' => $image->rootDirectory, 'exclusiveDirectory' => $image->exclusiveDirectory, 'archiveDirectories' => $image->archiveDirectories, - 'sizesDirectory' => $image->sizesDirectory, - 'quality' => $image->quality, + 'sizesDirectory' => $image->sizesDirectory, + 'quality' => $image->quality, ]; }); @@ -277,19 +274,19 @@ public function test_manually_way_properties() ->setSizesDirectory($random) ->save(false, function ($image) { return [ - 'image' => $image->image, - 'sizes' => $image->sizes, - 'defaultSize' => $image->defaultSize, - 'imagePath' => $image->imagePath, - 'imageDirectory' => $image->imageDirectory, - 'imageName' => $image->imageName, - 'imageFormat' => $image->imageFormat, - 'disk' => $image->disk, - 'rootDirectory' => $image->rootDirectory, + 'image' => $image->image, + 'sizes' => $image->sizes, + 'defaultSize' => $image->defaultSize, + 'imagePath' => $image->imagePath, + 'imageDirectory' => $image->imageDirectory, + 'imageName' => $image->imageName, + 'imageFormat' => $image->imageFormat, + 'disk' => $image->disk, + 'rootDirectory' => $image->rootDirectory, 'exclusiveDirectory' => $image->exclusiveDirectory, 'archiveDirectories' => $image->archiveDirectories, - 'sizesDirectory' => $image->sizesDirectory, - 'quality' => $image->quality, + 'sizesDirectory' => $image->sizesDirectory, + 'quality' => $image->quality, ]; }); @@ -302,19 +299,19 @@ public function test_manually_way_properties() ->in('post/') ->save(false, function ($image) { return [ - 'image' => $image->image, - 'sizes' => $image->sizes, - 'defaultSize' => $image->defaultSize, - 'imagePath' => $image->imagePath, - 'imageDirectory' => $image->imageDirectory, - 'imageName' => $image->imageName, - 'imageFormat' => $image->imageFormat, - 'disk' => $image->disk, - 'rootDirectory' => $image->rootDirectory, + 'image' => $image->image, + 'sizes' => $image->sizes, + 'defaultSize' => $image->defaultSize, + 'imagePath' => $image->imagePath, + 'imageDirectory' => $image->imageDirectory, + 'imageName' => $image->imageName, + 'imageFormat' => $image->imageFormat, + 'disk' => $image->disk, + 'rootDirectory' => $image->rootDirectory, 'exclusiveDirectory' => $image->exclusiveDirectory, 'archiveDirectories' => $image->archiveDirectories, - 'sizesDirectory' => $image->sizesDirectory, - 'quality' => $image->quality, + 'sizesDirectory' => $image->sizesDirectory, + 'quality' => $image->quality, ]; }); @@ -323,12 +320,12 @@ public function test_manually_way_properties() /** * Tests the output of manually given image. - * + * * @param array $image * @param array $sizes - * @param bool $isRaw - * @param int $quality - * + * @param bool $isRaw + * @param int $quality + * * @return void */ private function propertiesAreValid(array $image, array $sizes = [], bool $isRaw = false, int $quality = 90, int $random): void @@ -337,10 +334,10 @@ private function propertiesAreValid(array $image, array $sizes = [], bool $isRaw if ($sizes) { foreach ($sizes as $sizeName => $dimensions) { $this->assertArrayHasKey($sizeName, $image['sizes']); - }; + } } else { $this->assertNull($image['sizes']); - } + } $this->assertNull($image['defaultSize']); if (is_array($image['imagePath'])) { foreach ($image['imagePath'] as $path) { @@ -354,7 +351,7 @@ private function propertiesAreValid(array $image, array $sizes = [], bool $isRaw if ($sizes) { $fileName = pathinfo(public_path($image['imagePath']['small']), PATHINFO_FILENAME); $extension = pathinfo(public_path($image['imagePath']['small']), PATHINFO_EXTENSION); - $this->assertEquals($fileName, $image['imageName'] . '_small'); + $this->assertEquals($fileName, $image['imageName'].'_small'); } else { $fileName = pathinfo(public_path($image['imagePath']), PATHINFO_FILENAME); $extension = pathinfo(public_path($image['imagePath']), PATHINFO_EXTENSION); @@ -366,10 +363,10 @@ private function propertiesAreValid(array $image, array $sizes = [], bool $isRaw $this->assertEquals(config('image.root_directory'), $image['rootDirectory']); $this->assertEquals('post', $image['exclusiveDirectory']); $this->assertEquals( - $this->directorySeparator(date('Y') . '/' . date('m') . '/' . date('d')), + $this->directorySeparator(date('Y').'/'.date('m').'/'.date('d')), $image['archiveDirectories'] ); - } + } $this->assertEquals($random, $image['sizesDirectory']); $this->assertEquals($quality, $image['quality']); } diff --git a/tests/Feature/ExceptionsTest.php b/tests/Feature/ExceptionsTest.php index 8741e0a..cf3bb4a 100644 --- a/tests/Feature/ExceptionsTest.php +++ b/tests/Feature/ExceptionsTest.php @@ -4,10 +4,8 @@ use AmirHossein5\LaravelImage\Facades\Image; use AmirHossein5\LaravelImage\Tests\TestCase; -use Illuminate\Filesystem\Filesystem; use LogicException; use Symfony\Component\Routing\Exception\InvalidParameterException; -use Intervention\Image\Facades\Image as Intervention; class ExceptionsTest extends TestCase { diff --git a/tests/Feature/FakeTest.php b/tests/Feature/FakeTest.php index 5a7a60a..d7222fd 100644 --- a/tests/Feature/FakeTest.php +++ b/tests/Feature/FakeTest.php @@ -4,10 +4,6 @@ use AmirHossein5\LaravelImage\Facades\Image; use AmirHossein5\LaravelImage\Tests\TestCase; -use Illuminate\Filesystem\Filesystem; -use LogicException; -use Symfony\Component\Routing\Exception\InvalidParameterException; -use Intervention\Image\Facades\Image as Intervention; class FakeTest extends TestCase { diff --git a/tests/Feature/PathableTest.php b/tests/Feature/PathableTest.php index b4dcc77..0af42a3 100644 --- a/tests/Feature/PathableTest.php +++ b/tests/Feature/PathableTest.php @@ -4,11 +4,6 @@ use AmirHossein5\LaravelImage\Facades\Image; use AmirHossein5\LaravelImage\Tests\TestCase; -use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Facades\Storage; -use LogicException; -use Symfony\Component\Routing\Exception\InvalidParameterException; -use Intervention\Image\Facades\Image as Intervention; class PathableTest extends TestCase { @@ -47,11 +42,11 @@ public function test_dierctory_setters_for_make_method() ->save(); $this->assertEquals( - $this->directorySeparator("root/post/archive/sizes/name_large.png"), + $this->directorySeparator('root/post/archive/sizes/name_large.png'), $image['index']['large'] ); $this->assertEquals( - $this->directorySeparator("root/post/archive/sizes"), + $this->directorySeparator('root/post/archive/sizes'), $image['imageDirectory'] ); foreach ($image['index'] as $img) { @@ -88,7 +83,7 @@ public function test_directory_setters_for_raw_method() $image['imageDirectory'] ); foreach ($image['index'] as $img) { - $this->assertFileExists(storage_path('app/' . $img)); + $this->assertFileExists(storage_path('app/'.$img)); } } } diff --git a/tests/Feature/RemoveableTest.php b/tests/Feature/RemoveableTest.php index 62de212..a651ff6 100644 --- a/tests/Feature/RemoveableTest.php +++ b/tests/Feature/RemoveableTest.php @@ -30,54 +30,54 @@ public function test_rm_works() $random = $this->random(); $image = Image::raw($this->image) - ->be($random . '.png') + ->be($random.'.png') ->save(); - $this->assertFileExists(public_path($random . '.png')); + $this->assertFileExists(public_path($random.'.png')); Image::rm($image); $this->assertTrue(Image::wasRecentlyRemoved()); - $this->assertFalse(file_exists(public_path($random . '.png'))); + $this->assertFalse(file_exists(public_path($random.'.png'))); $random = $this->random(); $image = Image::raw($this->image) ->in('test') - ->be($random . '.png') + ->be($random.'.png') ->save(); - $this->assertFileExists(public_path('test/' . $random . '.png')); + $this->assertFileExists(public_path('test/'.$random.'.png')); Image::disk('public')->rm($image); $this->assertTrue(Image::wasRecentlyRemoved()); - $this->assertFileDoesNotExist(public_path('test/' . $random . '.png')); + $this->assertFileDoesNotExist(public_path('test/'.$random.'.png')); $random = $this->random(); $image = Image::raw($this->image) - ->be($random . '.png') + ->be($random.'.png') ->disk('storage') ->save(); - $this->assertFileExists(storage_path('app/' . $random . '.png')); + $this->assertFileExists(storage_path('app/'.$random.'.png')); Image::disk('storage')->rm($image); $this->assertTrue(Image::wasRecentlyRemoved()); - $this->assertFileDoesNotExist(storage_path('app/test/' . $random . '.png')); + $this->assertFileDoesNotExist(storage_path('app/test/'.$random.'.png')); $random = $this->random(); $image = Image::raw($this->image) ->in('test') ->disk('storage') - ->be($random . '.png') + ->be($random.'.png') ->save(); - $this->assertFileExists(storage_path('app/test/' . $random . '.png')); + $this->assertFileExists(storage_path('app/test/'.$random.'.png')); Image::disk('storage')->rm($image); $this->assertTrue(Image::wasRecentlyRemoved()); - $this->assertFileDoesNotExist(storage_path('app/test/' . $random . '.png')); + $this->assertFileDoesNotExist(storage_path('app/test/'.$random.'.png')); $images = Image::make($this->image) ->setExclusiveDirectory('post') @@ -96,7 +96,6 @@ public function test_rm_works() } $this->assertTrue(Image::wasRecentlyRemoved()); - $image = Image::raw($this->image) ->disk('public') ->in('') diff --git a/tests/Feature/SizeableTest.php b/tests/Feature/SizeableTest.php index dbfd390..8afc429 100644 --- a/tests/Feature/SizeableTest.php +++ b/tests/Feature/SizeableTest.php @@ -90,10 +90,10 @@ public function test_when_more_than_one_size_make_method() ->setImageFormat('png') ->resize(50, 20) ->alsoResize(100, 50, 'large') - ->alsoResize(100, 50,) + ->alsoResize(100, 50) ->save(); - $expectedPath = $this->directorySeparator('images/post/arch/' . $random); + $expectedPath = $this->directorySeparator('images/post/arch/'.$random); $this->assertEquals($expectedPath, $image['imageDirectory']); $this->assertTrue(array_key_exists(0, $image['index'])); $this->assertTrue(array_key_exists('large', $image['index'])); @@ -101,7 +101,7 @@ public function test_when_more_than_one_size_make_method() foreach ($image['index'] as $sizeName => $path) { $this->assertFileExists(public_path($path)); $this->assertEquals( - $expectedPath . DIRECTORY_SEPARATOR . "{$random}_{$sizeName}.png", + $expectedPath.DIRECTORY_SEPARATOR."{$random}_{$sizeName}.png", $path ); } @@ -118,17 +118,17 @@ public function test_when_more_than_one_size_raw_method() ->alsoResize(100, 50) ->save(); - $expectedPath = 'post' . DIRECTORY_SEPARATOR . $random; + $expectedPath = 'post'.DIRECTORY_SEPARATOR.$random; $this->assertEquals($expectedPath, $image['imageDirectory']); $this->assertTrue(array_key_exists(0, $image['index'])); $this->assertTrue(array_key_exists('large', $image['index'])); - $this->assertEquals($expectedPath . DIRECTORY_SEPARATOR . $random . '_0.png', $image['index'][0]); - $this->assertEquals($expectedPath . DIRECTORY_SEPARATOR . $random . '_large.png', $image['index']['large']); + $this->assertEquals($expectedPath.DIRECTORY_SEPARATOR.$random.'_0.png', $image['index'][0]); + $this->assertEquals($expectedPath.DIRECTORY_SEPARATOR.$random.'_large.png', $image['index']['large']); foreach ($image['index'] as $sizeName => $path) { $this->assertFileExists(public_path($path)); $this->assertEquals( - $expectedPath . DIRECTORY_SEPARATOR . "{$random}_{$sizeName}.png", + $expectedPath.DIRECTORY_SEPARATOR."{$random}_{$sizeName}.png", $path ); } @@ -172,7 +172,7 @@ public function test_resize_removes_predefined_sizes_and_adds_given_size() ->resize(10, 10, 'large') ->save(); - $this->assertStringContainsString($image['index'], 'post' . DIRECTORY_SEPARATOR . 'name_large.png'); + $this->assertStringContainsString($image['index'], 'post'.DIRECTORY_SEPARATOR.'name_large.png'); $this->assertFileExists(public_path($image['index'])); $image = Image::raw($this->image) @@ -200,7 +200,7 @@ public function test_resize_removes_predefined_sizes_and_adds_given_size() ->resize(10, 10, 'large') ->save(); - $this->assertStringContainsString($image['index'], 'post' . DIRECTORY_SEPARATOR . 'name_large.png'); + $this->assertStringContainsString($image['index'], 'post'.DIRECTORY_SEPARATOR.'name_large.png'); $this->assertFileExists(public_path($image['index'])); } @@ -252,7 +252,7 @@ public function test_resize_by_adds_array_of_sizes() ], ]) ->save(); - + $this->assertTrue(is_array($image['index'])); foreach ($image['index'] as $key => $path) { $this->assertStringContainsString("_$key.png", $image['index'][$key]); @@ -436,7 +436,7 @@ public function test_disk_works() ->save(); foreach ($images['index'] as $image) { - $this->assertFileExists(storage_path('app/' . $image)); + $this->assertFileExists(storage_path('app/'.$image)); } $images = Image::make($this->image) @@ -458,7 +458,7 @@ public function test_disk_works() }); foreach ($images as $image) { - $this->assertFileExists(storage_path('app/' . $image)); + $this->assertFileExists(storage_path('app/'.$image)); } config(['image.disks.storage-public' => storage_path('public')]); @@ -472,7 +472,7 @@ public function test_disk_works() }); foreach ($images as $image) { - $this->assertFileExists(storage_path('public/' . $image)); + $this->assertFileExists(storage_path('public/'.$image)); } $image = Image::raw($this->image) @@ -491,7 +491,7 @@ public function test_disk_works() return $image->imagePath; }); - $this->assertFileExists(storage_path('app/' . $image)); + $this->assertFileExists(storage_path('app/'.$image)); $image = Image::raw($this->image) ->disk('storage-public') @@ -501,6 +501,6 @@ public function test_disk_works() return $image->imagePath; }); - $this->assertFileExists(storage_path('public/' . $image)); + $this->assertFileExists(storage_path('public/'.$image)); } } diff --git a/tests/Feature/TransactionTest.php b/tests/Feature/TransactionTest.php index d74e73f..5692838 100644 --- a/tests/Feature/TransactionTest.php +++ b/tests/Feature/TransactionTest.php @@ -4,10 +4,7 @@ use AmirHossein5\LaravelImage\Facades\Image; use AmirHossein5\LaravelImage\Tests\TestCase; -use Illuminate\Filesystem\Filesystem; use LogicException; -use Symfony\Component\Routing\Exception\InvalidParameterException; -use Intervention\Image\Facades\Image as Intervention; class TransactionTest extends TestCase { @@ -27,7 +24,6 @@ public function test_transaction_method_when_throws_exception() try { Image::transaction(function () use (&$image1, &$image2) { - $image1 = Image::make($this->image) ->setExclusiveDirectory('post') ->disk('storage') @@ -35,7 +31,7 @@ public function test_transaction_method_when_throws_exception() ->save(false, function ($image) { return [ 'index' => $image->imagePath, - 'directory' => $image->imageDirectory + 'directory' => $image->imageDirectory, ]; }); @@ -49,11 +45,10 @@ public function test_transaction_method_when_throws_exception() Image::raw($this->image)->disk()->save(); }); } catch (\Throwable $e) { - - $this->assertDirectoryDoesNotExist(storage_path('app/' . $image1['directory'])); + $this->assertDirectoryDoesNotExist(storage_path('app/'.$image1['directory'])); foreach ($image1['index'] as $image) { - $this->assertFileDoesNotExist(storage_path('app/' . $image)); + $this->assertFileDoesNotExist(storage_path('app/'.$image)); } // $this->assertFileDoesNotExist(public_path($image2)); @@ -76,7 +71,7 @@ public function test_transaction_manually_when_throws_exception() ->save(false, function ($image) { return [ 'index' => $image->imagePath, - 'directory' => $image->imageDirectory + 'directory' => $image->imageDirectory, ]; }); @@ -94,10 +89,10 @@ public function test_transaction_manually_when_throws_exception() Image::rollBack(); } - $this->assertDirectoryDoesNotExist(storage_path('app/' . $image1['directory'])); + $this->assertDirectoryDoesNotExist(storage_path('app/'.$image1['directory'])); foreach ($image1['index'] as $image) { - $this->assertFileDoesNotExist(storage_path('app/' . $image)); + $this->assertFileDoesNotExist(storage_path('app/'.$image)); } $this->assertFileDoesNotExist(public_path($image2)); @@ -113,13 +108,12 @@ public function test_transaction_method_when_not_throws_exception_works() ->save(); Image::transaction(function () use (&$image1, &$image2) { - $image1 = Image::make($this->image) ->setExclusiveDirectory('post') ->disk('storage') ->save(false, function ($image) { return [ - 'index' => $image->imagePath + 'index' => $image->imagePath, ]; }); @@ -132,7 +126,7 @@ public function test_transaction_method_when_not_throws_exception_works() }); foreach ($image1['index'] as $image) { - $this->assertFileExists(storage_path('app/' . $image)); + $this->assertFileExists(storage_path('app/'.$image)); } $this->assertFileExists(public_path($image2)); @@ -152,7 +146,7 @@ public function test_transaction_manually_when_not_throws_exception_works() ->disk('storage') ->save(false, function ($image) { return [ - 'index' => $image->imagePath + 'index' => $image->imagePath, ]; }); @@ -166,7 +160,7 @@ public function test_transaction_manually_when_not_throws_exception_works() Image::commit(); foreach ($image1['index'] as $image) { - $this->assertFileExists(storage_path('app/' . $image)); + $this->assertFileExists(storage_path('app/'.$image)); } $this->assertFileExists(public_path($image2)); @@ -188,8 +182,6 @@ public function test_manually_transaction_when_commit_and_rollback_methods_are_n $this->assertFileExists(public_path($image)); - - Image::beginTransaction(); $image = Image::raw($this->image) diff --git a/tests/TestCase.php b/tests/TestCase.php index 2c956cd..3e3760c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,8 +5,8 @@ use AmirHossein5\LaravelImage\ImageServiceProvider; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; -use Orchestra\Testbench\TestCase as TestbenchTestCase; use Intervention\Image\Facades\Image as Intervention; +use Orchestra\Testbench\TestCase as TestbenchTestCase; class TestCase extends TestbenchTestCase { @@ -76,9 +76,9 @@ public function interventionCircle(): \Intervention\Image\Image /** * Re modifies string by directory separator. - * + * * @param string $string - * + * * @return string */ public function directorySeparator(string $string): string