Completed
Push — feature/0.7.0 ( 38440f...02d6a4 )
by Ryuichi
07:28
created

FileWriterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 65
loc 65
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A okWriteFromFilePath() 12 12 1
A okWriteFromFileObject() 12 12 1
A okWriteAppend() 16 16 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
namespace WebStream\IO\Test;
3
4
require_once dirname(__FILE__) . '/../InputStream.php';
5
require_once dirname(__FILE__) . '/../OutputStream.php';
6
require_once dirname(__FILE__) . '/../File.php';
7
require_once dirname(__FILE__) . '/../FileInputStream.php';
8
require_once dirname(__FILE__) . '/../FileOutputStream.php';
9
require_once dirname(__FILE__) . '/../Reader/InputStreamReader.php';
10
require_once dirname(__FILE__) . '/../Reader/FileReader.php';
11
require_once dirname(__FILE__) . '/../Writer/OutputStreamWriter.php';
12
require_once dirname(__FILE__) . '/../Writer/FileWriter.php';
13
require_once dirname(__FILE__) . '/../Test/Providers/FileWriterProvider.php';
14
require_once dirname(__FILE__) . '/../Test/Modules/IOException.php';
15
16
use WebStream\IO\File;
17
use WebStream\IO\Reader\FileReader;
18
use WebStream\IO\Writer\FileWriter;
19
use WebStream\IO\Test\Providers\FileWriterProvider;
20
21
/**
22
 * FileWriterTest
23
 * @author Ryuichi TANAKA.
24
 * @since 2016/08/18
25
 * @version 0.7
26
 */
27 View Code Duplication
class FileWriterTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
28
{
29
    use FileWriterProvider;
30
31
    /**
32
     * 正常系
33
     * ファイルパスからファイルに書き込みできること
34
     * @test
35
     * @dataProvider writeProvider
36
     */
37
    public function okWriteFromFilePath($filePath, $content)
38
    {
39
        $file = new File($filePath);
40
        $file->delete();
41
42
        $writer = new FileWriter($filePath);
43
        $writer->write($content);
44
        $writer->close();
45
46
        $reader = new FileReader($filePath);
47
        $this->assertEquals($reader->read(), $content);
48
    }
49
50
    /**
51
     * 正常系
52
     * ファイルオブジェクトからファイルに書き込みできること
53
     * @test
54
     * @dataProvider writeProvider
55
     */
56
    public function okWriteFromFileObject($filePath, $content)
57
    {
58
        $file = new File($filePath);
59
        $file->delete();
60
61
        $writer = new FileWriter($file);
62
        $writer->write($content);
63
        $writer->close();
64
65
        $reader = new FileReader($filePath);
66
        $this->assertEquals($reader->read(), $content);
67
    }
68
69
    /**
70
     * 正常系
71
     * ファイルに追記できること
72
     * @test
73
     * @dataProvider writeAppendProvider
74
     */
75
    public function okWriteAppend($filePath, $content, $result)
76
    {
77
        $file = new File($filePath);
78
        $file->delete();
79
80
        $writer = new FileWriter($filePath);
81
        $writer->write($content);
82
        $writer->close();
83
84
        $writer = new FileWriter($filePath, true);
85
        $writer->write($content);
86
        $writer->close();
87
88
        $reader = new FileReader($filePath);
89
        $this->assertEquals($reader->read(), $result);
90
    }
91
}
92