Passed
Push — master ( 972120...1c77fc )
by Michiel
08:19
created

AppendTaskTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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