Skip to content

Commit

Permalink
added failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xb4lint committed May 3, 2024
1 parent 02e2717 commit 518edd7
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/OptimizerChainFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
<?php

use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertFileEquals;

use Spatie\ImageOptimizer\Optimizer;
use Spatie\ImageOptimizer\OptimizerChainFactory;
use Spatie\ImageOptimizer\Optimizers\Avifenc;
use Spatie\ImageOptimizer\Optimizers\Cwebp;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
use Spatie\ImageOptimizer\Optimizers\Optipng;
use Spatie\ImageOptimizer\Optimizers\Pngquant;

use Spatie\ImageOptimizer\Optimizers\Svgo;

beforeEach(function () {
$this->optimizerChain = OptimizerChainFactory::create()
->useLogger($this->log);
});

it('can use config', function () {
$this->optimizerChain = OptimizerChainFactory::create([
Jpegoptim::class => ['--foo'],
Pngquant::class => ['--foo'],
Optipng::class => ['--foo'],
Svgo::class => ['--foo'],
Gifsicle::class => ['--foo'],
Cwebp::class => ['--foo'],
Avifenc::class => ['--foo'],
])
->useLogger($this->log);

assertEquals(
[
new Jpegoptim(['--foo']),
new Pngquant(['--foo']),
new Optipng(['--foo']),
new Svgo(['--foo']),
new Gifsicle(['--foo']),
new Cwebp(['--foo']),
new Avifenc(['--foo']),
],
$this->optimizerChain->getOptimizers()
);
});

it('can use default config', function () {
assertEquals(
[
Jpegoptim::class,
Pngquant::class,
Optipng::class,
Svgo::class,
Gifsicle::class,
Cwebp::class,
Avifenc::class,
],
array_map(fn (Optimizer $optimizer) => get_class($optimizer), $this->optimizerChain->getOptimizers())
);
});

it('can optimize a jpg', function () {
$tempFilePath = getTempFilePath('image.jpg');

Expand Down

0 comments on commit 518edd7

Please sign in to comment.