Passed
Push — master ( 26a73e...e9f82c )
by Brent
03:12
created

test_scale_down_with_include_source_disabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
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
use Symfony\Component\Finder\Finder;
12
13
class WidthScalerTest extends TestCase
14
{
15
16
    /**
17
     * @var Filesystem
18
     */
19
    private $fs;
20
21
    /**
22
     * @var string
23
     */
24
    private $publicPath = './tests/public';
25
26
    /**
27
     * @var WidthScaler
28
     */
29
    private $scaler;
30
31
    /**
32
     * @var ImageManager
33
     */
34
    private $engine;
35
36 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...
37
        parent::__construct();
38
39
        $this->fs = new Filesystem();
40
        $this->engine = new ImageManager([
41
            'driver' => 'gd',
42
        ]);
43
    }
44
45
    public function __destruct() {
46
        if ($this->fs->exists($this->publicPath)) {
47
            $this->fs->remove($this->publicPath);
48
        }
49
    }
50
51
    public function setUp() {
52
        $this->scaler = new WidthScaler(new DefaultConfigurator([
53
            'scaler' => 'width',
54
            'stepModifier' => 0.8,
55
            'publicPath' => $this->publicPath
56
        ]));
57
    }
58
59 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...
60
        $sourceFile = $this->createSourceFile();
61
        $imageObject = $this->createImageObject();
62
63
        $sizes = $this->scaler->scale($sourceFile, $imageObject);
64
65
        $this->assertTrue(count($sizes) > 1);
66
    }
67
68 View Code Duplication
    public function test_scale_down_with_max_width() {
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...
69
        $sourceFile = $this->createSourceFile();
70
        $imageObject = $this->createImageObject();
71
72
        $this->scaler->setMaxWidth(1000);
73
        $sizes = $this->scaler->scale($sourceFile, $imageObject);
74
75
        foreach ($sizes as $width => $height) {
76
            $this->assertTrue($width < 1000);
77
        }
78
    }
79
80 View Code Duplication
    public function test_scale_down_with_include_source_disabled() {
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...
81
        $sourceFile = $this->createSourceFile();
82
        $imageObject = $this->createImageObject();
83
84
        $this->scaler->setIncludeSource(false);
85
        $sizes = $this->scaler->scale($sourceFile, $imageObject);
86
87
        $this->assertFalse(array_key_exists(1920, $sizes));
88
    }
89
90
    private function createSourceFile() {
91
        $sourceFiles = Finder::create()->files()->in('./tests/img')->name('image.jpeg')->getIterator();
92
        $sourceFiles->rewind();
93
94
        return $sourceFiles->current();
95
    }
96
97
    private function createImageObject() {
98
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
99
100
        return $imageObject;
101
    }
102
103
}
104