Skip to content

Commit

Permalink
rename classes
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jul 4, 2017
1 parent 73bff3b commit 74d2933
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/ImageOptimizer.php → src/OptimizerChain.php
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\Process\Process;
use Spatie\ImageOptimizer\Optimizers\Optimizer;

class ImageOptimizer
class OptimizerChain
{
protected $optimizers = [];

Expand Down
Expand Up @@ -7,11 +7,11 @@
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;

class ImageOptimizerFactory
class OptimizerChainFactory
{
public static function create(): ImageOptimizer
public static function create(): OptimizerChain
{
return (new ImageOptimizer())
return (new OptimizerChain())
->addOptimizer(new Jpegoptim([
'--strip-all',
'--all-progressive',
Expand Down
60 changes: 0 additions & 60 deletions tests/ImageOptimizerTest.php

This file was deleted.

Expand Up @@ -6,18 +6,18 @@
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
use Spatie\ImageOptimizer\ImageOptimizerFactory;
use Spatie\ImageOptimizer\OptimizerChainFactory;

class ImageOptimizerFactoryTest extends TestCase
class OptimizerChainFactoryTest extends TestCase
{
/** @var \Spatie\ImageOptimizer\ImageOptimizer */
protected $imageOptimizer;
/** @var \Spatie\ImageOptimizer\OptimizerChain */
protected $optimizerChain;

public function setUp()
{
parent::setUp();

$this->imageOptimizer = ImageOptimizerFactory::create()
$this->optimizerChain = OptimizerChainFactory::create()
->useLogger($this->log);
}

Expand All @@ -26,7 +26,7 @@ public function it_can_optimize_a_jpg()
{
$tempFilePath = $this->getTempFilePath('test.jpg');

$this->imageOptimizer->optimize($tempFilePath);
$this->optimizerChain->optimize($tempFilePath);

$this->assertDecreasedFileSize($tempFilePath, $this->getTestFilePath('test.jpg'));

Expand All @@ -38,7 +38,7 @@ public function it_can_optimize_a_png()
{
$tempFilePath = $this->getTempFilePath('test.png');

$this->imageOptimizer->optimize($tempFilePath);
$this->optimizerChain->optimize($tempFilePath);

$this->assertDecreasedFileSize($tempFilePath, $this->getTestFilePath('test.png'));

Expand All @@ -53,7 +53,7 @@ public function it_can_optimize_a_gif()
{
$tempFilePath = $this->getTempFilePath('test.gif');

$this->imageOptimizer->optimize($tempFilePath);
$this->optimizerChain->optimize($tempFilePath);

$this->assertDecreasedFileSize($tempFilePath, $this->getTestFilePath('test.gif'));

Expand All @@ -67,7 +67,7 @@ public function it_will_not_not_touch_a_non_image_file()

$originalContent = file_get_contents($tempFilePath);

$this->imageOptimizer->optimize($tempFilePath);
$this->optimizerChain->optimize($tempFilePath);

$optimizedContent = file_get_contents($tempFilePath);

Expand Down
60 changes: 60 additions & 0 deletions tests/OptimizerChainTest.php
@@ -0,0 +1,60 @@
<?php

namespace Spatie\ImageOptimizer\Test;

use Spatie\ImageOptimizer\OptimizerChain;
use Spatie\ImageOptimizer\Optimizers\Optipng;
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;

class OptimizerChainTest extends TestCase
{
/** @var \Spatie\ImageOptimizer\OptimizerChain; */
protected $optimizerChain;

public function setUp()
{
parent::setUp();

$this->optimizerChain = new OptimizerChain();
}

/** @test */
public function it_will_not_throw_an_exception_when_not_using_a_logger()
{
$testImage = $this->getTempFilePath('test.jpg');

$this->optimizerChain
->addOptimizer(new Jpegoptim())
->optimize($testImage);

$this->assertDecreasedFileSize($testImage, $this->getTestFilePath('test.jpg'));
}

/** @test */
public function it_can_get_all_optimizers()
{
$this->assertEquals([], $this->optimizerChain->getOptimizers());

$this->optimizerChain->addOptimizer(new Jpegoptim());

$this->assertInstanceOf(Jpegoptim::class, $this->optimizerChain->getOptimizers()[0]);
}

/** @test */
public function it_can_replace_all_optimizers_with_other_ones()
{
$this->assertEquals([], $this->optimizerChain->getOptimizers());

$this->optimizerChain->addOptimizer(new Jpegoptim());

$this->optimizerChain->setOptimizers([
new Optipng(),
new Pngquant(),
]);

$this->assertCount(2, $this->optimizerChain->getOptimizers());
$this->assertInstanceOf(Optipng::class, $this->optimizerChain->getOptimizers()[0]);
$this->assertInstanceOf(Pngquant::class, $this->optimizerChain->getOptimizers()[1]);
}
}

0 comments on commit 74d2933

Please sign in to comment.