ImagyTest::it_should_create_a_file()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 10
rs 9.4286
cc 2
eloc 5
nc 2
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
8
class ImagyTest extends MediaTestCase
9
{
10
    /**
11
     * @var Imagy
12
     */
13
    protected $imagy;
14
    /**
15
     * @var \Illuminate\Filesystem\Filesystem
16
     */
17
    protected $finder;
18
    /**
19
     * @var \Illuminate\Contracts\Config\Repository
20
     */
21
    protected $config;
22
    /**
23
     * @var string
24
     */
25
    protected $mediaPath;
26
    private $testbenchPublicPath;
27
28
    /**
29
     *
30
     */
31
    public function setUp()
32
    {
33
        parent::setUp();
34
        $this->config = App::make('Illuminate\Contracts\Config\Repository');
35
        $module = App::make('modules');
36
        $this->finder = App::make('Illuminate\Filesystem\Filesystem');
37
        $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...
38
39
        $this->testbenchPublicPath = __DIR__ . '/../vendor/orchestra/testbench/fixture/public/';
40
        $this->mediaPath = __DIR__ . '/Fixtures/';
41
        $this->finder->copy("{$this->mediaPath}google-map.png", "{$this->testbenchPublicPath}google-map.png");
42
    }
43
44
    public function tearDown()
45
    {
46
        $this->finder->delete("{$this->testbenchPublicPath}google-map.png");
47
        $this->finder->delete("{$this->testbenchPublicPath}google-map_smallThumb.png");
48
    }
49
50
    /** @test */
51
    public function it_should_create_a_file()
52
    {
53
        if ($this->finder->isFile("{$this->mediaPath}google-map_smallThumb.png")) {
54
            $this->finder->delete("{$this->mediaPath}google-map_smallThumb.png");
55
        }
56
57
        $this->imagy->get("/google-map.png", 'smallThumb', true);
58
59
        $this->assertTrue($this->finder->isFile("{$this->testbenchPublicPath}google-map_smallThumb.png"));
60
    }
61
62
    /** @test */
63
    public function it_should_not_create_thumbs_for_pdf_files()
64
    {
65
        $this->imagy->get("{$this->mediaPath}test-pdf.pdf", 'smallThumb', true);
66
67
        $this->assertFalse($this->finder->isFile(public_path() . "{$this->mediaPath}test-pdf_smallThumb.png"));
68
    }
69
70
    /** @test */
71 View Code Duplication
    public function it_should_return_thumbnail_path()
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...
72
    {
73
        $path = $this->mediaPath;
74
        $path .= $this->imagy->getThumbnail("{$this->mediaPath}google-map.png", 'smallThumb');
75
        $expected = "{$this->mediaPath}google-map_smallThumb.png";
76
77
        $this->assertEquals($expected, $path);
78
    }
79
80
    /** @test */
81 View Code Duplication
    public function it_should_return_same_path_for_non_images()
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...
82
    {
83
        $path = $this->imagy->getThumbnail("{$this->mediaPath}test-pdf.pdf", 'smallThumb');
84
        $expected = "{$this->mediaPath}test-pdf.pdf";
85
86
        $this->assertEquals($expected, $path);
87
    }
88
89
    /** @test */
90
    public function it_should_detect_an_image()
91
    {
92
        $jpg = $this->imagy->isImage('image.jpg');
93
        $png = $this->imagy->isImage('image.png');
94
        $pdf = $this->imagy->isImage('pdf.pdf');
95
96
        $this->assertTrue($jpg);
97
        $this->assertTrue($png);
98
        $this->assertFalse($pdf);
99
    }
100
}
101