Completed
Pull Request — master (#1)
by Harry
04:42
created

CompressionFactoryTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 19.72 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 14
loc 71
wmc 10
lcom 1
cbo 2
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetCompressorForGzipReturnsGzip() 7 7 1
A testGetCompressorForZipReturnsZip() 7 7 1
A testGetCompressorForNoneWillThrowAnException() 0 5 1
A testGetDeCompressorForNoneWillThrowAnException() 0 5 1
A testGetCompressorForUnknownWillThrowAnException() 0 5 1
A testGetDeCompressorForUnknownWillThrowAnException() 0 5 1
A testGetCompressorForRandomWillThrowAnException() 0 5 1
A testGetDeCompressorForRandomWillThrowAnException() 0 5 1
A testIsCompression() 0 6 1

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 Graze\DataFile\Test\Unit\Modify\Compress;
4
5
use Graze\DataFile\Modify\Compress\CompressionFactory;
6
use Graze\DataFile\Modify\Compress\Gzip;
7
use Graze\DataFile\Modify\Compress\Zip;
8
use Graze\DataFile\Modify\Exception\InvalidCompressionTypeException;
9
use Graze\DataFile\Test\TestCase;
10
11
class CompressionFactoryTest extends TestCase
12
{
13
    /**
14
     * @var CompressionFactory
15
     */
16
    private $factory;
17
18
    public function setUp()
19
    {
20
        $this->factory = new CompressionFactory();
21
    }
22
23 View Code Duplication
    public function testGetCompressorForGzipReturnsGzip()
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...
24
    {
25
        $object = $this->factory->getCompressor(Gzip::NAME);
26
        static::assertInstanceOf(Gzip::class, $object);
27
        $object = $this->factory->getDeCompressor(Gzip::NAME);
28
        static::assertInstanceOf(Gzip::class, $object);
29
    }
30
31 View Code Duplication
    public function testGetCompressorForZipReturnsZip()
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...
32
    {
33
        $object = $this->factory->getCompressor(Zip::NAME);
34
        static::assertInstanceOf(Zip::class, $object);
35
        $object = $this->factory->getDeCompressor(Zip::NAME);
36
        static::assertInstanceOf(Zip::class, $object);
37
    }
38
39
    public function testGetCompressorForNoneWillThrowAnException()
40
    {
41
        $this->expectException(InvalidCompressionTypeException::class);
42
        $this->factory->getCompressor(CompressionFactory::TYPE_NONE);
43
    }
44
45
    public function testGetDeCompressorForNoneWillThrowAnException()
46
    {
47
        $this->expectException(InvalidCompressionTypeException::class);
48
        $this->factory->getDeCompressor(CompressionFactory::TYPE_NONE);
49
    }
50
51
    public function testGetCompressorForUnknownWillThrowAnException()
52
    {
53
        $this->expectException(InvalidCompressionTypeException::class);
54
        $this->factory->getCompressor(CompressionFactory::TYPE_UNKNOWN);
55
    }
56
57
    public function testGetDeCompressorForUnknownWillThrowAnException()
58
    {
59
        $this->expectException(InvalidCompressionTypeException::class);
60
        $this->factory->getDeCompressor(CompressionFactory::TYPE_UNKNOWN);
61
    }
62
63
    public function testGetCompressorForRandomWillThrowAnException()
64
    {
65
        $this->expectException(InvalidCompressionTypeException::class);
66
        $this->factory->getCompressor('random');
67
    }
68
69
    public function testGetDeCompressorForRandomWillThrowAnException()
70
    {
71
        $this->expectException(InvalidCompressionTypeException::class);
72
        $this->factory->getDeCompressor('random');
73
    }
74
75
    public function testIsCompression()
76
    {
77
        static::assertTrue($this->factory->isCompression(Gzip::NAME));
78
        static::assertTrue($this->factory->isCompression(Zip::NAME));
79
        static::assertFalse($this->factory->isCompression('lzop'));
80
    }
81
}
82