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\Node\LocalFile; |
17
|
|
|
use Graze\DataFlow\Flow; |
18
|
|
|
use Graze\DataFlow\Flow\File\ConvertEncoding; |
19
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
20
|
|
|
use Graze\DataNode\NodeInterface; |
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
use Mockery as m; |
23
|
|
|
|
24
|
|
|
class ConvertEncodingTest extends RealFileTestCase |
25
|
|
|
{ |
26
|
|
|
public function testConvertEncodingNotOnLocalFileWillThrowAnException() |
27
|
|
|
{ |
28
|
|
|
$file = m::mock(NodeInterface::class); |
29
|
|
|
$flow = new ConvertEncoding('UTF-16'); |
30
|
|
|
|
31
|
|
|
$this->expectException(InvalidArgumentException::class); |
32
|
|
|
|
33
|
|
|
$flow->flow($file); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testChangeEncoding() |
37
|
|
|
{ |
38
|
|
|
$file = $this->makeFile('encoding.utf8', mb_convert_encoding('some#¢±±§', 'UTF-8')); |
39
|
|
|
$file->setEncoding('UTF-8'); |
40
|
|
|
$flow = new ConvertEncoding('UTF-16'); |
41
|
|
|
|
42
|
|
|
$output = $flow->flow($file); |
43
|
|
|
|
44
|
|
|
static::assertNotSame($file, $output); |
45
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
46
|
|
|
static::assertEquals('UTF-16', $output->getEncoding()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testStaticFlow() |
50
|
|
|
{ |
51
|
|
|
$file = $this->makeFile('encoding.static.utf8', mb_convert_encoding('some#¢±±§', 'UTF-8')); |
52
|
|
|
$file->setEncoding('UTF-8'); |
53
|
|
|
$flow = Flow::convertEncoding('UTF-16'); |
54
|
|
|
|
55
|
|
|
$output = $flow->flow($file); |
56
|
|
|
|
57
|
|
|
static::assertNotSame($file, $output); |
58
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
59
|
|
|
static::assertEquals('UTF-16', $output->getEncoding()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testInvokeFlow() |
63
|
|
|
{ |
64
|
|
|
$file = $this->makeFile('encoding.invoke.utf8', mb_convert_encoding('some#¢±±§', 'UTF-8')); |
65
|
|
|
$file->setEncoding('UTF-8'); |
66
|
|
|
$flow = Flow::convertEncoding('UTF-16'); |
67
|
|
|
|
68
|
|
|
$output = call_user_func($flow, $file); |
69
|
|
|
|
70
|
|
|
static::assertNotSame($file, $output); |
71
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
72
|
|
|
static::assertEquals('UTF-16', $output->getEncoding()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|