Passed
Push — master ( 1d5a7e...f5ffe9 )
by Brent
02:21
created

FileSizeScalerTest::test_scale_down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Brendt\Image\Tests\Phpunit\Scaler;
4
5
use Brendt\Image\Config\DefaultConfigurator;
6
use Brendt\Image\ResponsiveImage;
7
use Brendt\Image\Scaler\FileSizeScaler;
8
use Intervention\Image\ImageManager;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\Filesystem\Filesystem;
11
12
class FileSizeScalerTest extends TestCase
13
{
14
15
    /**
16
     * @var Filesystem
17
     */
18
    private $fs;
19
20
    /**
21
     * @var string
22
     */
23
    private $publicPath = './tests/public';
24
25
    /**
26
     * @var FileSizeScaler
27
     */
28
    private $scaler;
29
30
    /**
31
     * @var ImageManager
32
     */
33
    private $engine;
34
35 View Code Duplication
    public function __construct() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
        parent::__construct();
37
38
        $this->fs = new Filesystem();
39
        $this->engine = new ImageManager([
40
            'driver' => 'gd',
41
        ]);
42
    }
43
44
    public function __destruct() {
45
        if ($this->fs->exists($this->publicPath)) {
46
            $this->fs->remove($this->publicPath);
47
        }
48
    }
49
50
    public function setUp() {
51
        $this->scaler = new FileSizeScaler(new DefaultConfigurator([
52
            'publicPath' => $this->publicPath,
53
        ]));
54
    }
55
56 View Code Duplication
    public function test_scale_down() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
        $responsiveImage = $this->createResponsiveImage();
58
        $imageObject = $this->createImageObject();
59
60
        $responsiveImage = $this->scaler->scale($responsiveImage, $imageObject);
61
62
        $this->assertTrue(count($responsiveImage->getSrcset()) > 1);
63
    }
64
65
    // TODO: test algorithm
66
67 View Code Duplication
    private function createResponsiveImage() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
        $responsiveImage = new ResponsiveImage('img/image.jpeg');
69
        $responsiveImage->setExtension('jpeg');
70
        $responsiveImage->setFileName('image');
71
        $responsiveImage->setUrlPath('/img');
72
73
        return $responsiveImage;
74
    }
75
76
    private function createImageObject() {
77
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
78
79
        return $imageObject;
80
    }
81
82
}
83