Skip to content

Commit

Permalink
tests: improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamriajul committed Oct 31, 2023
1 parent 4faa4dd commit bca7de2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
fail-fast: true

matrix:
laravel: [ '10', '9', '8' ]
php: [ '8.2', '8.1', '8.0' ]
os: [ ubuntu-latest, windows-latest, macOS-latest ]
os: [ ubuntu-latest ]

steps:
- uses: actions/checkout@v3
Expand All @@ -70,7 +70,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, imagick
extensions: fileinfo, imagick, gd
coverage: xdebug

- name: Get composer cache directory for Windows
Expand Down
3 changes: 3 additions & 0 deletions src/Facades/Thumbhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* @method static string encode(mixed|string|UploadedFile|Image $data)
* @method static void setDriver(string $driver)
* @method static string getDriver()
* @method static void setResizedImageMaxSize(int $imageMaxSize)
*/
class Thumbhash extends Facade
{
Expand Down
14 changes: 14 additions & 0 deletions tests/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,19 @@ public function testPackageLoaded(): void
$hash,
Thumbhash::encode(__DIR__ . '/assets/sunrise.jpg'),
);

// Test GD

Thumbhash::setDriver('gd');

$this->assertSame(
'gd',
Thumbhash::getDriver()
);

$this->assertSame(
$hash,
Thumbhash::encode(__DIR__ . '/assets/sunrise.jpg'),
);
}
}
66 changes: 60 additions & 6 deletions tests/ThumbhashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
use Riajul\Thumbhash\Thumbhash;
use PHPUnit\Framework\TestCase;

/**
* These tests are only Imagick compatible.
* If you use GD driver, than results will unexpected.
*/
class ThumbhashTest extends TestCase
{
public function testEncode(): void
public function testEncodeImagick(): void
{
$data = [
[
Expand Down Expand Up @@ -54,7 +50,7 @@ public function testEncode(): void
],
];

$hash = new Thumbhash();
$hash = new Thumbhash('imagick');

$this->assertSame(
'imagick',
Expand All @@ -68,4 +64,62 @@ public function testEncode(): void
);
}
}

public function testEncodeGd(): void
{
$data = [
[
'url' => 'assets/sunrise.jpg',
'hash' => '1QcSHQRnh493V4dIh4eXh1h4kJUI'
],
[
'url' => 'assets/sunset.jpg',
'hash' => '3PcNNYSFeXh/d3eld0iHZoZgVwh2'
],
[
'url' => 'assets/field.jpg',
'hash' => '3OcRJYB4d3h/iIeHeEh3eIhw+j3A'
],
[
'url' => 'assets/fall.jpg',
'hash' => 'HBkSHYSIeHiPiHh8eJd4eTN0EEQG'
],
[
'url' => 'assets/street.jpg',
'hash' => 'VggKDYAW6lZvdYd6d2iZh/p4GE/k'
],
[
'url' => 'assets/mountain.jpg',
'hash' => '2fcZFIB3iId/h3iJh4aIYJ2W8g'
],
[
'url' => 'assets/coast.jpg',
'hash' => 'IQgSLYZ6iHePh4h1eFeHh4dwgwg3'
],

// Images with transparency
[
'url' => 'assets/firefox.png',
'hash' => 'YJqGPQw7sFlslqhFafSE+Q6oJ1h2iHB2Rw'
],
[
'url' => 'assets/opera.png',
'hash' => 'mYqDBQQnxnj0JoLYdN7f8JhpuDeHiHdwZw'
],
];

$hash = new Thumbhash('gd');

$this->assertSame(
'gd',
$hash->getDriver(),
);

foreach ($data as $item) {
$this->assertSame(
$item['hash'],
$hash->encode(__DIR__ . '/' . $item['url'])
);
}
}
}

0 comments on commit bca7de2

Please sign in to comment.