Passed
Push — main ( a6899b...383ad4 )
by Michiel
08:58
created

AppendTaskTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 19
eloc 53
dl 0
loc 147
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A test2() 0 5 1
A testsame() 0 5 1
A test1() 0 5 1
A setUp() 0 3 1
A testConcatNoNewline() 0 3 1
A testfileheader() 0 4 1
A testFilter() 0 3 1
A testfixlastline() 0 6 1
A test4() 0 3 1
A tearDown() 0 3 1
A testfixlastlineeol() 0 6 1
A testPath() 0 13 1
A testNoOverwrite() 0 6 1
A test3() 0 10 2
A testfilterinline() 0 3 1
A testAppend() 0 13 1
A testheaderfooter() 0 4 1
A testSkipSanitize() 0 5 1
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Test\Task\System;
22
23
use Phing\Exception\BuildException;
24
use Phing\Io\File;
25
use Phing\Test\Support\BuildFileTest;
26
27
/**
28
 * Tests the Append / Concat Task.
29
 *
30
 * @internal
31
 */
32
class AppendTaskTest extends BuildFileTest
33
{
34
    private $tempFile = 'concat.tmp';
35
    private $tempFile2 = 'concat.tmp.2';
36
37
    /**
38
     * Setup the test.
39
     */
40
    public function setUp(): void
41
    {
42
        $this->configureProject(PHING_TEST_BASE . '/etc/tasks/system/AppendTest.xml');
43
    }
44
45
    public function tearDown(): void
46
    {
47
        $this->getProject()->executeTarget('cleanup');
48
    }
49
50
    public function test1(): void
51
    {
52
        $this->expectException(BuildException::class);
53
54
        $this->getProject()->executeTarget(__FUNCTION__);
55
    }
56
57
    public function test2(): void
58
    {
59
        $this->expectException(BuildException::class);
60
61
        $this->getProject()->executeTarget(__FUNCTION__);
62
    }
63
64
    public function test3(): void
65
    {
66
        $file = new File($this->getProjectDir(), $this->tempFile);
67
        if ($file->exists()) {
68
            $file->delete();
69
        }
70
71
        $this->executeTarget(__FUNCTION__);
72
73
        $this->assertTrue($file->exists());
74
    }
75
76
    public function test4(): void
77
    {
78
        $this->expectLog(__FUNCTION__, 'Hello, World!');
79
    }
80
81
    public function testConcatNoNewline(): void
82
    {
83
        $this->expectLog(__FUNCTION__, 'ab');
84
    }
85
86
    public function testPath(): void
87
    {
88
        $this->test3();
89
90
        $file = new File($this->getProjectDir(), $this->tempFile);
91
        $origSize = $file->length();
92
93
        $this->executeTarget('testPath');
94
95
        $file2 = new File($this->getProjectDir(), $this->tempFile2);
96
        $newSize = $file2->length();
97
98
        $this->assertEquals($origSize, $newSize);
99
    }
100
101
    public function testAppend(): void
102
    {
103
        $this->test3();
104
105
        $file = new File($this->getProjectDir(), $this->tempFile);
106
        $origSize = $file->length();
107
108
        $this->executeTarget('testAppend');
109
110
        $file2 = new File($this->getProjectDir(), $this->tempFile2);
111
        $newSize = $file2->length();
112
113
        $this->assertEquals($origSize * 2, $newSize);
114
    }
115
116
    public function testFilter(): void
117
    {
118
        $this->expectLog('testfilter', 'REPLACED');
119
    }
120
121
    public function testNoOverwrite(): void
122
    {
123
        $this->executeTarget('testnooverwrite');
124
        $file2 = new File($this->getProjectDir(), $this->tempFile2);
125
        $size = $file2->length();
126
        $this->assertEquals(0, $size);
127
    }
128
129
    public function testheaderfooter(): void
130
    {
131
        $this->test3();
132
        $this->expectLog('testheaderfooter', 'headerHello, World!footer');
133
    }
134
135
    public function testfileheader(): void
136
    {
137
        $this->test3();
138
        $this->expectLog('testfileheader', 'Hello, World!Hello, World!');
139
    }
140
141
    /**
142
     * Expect an exception when attempting to cat an file to itself.
143
     */
144
    public function testsame(): void
145
    {
146
        $this->expectException(BuildException::class);
147
148
        $this->executeTarget('samefile');
149
    }
150
151
    public function testfilterinline(): void
152
    {
153
        $this->expectLogContaining('testfilterinline', 'REPLACED');
154
    }
155
156
    public function testfixlastline(): void
157
    {
158
        $this->executeTarget('testfixlastline');
159
        $this->assertStringContainsString(
160
            'end of line' . $this->getProject()->getProperty('line.separator') . 'This has',
161
            file_get_contents($this->getProject()->getProperty('basedir') . 'concat.line4')
162
        );
163
    }
164
165
    public function testfixlastlineeol(): void
166
    {
167
        $this->executeTarget('testfixlastlineeol');
168
        $this->assertStringContainsString(
169
            "end of line\rThis has",
170
            file_get_contents($this->getProject()->getProperty('basedir') . 'concat.linecr')
171
        );
172
    }
173
174
    public function testSkipSanitize(): void
175
    {
176
        $this->executeTarget('testskipsanitize');
177
        $contents = file_get_contents($this->getProject()->getProperty('basedir') . $this->tempFile);
178
        $this->assertEquals("\n foo", $contents);
179
    }
180
}
181