Completed
Pull Request — master (#41)
by
unknown
02:46
created

ImagyTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php namespace Modules\Media\Tests;
2
3
use Illuminate\Support\Facades\App;
4
use Modules\Media\Image\Imagy;
5
use Modules\Media\Image\Intervention\InterventionFactory;
6
use Modules\Media\Image\ThumbnailsManager;
7
use Modules\Media\ValueObjects\MediaPath;
8
9
class ImagyTest extends MediaTestCase
10
{
11
    /**
12
     * @var Imagy
13
     */
14
    protected $imagy;
15
    /**
16
     * @var \Illuminate\Filesystem\Filesystem
17
     */
18
    protected $finder;
19
    /**
20
     * @var \Illuminate\Contracts\Config\Repository
21
     */
22
    protected $config;
23
    /**
24
     * @var string
25
     */
26
    protected $mediaPath;
27
    private $testbenchPublicPath;
28
29
    /**
30
     *
31
     */
32
    public function setUp()
33
    {
34
        parent::setUp();
35
        $this->config = App::make('Illuminate\Contracts\Config\Repository');
36
        $module = App::make('modules');
37
        $this->finder = App::make('Illuminate\Filesystem\Filesystem');
38
        $this->imagy = new Imagy(new InterventionFactory(), new ThumbnailsManager($this->config, $module), $this->config);
0 ignored issues
show
Unused Code introduced by
The call to ThumbnailsManager::__construct() has too many arguments starting with $module.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Imagy::__construct() has too many arguments starting with $this->config.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
40
        $this->testbenchPublicPath = __DIR__ . '/../vendor/orchestra/testbench/fixture/public/';
41
        $this->mediaPath = __DIR__ . '/Fixtures/';
42
        $this->finder->copy("{$this->mediaPath}google-map.png", "{$this->testbenchPublicPath}google-map.png");
43
    }
44
45
    public function tearDown()
46
    {
47
        $this->finder->delete("{$this->testbenchPublicPath}google-map.png");
48
        $this->finder->delete("{$this->testbenchPublicPath}google-map_smallThumb.png");
49
    }
50
51
    public function it_should_create_a_file()
52
    {
53
        $path = new MediaPath("/google-map.png");
54
        $this->imagy->get($path, 'smallThumb', true);
55
56
        $this->assertTrue($this->finder->isFile("{$this->testbenchPublicPath}google-map_smallThumb.png"));
57
    }
58
59
    /** @test */
60
    public function it_should_not_create_thumbs_for_pdf_files()
61
    {
62
        $this->imagy->get("{$this->mediaPath}test-pdf.pdf", 'smallThumb', true);
63
64
        $this->assertFalse($this->finder->isFile(public_path() . "{$this->mediaPath}test-pdf_smallThumb.png"));
65
    }
66
67
    /** @test */
68
    public function it_should_return_thumbnail_path()
69
    {
70
        $path = $this->imagy->getThumbnail("{$this->mediaPath}google-map.png", 'smallThumb');
71
72
        $expected = config('app.url') . config('asgard.media.config.files-path') . 'google-map_smallThumb.png';
73
74
        $this->assertEquals($expected, $path);
75
    }
76
77
    /** @test */
78
    public function it_should_return_same_path_for_non_images()
79
    {
80
        $path = $this->imagy->getThumbnail("{$this->mediaPath}test-pdf.pdf", 'smallThumb');
81
        $expected = "{$this->mediaPath}test-pdf.pdf";
82
83
        $this->assertEquals($expected, $path);
84
    }
85
86
    /** @test */
87
    public function it_should_detect_an_image()
88
    {
89
        $jpg = $this->imagy->isImage('image.jpg');
90
        $png = $this->imagy->isImage('image.png');
91
        $pdf = $this->imagy->isImage('pdf.pdf');
92
93
        $this->assertTrue($jpg);
94
        $this->assertTrue($png);
95
        $this->assertFalse($pdf);
96
    }
97
}
98