1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Component\Core\Uploader; |
13
|
|
|
|
14
|
|
|
use Gaufrette\Filesystem; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Prophecy\Argument; |
17
|
|
|
use Sylius\Component\Core\Model\ImageInterface; |
18
|
|
|
use Sylius\Component\Core\Uploader\ImageUploader; |
19
|
|
|
use Sylius\Component\Core\Uploader\ImageUploaderInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
21
|
|
|
|
22
|
|
|
final class ImageUploaderSpec extends ObjectBehavior |
23
|
|
|
{ |
24
|
|
|
function let(Filesystem $filesystem, ImageInterface $image) |
25
|
|
|
{ |
26
|
|
|
$filesystem->has(Argument::any())->willReturn(false); |
27
|
|
|
|
28
|
|
|
$file = new File(__FILE__, 'img.jpg'); |
29
|
|
|
$image->getFile()->willReturn($file); |
30
|
|
|
|
31
|
|
|
$this->beConstructedWith($filesystem); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType(ImageUploader::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_is_an_image_uploader() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement(ImageUploaderInterface::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_uploads_an_image($filesystem, $image) |
45
|
|
|
{ |
46
|
|
|
$image->hasFile()->willReturn(true); |
47
|
|
|
$image->getPath()->willReturn('foo.jpg'); |
48
|
|
|
|
49
|
|
|
$filesystem->has('foo.jpg')->willReturn(false); |
50
|
|
|
|
51
|
|
|
$filesystem->delete(Argument::any())->shouldNotBeCalled(); |
52
|
|
|
|
53
|
|
|
$image->setPath(Argument::type('string'))->will(function ($args) use ($image, $filesystem) { |
54
|
|
|
$image->getPath()->willReturn($args[0]); |
55
|
|
|
|
56
|
|
|
$filesystem->write($args[0], Argument::any())->shouldBeCalled(); |
57
|
|
|
})->shouldBeCalled(); |
58
|
|
|
|
59
|
|
|
$this->upload($image); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function it_replaces_an_image($filesystem, $image) |
63
|
|
|
{ |
64
|
|
|
$image->hasFile()->willReturn(true); |
65
|
|
|
$image->getPath()->willReturn('foo.jpg'); |
66
|
|
|
|
67
|
|
|
$filesystem->has('foo.jpg')->willReturn(true); |
68
|
|
|
|
69
|
|
|
$filesystem->delete('foo.jpg')->shouldBeCalled(); |
70
|
|
|
|
71
|
|
|
$image->setPath(Argument::type('string'))->will(function ($args) use ($image, $filesystem) { |
72
|
|
|
$image->getPath()->willReturn($args[0]); |
73
|
|
|
|
74
|
|
|
$filesystem->write($args[0], Argument::any())->shouldBeCalled(); |
75
|
|
|
})->shouldBeCalled(); |
76
|
|
|
|
77
|
|
|
$this->upload($image); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.