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

WidthScalerTest::createImageObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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\WidthScaler;
8
use Intervention\Image\ImageManager;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\Filesystem\Filesystem;
11
12
class WidthScalerTest 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 WidthScaler
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 WidthScaler(new DefaultConfigurator([
52
            'scaler' => 'width',
53
            'stepModifier' => 0.8,
54
            'publicPath' => $this->publicPath
55
        ]));
56
    }
57
58 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...
59
        $responsiveImage = $this->createResponsiveImage();
60
        $imageObject = $this->createImageObject();
61
62
        $responsiveImage = $this->scaler->scale($responsiveImage, $imageObject);
63
64
        $this->assertTrue(count($responsiveImage->getSrcset()) > 1);
65
    }
66
67
    // TODO: test algorithm
68
69 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...
70
        $responsiveImage = new ResponsiveImage('img/image.jpeg');
71
        $responsiveImage->setExtension('jpeg');
72
        $responsiveImage->setFileName('image');
73
        $responsiveImage->setUrlPath('/img');
74
        
75
        return $responsiveImage;
76
    }
77
78
    private function createImageObject() {
79
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
80
81
        return $imageObject;
82
    }
83
84
}
85