Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,35 @@ on:

jobs:
tests:
uses: zenstruck/.github/.github/workflows/php-test.yml@main
name: PHP ${{ matrix.php }}, ${{ matrix.deps }}
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.3, 8.4, 8.5]
deps: [highest]
include:
- php: 8.3
deps: lowest
steps:
- uses: zenstruck/.github/actions/php-test-symfony@main
with:
php: ${{ matrix.php }}
deps: ${{ matrix.deps }}

code-coverage:
uses: zenstruck/.github/.github/workflows/php-coverage-codecov.yml@main
with:
php: 8.3

composer-validate:
uses: zenstruck/.github/.github/workflows/php-composer-validate.yml@main
with:
php: 8.3

sca:
uses: zenstruck/.github/.github/workflows/php-stan.yml@main
with:
php: 8.3

fixcs:
name: Run php-cs-fixer
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
}
],
"require": {
"php": ">=8.0",
"symfony/polyfill-php81": "^1.26",
"php": ">=8.3",
"zenstruck/temp-file": "^1.0"
},
"require-dev": {
Expand Down
8 changes: 5 additions & 3 deletions tests/ImageFileInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
final class ImageFileInfoTest extends TestCase
{
use TempDirAssertions;

/**
* @test
* @dataProvider imageMetadataProvider
Expand All @@ -28,13 +30,13 @@ public function can_get_metadata(string $file, int $height, int $width, string $
$this->metadataAssertions(ImageFileInfo::wrap($file), $height, $width, $mime, $extension);

$this->metadataAssertions($image = ImageFileInfo::from(\file_get_contents($file)), $height, $width, $mime, $extension);
$this->assertSame('/tmp', \dirname($image));
$this->assertInTempDir($image);

$this->metadataAssertions($image = ImageFileInfo::from(\fopen($file, 'r')), $height, $width, $mime, $extension);
$this->assertSame('/tmp', \dirname($image));
$this->assertInTempDir($image);

$this->metadataAssertions($image = ImageFileInfo::from(new \SplFileInfo($file)), $height, $width, $mime, $extension);
$this->assertSame('/tmp', \dirname($image));
$this->assertInTempDir($image);
}

public static function imageMetadataProvider(): iterable
Expand Down
27 changes: 27 additions & 0 deletions tests/TempDirAssertions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the zenstruck/image package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Image\Tests;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
trait TempDirAssertions
{
/**
* macOS reports its temp directory unresolved but creates files in the
* resolved one, so both sides have to be normalized before comparing.
*/
protected function assertInTempDir(\SplFileInfo $file): void
{
$this->assertSame(\realpath(\sys_get_temp_dir()), \realpath(\dirname($file)));
}
}
4 changes: 2 additions & 2 deletions tests/Transformer/FilterObjectTransformerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public function can_transform_into_temp_image_with_filter_object(): void
$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('jpg', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);

$resized = $image->transform($this->filterObject(), ['format' => 'png']);

$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('png', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions tests/TransformerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
abstract class TransformerTestCase extends TestCase
{
use TempDirAssertions;

/**
* @test
*/
Expand All @@ -32,14 +34,14 @@ public function can_transform_into_temp_image(): void
$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('jpg', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);

$resized = $image->transform($this->filterCallback(), ['format' => 'png']);

$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('png', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);
}

/**
Expand Down Expand Up @@ -90,14 +92,14 @@ public function can_transform_into_temp_image_with_invokable_object(): void
$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('jpg', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);

$resized = $image->transform($this->filterCallback(), ['format' => 'png']);

$this->assertSame(100, $resized->dimensions()->width());
$this->assertSame(120, $resized->dimensions()->height());
$this->assertSame('png', $resized->getExtension());
$this->assertSame('/tmp', \dirname($resized));
$this->assertInTempDir($resized);
}

/**
Expand Down