|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Brendt\Image\Scaler; |
|
4
|
|
|
|
|
5
|
|
|
use Brendt\Image\Config\DefaultConfigurator; |
|
6
|
|
|
use Intervention\Image\ImageManager; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
9
|
|
|
use Symfony\Component\Finder\Finder; |
|
10
|
|
|
|
|
11
|
|
|
class SizesScalerTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var Filesystem |
|
16
|
|
|
*/ |
|
17
|
|
|
private $fs; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $publicPath = './tests/public'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ImageManager |
|
26
|
|
|
*/ |
|
27
|
|
|
private $engine; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function __construct() { |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
|
|
33
|
|
|
$this->fs = new Filesystem(); |
|
34
|
|
|
$this->engine = new ImageManager([ |
|
35
|
|
|
'driver' => 'gd', |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function __destruct() { |
|
40
|
|
|
if ($this->fs->exists($this->publicPath)) { |
|
41
|
|
|
$this->fs->remove($this->publicPath); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function test_scale_down() { |
|
47
|
|
|
$scaler = new SizesScaler(new DefaultConfigurator([ |
|
48
|
|
|
'publicPath' => $this->publicPath, |
|
49
|
|
|
])); |
|
50
|
|
|
$scaler->setSizes([500, 10000, 1920]); |
|
51
|
|
|
|
|
52
|
|
|
$sourceFile = $this->createSourceFile(); |
|
53
|
|
|
$imageObject = $this->createImageObject(); |
|
54
|
|
|
|
|
55
|
|
|
$sizes = $scaler->scale($sourceFile, $imageObject); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertCount(2, $sizes); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
private function createImageObject() { |
|
62
|
|
|
$imageObject = $this->engine->make('./tests/img/image.jpeg'); |
|
63
|
|
|
|
|
64
|
|
|
return $imageObject; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function createSourceFile() { |
|
68
|
|
|
$sourceFiles = Finder::create()->files()->in('./tests/img')->name('image.jpeg')->getIterator(); |
|
69
|
|
|
$sourceFiles->rewind(); |
|
70
|
|
|
|
|
71
|
|
|
return $sourceFiles->current(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|