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\Compress; |
21
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
22
|
|
|
use Graze\DataNode\NodeInterface; |
23
|
|
|
use InvalidArgumentException; |
24
|
|
|
use Mockery as m; |
25
|
|
|
|
26
|
|
|
class CompressTest extends RealFileTestCase |
27
|
|
|
{ |
28
|
|
|
public function testCompressNotOnLocalFileWillThrowAnException() |
29
|
|
|
{ |
30
|
|
|
$file = m::mock(NodeInterface::class); |
31
|
|
|
$flow = new Compress(Gzip::NAME); |
32
|
|
|
|
33
|
|
|
$this->expectException(InvalidArgumentException::class); |
34
|
|
|
|
35
|
|
|
$flow->flow($file); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCompress() |
39
|
|
|
{ |
40
|
|
|
$file = $this->makeFile('compress/initial/source', 'some text'); |
41
|
|
|
$file->setCompression(CompressionFactory::TYPE_NONE); |
42
|
|
|
$flow = new Compress(Gzip::NAME); |
43
|
|
|
|
44
|
|
|
$output = $flow->flow($file); |
45
|
|
|
|
46
|
|
|
static::assertNotSame($file, $output); |
47
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
48
|
|
|
static::assertEquals(Gzip::NAME, $output->getCompression()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testStaticFlow() |
52
|
|
|
{ |
53
|
|
|
$file = $this->makeFile('compress/static/source', 'some text'); |
54
|
|
|
$file->setCompression(CompressionFactory::TYPE_NONE); |
55
|
|
|
$flow = Flow::compress(Gzip::NAME); |
56
|
|
|
|
57
|
|
|
$output = $flow->flow($file); |
58
|
|
|
|
59
|
|
|
static::assertNotSame($file, $output); |
60
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
61
|
|
|
static::assertEquals(Gzip::NAME, $output->getCompression()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testInvokeFlow() |
65
|
|
|
{ |
66
|
|
|
$file = $this->makeFile('compress/invoke/source', 'some text'); |
67
|
|
|
$file->setCompression(CompressionFactory::TYPE_NONE); |
68
|
|
|
$flow = new Compress(Gzip::NAME); |
69
|
|
|
|
70
|
|
|
$output = call_user_func($flow, $file); |
71
|
|
|
|
72
|
|
|
static::assertNotSame($file, $output); |
73
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
74
|
|
|
static::assertEquals(Gzip::NAME, $output->getCompression()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|