diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f64765..cb62102 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.2, 7.3, 7.4, 8.0] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -123,7 +123,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.1, 7.2, 7.4, 8.0] + php: [7.2, 7.4, 8.0] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -151,7 +151,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.2, 7.3, 7.4, 8.0] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/composer.json b/composer.json index 8a21b35..8ce9f6c 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,11 @@ } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^7.2 || ^8.0", "ext-json": "*", "imagine/imagine": "^0.7.1 || ^1.0", - "symfony/filesystem": "^2.8 || ^3.0 || ^4.0 || ^5.0", - "symfony/polyfill-php73": "^1.11", - "webmozart/path-util": "^2.0" + "symfony/filesystem": "^5.4 || ^6.0", + "symfony/polyfill-php73": "^1.11" }, "conflict": { "contao/imagine-svg": "<0.1.4 || >=2.0" diff --git a/src/DeferredImageStorageFilesystem.php b/src/DeferredImageStorageFilesystem.php index b04b8d5..40846d1 100644 --- a/src/DeferredImageStorageFilesystem.php +++ b/src/DeferredImageStorageFilesystem.php @@ -18,11 +18,11 @@ use Contao\Image\Exception\RuntimeException; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; class DeferredImageStorageFilesystem implements DeferredImageStorageInterface { - private const PATH_PREFIX = '/deferred'; + private const PATH_PREFIX = 'deferred'; private const PATH_SUFFIX = '.json'; /** @@ -46,7 +46,7 @@ public function __construct(string $cacheDir, Filesystem $filesystem = null) $filesystem = new Filesystem(); } - $this->cacheDir = $cacheDir.self::PATH_PREFIX; + $this->cacheDir = Path::join($cacheDir, self::PATH_PREFIX); $this->filesystem = $filesystem; } @@ -196,7 +196,7 @@ private function getConfigPath(string $path): string throw new InvalidArgumentException(sprintf('Invalid storage key "%s"', $path)); } - return $this->cacheDir.'/'.$path.self::PATH_SUFFIX; + return Path::join($this->cacheDir, $path.self::PATH_SUFFIX); } /** diff --git a/src/DeferredResizer.php b/src/DeferredResizer.php index a495470..410fcb5 100644 --- a/src/DeferredResizer.php +++ b/src/DeferredResizer.php @@ -18,7 +18,7 @@ use Imagine\Image\ImagineInterface; use Imagine\Image\Point; use Symfony\Component\Filesystem\Filesystem; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; class DeferredResizer extends Resizer implements DeferredResizerInterface { @@ -63,7 +63,7 @@ public function getDeferredImage(string $targetPath, ImagineInterface $imagine): $config = $this->storage->get($targetPath); return new DeferredImage( - $this->cacheDir.'/'.$targetPath, + Path::join($this->cacheDir, $targetPath), $imagine, new ImageDimensions( new Box( @@ -182,12 +182,12 @@ private function executeDeferredResize(string $targetPath, array $config, Imagin $options = new ResizeOptions(); $options->setImagineOptions($config['options']['imagine_options']); - $path = Path::canonicalize($this->cacheDir.'/'.$config['path']); + $path = Path::join($this->cacheDir, $config['path']); return parent::executeResize( new Image($path, $imagine, $this->filesystem), $coordinates, - $this->cacheDir.'/'.$targetPath, + Path::join($this->cacheDir, $targetPath), $options ); } diff --git a/src/Image.php b/src/Image.php index 0ac80a8..d9ea99e 100644 --- a/src/Image.php +++ b/src/Image.php @@ -21,7 +21,7 @@ use Imagine\Image\ImagineInterface; use Imagine\Image\Metadata\MetadataBag; use Symfony\Component\Filesystem\Filesystem; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; class Image implements ImageInterface { diff --git a/src/Resizer.php b/src/Resizer.php index f757985..ec6936e 100644 --- a/src/Resizer.php +++ b/src/Resizer.php @@ -16,7 +16,7 @@ use Imagine\Filter\Basic\Autorotate; use Imagine\Image\Palette\RGB; use Symfony\Component\Filesystem\Filesystem; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; class Resizer implements ResizerInterface { @@ -157,7 +157,7 @@ protected function processResize(ImageInterface $image, ResizeConfiguration $con return $this->createImage($image, $image->getPath()); } - $cachePath = $this->cacheDir.'/'.$this->createCachePath($image->getPath(), $coordinates, $options); + $cachePath = Path::join($this->cacheDir, $this->createCachePath($image->getPath(), $coordinates, $options)); if ($this->filesystem->exists($cachePath) && !$options->getBypassCache()) { return $this->createImage($image, $cachePath); @@ -213,6 +213,6 @@ static function ($value) { $pathinfo = pathinfo($path); $extension = $options->getImagineOptions()['format'] ?? strtolower($pathinfo['extension']); - return $hash[0].'/'.$pathinfo['filename'].'-'.substr($hash, 1).'.'.$extension; + return Path::join($hash[0], $pathinfo['filename'].'-'.substr($hash, 1).'.'.$extension); } } diff --git a/tests/DeferredImageStorageFilesystemTest.php b/tests/DeferredImageStorageFilesystemTest.php index 919c4c0..1ea694d 100644 --- a/tests/DeferredImageStorageFilesystemTest.php +++ b/tests/DeferredImageStorageFilesystemTest.php @@ -18,6 +18,7 @@ use Contao\Image\Exception\RuntimeException; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Path; class DeferredImageStorageFilesystemTest extends TestCase { @@ -33,7 +34,7 @@ protected function setUp(): void { parent::setUp(); - $this->rootDir = __DIR__.'/tmp'; + $this->rootDir = Path::canonicalize(__DIR__.'/tmp'); } /** @@ -79,7 +80,7 @@ public function testGetLocked(string $key, array $value): void $this->assertSame($value, $storage->getLocked($key)); - $dataPath = $this->rootDir.'/deferred/'.$key.'.json'; + $dataPath = Path::join($this->rootDir, 'deferred', $key.'.json'); $handle = fopen($dataPath, 'r+'); $this->assertFalse(flock($handle, LOCK_EX | LOCK_NB), 'Data file should be locked'); @@ -129,10 +130,10 @@ public function testInvalidJsonThrows(): void { $storage = new DeferredImageStorageFilesystem($this->rootDir); - if (!is_dir($this->rootDir.'/deferred')) { - mkdir($this->rootDir.'/deferred', 0777, true); + if (!is_dir(Path::join($this->rootDir, 'deferred'))) { + mkdir(Path::join($this->rootDir, 'deferred'), 0777, true); } - file_put_contents($this->rootDir.'/deferred/test.json', 'invalid JSON'); + file_put_contents(Path::join($this->rootDir, 'deferred/test.json'), 'invalid JSON'); $this->expectException(JsonException::class); @@ -143,10 +144,10 @@ public function testInvalidJsonDataThrows(): void { $storage = new DeferredImageStorageFilesystem($this->rootDir); - if (!is_dir($this->rootDir.'/deferred')) { - mkdir($this->rootDir.'/deferred', 0777, true); + if (!is_dir(Path::join($this->rootDir, 'deferred'))) { + mkdir(Path::join($this->rootDir, 'deferred'), 0777, true); } - file_put_contents($this->rootDir.'/deferred/test.json', '"JSON string instead of an array"'); + file_put_contents(Path::join($this->rootDir, 'deferred/test.json'), '"JSON string instead of an array"'); $this->expectException(InvalidArgumentException::class); diff --git a/tests/DeferredResizerTest.php b/tests/DeferredResizerTest.php index adf29eb..39f3e4f 100644 --- a/tests/DeferredResizerTest.php +++ b/tests/DeferredResizerTest.php @@ -32,6 +32,7 @@ use Imagine\Image\Point; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Path; class DeferredResizerTest extends TestCase { @@ -47,7 +48,7 @@ protected function setUp(): void { parent::setUp(); - $this->rootDir = __DIR__.'/tmp'; + $this->rootDir = Path::canonicalize(__DIR__.'/tmp'); } /** @@ -86,7 +87,7 @@ static function (ResizeConfiguration $config, ImageDimensions $dimensions, Impor (new GdImagine()) ->create(new Box(100, 100)) - ->save($this->rootDir.'/dummy.jpg') + ->save(Path::join($this->rootDir, 'dummy.jpg')) ; $image = $this->createMock(Image::class); @@ -97,7 +98,7 @@ static function (ResizeConfiguration $config, ImageDimensions $dimensions, Impor $image ->method('getPath') - ->willReturn($this->rootDir.'/dummy.jpg') + ->willReturn(Path::join($this->rootDir, 'dummy.jpg')) ; $image @@ -123,7 +124,7 @@ static function (ResizeConfiguration $config, ImageDimensions $dimensions, Impor $this->assertMatchesRegularExpression('(/[0-9a-f]/dummy-[0-9a-f]{8}.jpg$)', $deferredImage->getPath()); $this->assertFileDoesNotExist($deferredImage->getPath()); $this->assertFileExists( - $this->rootDir.'/deferred/'.substr($deferredImage->getPath(), \strlen($this->rootDir)).'.json' + Path::join($this->rootDir, 'deferred', substr($deferredImage->getPath(), \strlen($this->rootDir)).'.json') ); /** @var DeferredImageInterface $deferredImage2 */ @@ -148,7 +149,7 @@ static function (ResizeConfiguration $config, ImageDimensions $dimensions, Impor $this->assertEquals(new ImageDimensions(new Box(50, 50)), $resizedImage->getDimensions()); $this->assertFileExists($resizedImage->getPath()); $this->assertFileDoesNotExist( - $this->rootDir.'/deferred/'.substr($deferredImage->getPath(), \strlen($this->rootDir)).'.json' + Path::join($this->rootDir, 'deferred', substr($deferredImage->getPath(), \strlen($this->rootDir)).'.json') ); // Calling resizeDeferredImage() a second time should return the already @@ -165,12 +166,12 @@ static function (ResizeConfiguration $config, ImageDimensions $dimensions, Impor $resizedImage = $resizer->resize( $image, (new ResizeConfiguration())->setWidth(100)->setHeight(100), - (new ResizeOptions())->setTargetPath($this->rootDir.'/target-path.jpg') + (new ResizeOptions())->setTargetPath(Path::join($this->rootDir, 'target-path.jpg')) ); $this->assertNotInstanceOf(DeferredImageInterface::class, $resizedImage); $this->assertEquals(new ImageDimensions(new Box(100, 100)), $resizedImage->getDimensions()); - $this->assertSame($this->rootDir.'/target-path.jpg', $resizedImage->getPath()); + $this->assertSame(Path::join($this->rootDir, 'target-path.jpg'), $resizedImage->getPath()); $this->assertFileExists($resizedImage->getPath()); } @@ -196,7 +197,7 @@ public function testGetDeferredImage(): void $imagine = $this->createMock(ImagineInterface::class); $resizer = $this->createResizer(null, null, null, $storage); - $imagePath = $this->rootDir.'/a/foo-5fc1c9f9.jpg'; + $imagePath = Path::join($this->rootDir, 'a/foo-5fc1c9f9.jpg'); $deferredImage = $resizer->getDeferredImage($imagePath, $imagine); $this->assertInstanceOf(DeferredImageInterface::class, $deferredImage); @@ -218,7 +219,7 @@ public function testGetMissingDeferredImage(): void $imagine = $this->createMock(ImagineInterface::class); $resizer = $this->createResizer(null, null, null, $storage); - $imagePath = $this->rootDir.'/a/foo-5fc1c9f9.jpg'; + $imagePath = Path::join($this->rootDir, 'a/foo-5fc1c9f9.jpg'); $this->assertNull($resizer->getDeferredImage($imagePath, $imagine)); } @@ -230,7 +231,7 @@ public function testResizeDeferredImageThrowsForOutsidePath(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/../foo.jpg') + ->willReturn(Path::join($this->rootDir, '../foo.jpg')) ; $this->expectException(InvalidArgumentException::class); @@ -244,7 +245,7 @@ public function testResizeDeferredImageThrowsForMissingJson(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, '/foo.jpg')) ; $this->expectException(FileNotExistsException::class); @@ -259,7 +260,7 @@ public function testResizeDeferredImageThrowsForMissingImage(): void ->method('getLocked') ->with('foo.jpg', true) ->willReturn([ - 'path' => $this->rootDir.'/foo.jpg', + 'path' => Path::join($this->rootDir, 'foo.jpg'), 'coordinates' => [ 'size' => [ 'width' => 100, @@ -289,7 +290,7 @@ public function testResizeDeferredImageThrowsForMissingImage(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, 'foo.jpg')) ; $this->expectException(FileNotExistsException::class); @@ -312,7 +313,7 @@ public function testResizeDeferredImageDoesNotCatchStorageException(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, 'foo.jpg')) ; $this->expectExceptionObject($storageException); @@ -333,7 +334,7 @@ public function testResizeDeferredImageReturnsNullForLockedNonBlockingResize(): $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, 'foo.jpg')) ; $this->assertNull($resizer->resizeDeferredImage($deferredImage, false)); @@ -352,7 +353,7 @@ public function testResizeDeferredImageThrowsForLockedBlockingResize(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, 'foo.jpg')) ; $this->expectException(RuntimeException::class); @@ -367,7 +368,7 @@ public function testResizeDeferredImageReleasesLockForFailedResize(): void ->method('getLocked') ->with('foo.jpg', true) ->willReturn([ - 'path' => $this->rootDir.'/foo.jpg', + 'path' => Path::join($this->rootDir, 'foo.jpg'), 'coordinates' => [ 'size' => [ 'width' => 100, @@ -397,7 +398,7 @@ public function testResizeDeferredImageReleasesLockForFailedResize(): void $deferredImage = $this->createMock(DeferredImageInterface::class); $deferredImage ->method('getPath') - ->willReturn($this->rootDir.'/foo.jpg') + ->willReturn(Path::join($this->rootDir, 'foo.jpg')) ; $this->expectException(InvalidArgumentException::class); diff --git a/tests/ImageTest.php b/tests/ImageTest.php index b57e592..0a66369 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -26,6 +26,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Path; class ImageTest extends TestCase { @@ -41,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->rootDir = __DIR__.'/tmp'; + $this->rootDir = Path::canonicalize(__DIR__.'/tmp'); } /** @@ -201,9 +202,9 @@ public function testGetDimensionsFromExifRotatedFile(int $orientation, int $widt ->get('jpg') ; - file_put_contents($this->rootDir.'/dummy.jpg', $this->addImageOrientation($image, $orientation)); + file_put_contents(Path::join($this->rootDir, 'dummy.jpg'), $this->addImageOrientation($image, $orientation)); - $image = $this->createImage($this->rootDir.'/dummy.jpg'); + $image = $this->createImage(Path::join($this->rootDir, 'dummy.jpg')); $dimensions = $image->getDimensions(); @@ -270,9 +271,9 @@ public function testGetDimensionsFromPartialFile(): void ; // Only store the first 500 bytes of the image - file_put_contents($this->rootDir.'/dummy.jpg', substr($image, 0, 500)); + file_put_contents(Path::join($this->rootDir, 'dummy.jpg'), substr($image, 0, 500)); - $image = $this->createImage($this->rootDir.'/dummy.jpg'); + $image = $this->createImage(Path::join($this->rootDir, 'dummy.jpg')); $this->assertEquals(new ImageDimensions(new Box(1000, 1000)), $image->getDimensions()); } @@ -290,9 +291,9 @@ public function testGetDimensionsFromPartialSvgFile(): void } // Only store a partial SVG file without an end tag - file_put_contents($this->rootDir.'/dummy.svg', ''); + file_put_contents(Path::join($this->rootDir, 'dummy.svg'), ''); - $image = $this->createImage($this->rootDir.'/dummy.svg', $imagine); + $image = $this->createImage(Path::join($this->rootDir, 'dummy.svg'), $imagine); $this->assertSame(1000, $image->getDimensions()->getSize()->getWidth()); $this->assertSame(1000, $image->getDimensions()->getSize()->getHeight()); @@ -313,9 +314,9 @@ public function testGetDimensionsFromPartialSvgzFile(): void } // Only store a partial SVG file without an end tag - file_put_contents($this->rootDir.'/dummy.svgz', gzencode('')); + file_put_contents(Path::join($this->rootDir, 'dummy.svgz'), gzencode('')); - $image = $this->createImage($this->rootDir.'/dummy.svgz', $imagine); + $image = $this->createImage(Path::join($this->rootDir, 'dummy.svgz'), $imagine); $this->assertSame(1000, $image->getDimensions()->getSize()->getWidth()); $this->assertSame(1000, $image->getDimensions()->getSize()->getHeight()); @@ -329,7 +330,7 @@ public function testGetDimensionsInvalidSvg(): void mkdir($this->rootDir, 0777, true); } - file_put_contents($this->rootDir.'/dummy.svg', ''); + file_put_contents(Path::join($this->rootDir, 'dummy.svg'), ''); $imagine = $this->createMock(Imagine::class); $imagine @@ -337,7 +338,7 @@ public function testGetDimensionsInvalidSvg(): void ->willThrowException(new \Exception()) ; - $image = $this->createImage($this->rootDir.'/dummy.svg', $imagine); + $image = $this->createImage(Path::join($this->rootDir, 'dummy.svg'), $imagine); $this->expectException('Exception'); $image->getDimensions(); diff --git a/tests/ResizerTest.php b/tests/ResizerTest.php index 947cde4..9b96ee7 100644 --- a/tests/ResizerTest.php +++ b/tests/ResizerTest.php @@ -29,6 +29,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Path; class ResizerTest extends TestCase { @@ -44,7 +45,7 @@ protected function setUp(): void { parent::setUp(); - $this->rootDir = __DIR__.'/tmp'; + $this->rootDir = Path::canonicalize(__DIR__.'/tmp'); } /** @@ -75,7 +76,7 @@ public function testResize(): void (new GdImagine()) ->create(new Box(100, 100)) - ->save($this->rootDir.'/dummy.jpg') + ->save(Path::join($this->rootDir, 'dummy.jpg')) ; $image = $this->createMock(Image::class); @@ -86,7 +87,7 @@ public function testResize(): void $image ->method('getPath') - ->willReturn($this->rootDir.'/dummy.jpg') + ->willReturn(Path::join($this->rootDir, 'dummy.jpg')) ; $image @@ -125,27 +126,27 @@ public function testResize(): void $resizedImage = $resizer->resize( $image, $configuration, - (new ResizeOptions())->setTargetPath($this->rootDir.'/target-path.jpg') + (new ResizeOptions())->setTargetPath(Path::join($this->rootDir, 'target-path.jpg')) ); $this->assertEquals(new ImageDimensions(new Box(100, 100)), $resizedImage->getDimensions()); - $this->assertSame($this->rootDir.'/target-path.jpg', $resizedImage->getPath()); + $this->assertSame(Path::join($this->rootDir, 'target-path.jpg'), $resizedImage->getPath()); $this->assertFilePermissions(0666, $resizedImage->getPath()); // Replace target image with larger image (new GdImagine()) ->create(new Box(200, 200)) - ->save($this->rootDir.'/target-path.jpg') + ->save(Path::join($this->rootDir, 'target-path.jpg')) ; // Resize with override $resizedImage = $resizer->resize( $image, $configuration, - (new ResizeOptions())->setTargetPath($this->rootDir.'/target-path.jpg') + (new ResizeOptions())->setTargetPath(Path::join($this->rootDir, 'target-path.jpg')) ); - $this->assertSame($this->rootDir.'/target-path.jpg', $resizedImage->getPath()); + $this->assertSame(Path::join($this->rootDir, 'target-path.jpg'), $resizedImage->getPath()); $this->assertEquals(new ImageDimensions(new Box(100, 100)), $resizedImage->getDimensions()); $this->assertFilePermissions(0666, $resizedImage->getPath()); } @@ -159,7 +160,7 @@ public function testResizeSvg(): void mkdir($this->rootDir, 0777, true); } - file_put_contents($this->rootDir.'/dummy.svg', $xml); + file_put_contents(Path::join($this->rootDir, 'dummy.svg'), $xml); $calculator = $this->createMock(ResizeCalculator::class); $calculator @@ -177,7 +178,7 @@ public function testResizeSvg(): void $image ->method('getPath') - ->willReturn($this->rootDir.'/dummy.svg') + ->willReturn(Path::join($this->rootDir, 'dummy.svg')) ; $image @@ -210,14 +211,14 @@ public function testResizeSvg(): void $resizedImage = $resizer->resize( $image, $configuration, - (new ResizeOptions())->setTargetPath($this->rootDir.'/target-path.svg') + (new ResizeOptions())->setTargetPath(Path::join($this->rootDir, 'target-path.svg')) ); $this->assertSame(100, $resizedImage->getDimensions()->getSize()->getWidth()); $this->assertSame(100, $resizedImage->getDimensions()->getSize()->getHeight()); $this->assertFalse($resizedImage->getDimensions()->isRelative()); $this->assertFalse($resizedImage->getDimensions()->isUndefined()); - $this->assertSame($this->rootDir.'/target-path.svg', $resizedImage->getPath()); + $this->assertSame(Path::join($this->rootDir, 'target-path.svg'), $resizedImage->getPath()); $this->assertFilePermissions(0666, $resizedImage->getPath()); unlink($resizedImage->getPath()); @@ -239,7 +240,7 @@ public function testResizeCache(): void (new GdImagine()) ->create(new Box(100, 100)) - ->save($this->rootDir.'/dummy.jpg') + ->save(Path::join($this->rootDir, 'dummy.jpg')) ; $image = $this->createMock(Image::class); @@ -250,7 +251,7 @@ public function testResizeCache(): void $image ->method('getPath') - ->willReturn($this->rootDir.'/dummy.jpg') + ->willReturn(Path::join($this->rootDir, 'dummy.jpg')) ; $image @@ -280,7 +281,7 @@ public function testResizeCache(): void $this->assertSame(200, getimagesize($imagePath)[0], 'Cache file should no be overwritten'); // With cache and target path - $targetPath = $this->rootDir.'/target-image.jpg'; + $targetPath = Path::join($this->rootDir, 'target-image.jpg'); $resizedImage = $resizer->resize($image, $configuration, (new ResizeOptions())->setTargetPath($targetPath)); $this->assertSame($targetPath, $resizedImage->getPath()); @@ -297,11 +298,11 @@ public function testResizeCache(): void $this->assertSame(100, getimagesize($resizedImage->getPath())[0], 'New cache file should have been created'); // With different paths, but same relative path - $subDir = $this->rootDir.'/sub/dir'; + $subDir = Path::join($this->rootDir, 'sub/dir'); mkdir($subDir, 0777, true); - copy($this->rootDir.'/dummy.jpg', $subDir.'/dummy.jpg'); - touch($subDir.'/dummy.jpg', filemtime($this->rootDir.'/dummy.jpg')); + copy(Path::join($this->rootDir, 'dummy.jpg'), Path::join($subDir, 'dummy.jpg')); + touch(Path::join($subDir, 'dummy.jpg'), filemtime(Path::join($this->rootDir, 'dummy.jpg'))); $subResizer = $this->createResizer($subDir, $calculator); @@ -313,7 +314,7 @@ public function testResizeCache(): void $subImage ->method('getPath') - ->willReturn($subDir.'/dummy.jpg') + ->willReturn(Path::join($subDir, 'dummy.jpg')) ; $subImage @@ -338,7 +339,7 @@ public function testResizeCache(): void public function testResizeUndefinedSize(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) { @@ -381,7 +382,7 @@ class_exists(SvgBox::class) ? SvgBox::createTypeNone() : new UndefinedBox() public function testResizeEmptyConfig(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) { @@ -424,7 +425,7 @@ public function testResizeEmptyConfig(): void public function testResizeEmptyConfigSkipsMatchingDimensions(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) { @@ -468,7 +469,7 @@ public function testResizeEmptyConfigSkipsMatchingDimensions(): void public function testResizeEmptyConfigWithFormat(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) { @@ -517,7 +518,7 @@ public function testResizeEmptyConfigWithFormat(): void public function testResizeSameDimensions(): void { - $path = $this->rootDir.'/dummy.jpg'; + $path = Path::join($this->rootDir, 'dummy.jpg'); $calculator = $this->createMock(ResizeCalculator::class); $calculator @@ -566,12 +567,12 @@ public function testResizeSameDimensions(): void $image, $configuration, (new ResizeOptions()) - ->setTargetPath($this->rootDir.'/target-path.jpg') + ->setTargetPath(Path::join($this->rootDir, 'target-path.jpg')) ->setSkipIfDimensionsMatch(true) ); $this->assertEquals(new ImageDimensions(new Box(100, 100)), $resizedImage->getDimensions()); - $this->assertSame($this->rootDir.'/target-path.jpg', $resizedImage->getPath()); + $this->assertSame(Path::join($this->rootDir, 'target-path.jpg'), $resizedImage->getPath()); } public function testResizeSameDimensionsRelative(): void @@ -583,7 +584,7 @@ public function testResizeSameDimensionsRelative(): void mkdir($this->rootDir, 0777, true); } - file_put_contents($this->rootDir.'/dummy.svg', $xml); + file_put_contents(Path::join($this->rootDir, 'dummy.svg'), $xml); $calculator = $this->createMock(ResizeCalculator::class); $calculator @@ -601,7 +602,7 @@ public function testResizeSameDimensionsRelative(): void $image ->method('getPath') - ->willReturn($this->rootDir.'/dummy.svg') + ->willReturn(Path::join($this->rootDir, 'dummy.svg')) ; $image @@ -622,7 +623,7 @@ public function testResizeSameDimensionsRelative(): void public function testResizeEmptyConfigRotatedImage(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) { @@ -665,7 +666,7 @@ public function testResizeEmptyConfigRotatedImage(): void public function testResizeEmptyConfigNoSkip(): void { - $imagePath = $this->rootDir.'/dummy.jpg'; + $imagePath = Path::join($this->rootDir, 'dummy.jpg'); $resizer = $this->createResizer(); if (!is_dir($this->rootDir)) {