1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-flow |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-flow/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-flow |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFlow\Test\Integration\Flow\File; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Modify\Compress\CompressionFactory; |
17
|
|
|
use Graze\DataFile\Modify\Compress\Gzip; |
18
|
|
|
use Graze\DataFile\Node\LocalFile; |
19
|
|
|
use Graze\DataFlow\Flow; |
20
|
|
|
use Graze\DataFlow\Flow\File\Compression\DeCompress; |
21
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
22
|
|
|
use Graze\DataNode\NodeInterface; |
23
|
|
|
use InvalidArgumentException; |
24
|
|
|
use Mockery as m; |
25
|
|
|
|
26
|
|
View Code Duplication |
class DeCompressTest extends RealFileTestCase |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
public function testDeCompressNotOnLocalFileWillThrowAnException() |
29
|
|
|
{ |
30
|
|
|
$file = m::mock(NodeInterface::class); |
31
|
|
|
$flow = new DeCompress(); |
32
|
|
|
|
33
|
|
|
$this->expectException(InvalidArgumentException::class); |
34
|
|
|
|
35
|
|
|
$flow->flow($file); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDeCompress() |
39
|
|
|
{ |
40
|
|
|
$file = $this->makeFile('decompress/initial/source', 'some text'); |
41
|
|
|
$compressed = Flow::compress(Gzip::NAME)->flow($file); |
42
|
|
|
$flow = new DeCompress(); |
43
|
|
|
|
44
|
|
|
$output = $flow->flow($compressed); |
45
|
|
|
|
46
|
|
|
static::assertNotSame($file, $output); |
47
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
48
|
|
|
static::assertEquals(CompressionFactory::TYPE_NONE, $output->getCompression()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testStaticFlow() |
52
|
|
|
{ |
53
|
|
|
$file = $this->makeFile('decompress/static/source', 'some text'); |
54
|
|
|
$compressed = Flow::compress(Gzip::NAME)->flow($file); |
55
|
|
|
$flow = Flow::decompress(); |
56
|
|
|
|
57
|
|
|
$output = $flow->flow($compressed); |
58
|
|
|
|
59
|
|
|
static::assertNotSame($file, $output); |
60
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
61
|
|
|
static::assertEquals(CompressionFactory::TYPE_NONE, $output->getCompression()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testInvokeFlow() |
65
|
|
|
{ |
66
|
|
|
$file = $this->makeFile('decompress/invoke/source', 'some text'); |
67
|
|
|
$compressed = Flow::compress(Gzip::NAME)->flow($file); |
68
|
|
|
$flow = new DeCompress(); |
69
|
|
|
|
70
|
|
|
$output = call_user_func($flow, $compressed); |
71
|
|
|
|
72
|
|
|
static::assertNotSame($file, $output); |
73
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
74
|
|
|
static::assertEquals(CompressionFactory::TYPE_NONE, $output->getCompression()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.