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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.