Completed
Push — master ( 0136c1...94aca9 )
by Lukas Kahwe
03:29
created

StreamLoaderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 48.98 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 24
loc 49
c 0
b 0
f 0
wmc 4
lcom 2
cbo 2
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\ImagineBundle\Tests\Binary\Loader;
4
5
use Liip\ImagineBundle\Binary\Loader\StreamLoader;
6
use Liip\ImagineBundle\Tests\AbstractTest;
7
8
/**
9
 * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader<extended>
10
 */
11
class StreamLoaderTest extends AbstractTest
12
{
13
    public function testThrowsIfInvalidPathGivenOnFind()
14
    {
15
        $loader = new StreamLoader('file://');
16
17
        $path = $this->tempDir.'/invalid.jpeg';
18
19
        $this->setExpectedException(
20
            'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException',
21
            'Source image file://'.$path.' not found.'
22
        );
23
24
        $loader->find($path);
25
    }
26
27
    public function testReturnImageContentOnFind()
28
    {
29
        $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
30
31
        $loader = new StreamLoader('file://');
32
33
        $this->assertSame(
34
            $expectedContent,
35
            $loader->find($this->fixturesDir.'/assets/cats.jpeg')
36
        );
37
    }
38
39
    public function testReturnImageContentWhenStreamContextProvidedOnFind()
40
    {
41
        $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
42
43
        $context = stream_context_create();
44
45
        $loader = new StreamLoader('file://', $context);
46
47
        $this->assertSame(
48
            $expectedContent,
49
            $loader->find($this->fixturesDir.'/assets/cats.jpeg')
50
        );
51
    }
52
53
    public function testThrowsIfInvalidResourceGivenInConstructor()
54
    {
55
        $this->setExpectedException('InvalidArgumentException', 'The given context is no valid resource.');
56
57
        new StreamLoader('not valid resource', true);
58
    }
59
}
60