Passed
Push — main ( 2c83d5...fb3f8a )
by Siad
05:21
created

testEmptyElementIfIsReference()   F

Complexity

Conditions 17
Paths > 20000

Size

Total Lines 246
Code Lines 184

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 184
dl 0
loc 246
rs 0.8399
c 0
b 0
f 0
cc 17
nc 43046721
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Test\Type;
21
22
use Phing\Exception\BuildException;
23
use Phing\Io\File;
24
use Phing\Project;
25
use Phing\Type\FileSet;
26
use Phing\Type\Reference;
27
28
/**
29
 * Unit tests for AbstractFileSet.
30
 *
31
 * @author Hans Lellelid <[email protected]>
32
 */
33
abstract class AbstractFileSetTest extends \PHPUnit\Framework\TestCase
34
{
35
    /** @var Project */
36
    private $project;
37
38
    public function setUp(): void
39
    {
40
        $this->project = new Project();
41
        $this->project->setBasedir(PHING_TEST_BASE);
42
    }
43
44
    abstract protected function getInstance();
45
46
    final protected function getProject()
47
    {
48
        return $this->project;
49
    }
50
51
    final public function testEmptyElementIfIsReference()
52
    {
53
        /** @var FileSet $f */
54
        $f = $this->getInstance();
55
        $f->setIncludes("**/*.php");
56
        try {
57
            $f->setRefid(new Reference($this->getProject(), "dummyref"));
58
            $this->fail(
59
                "Can add reference to "
60
                . $f
61
                . " with elements from setIncludes"
62
            );
63
        } catch (BuildException $be) {
64
            $this->assertEquals(
65
                "You must not specify more than one attribute "
66
                . "when using refid",
67
                $be->getMessage()
68
            );
69
        }
70
71
        $f = $this->getInstance();
72
        $f->createPatternSet();
73
        try {
74
            $f->setRefid(new Reference($this->getProject(), "dummyref"));
75
            $this->fail(
76
                "Can add reference to "
77
                . $f
78
                . " with nested patternset element."
79
            );
80
        } catch (BuildException $be) {
81
            $this->assertEquals(
82
                "You must not specify nested elements when "
83
                . "using refid",
84
                $be->getMessage()
85
            );
86
        }
87
88
        $f = $this->getInstance();
89
        $f->createInclude();
90
        try {
91
            $f->setRefid(new Reference($this->getProject(), "dummyref"));
92
            $this->fail(
93
                "Can add reference to "
94
                . $f
95
                . " with nested include element."
96
            );
97
        } catch (BuildException $be) {
98
            $this->assertEquals(
99
                "You must not specify more than one attribute "
100
                . "when using refid",
101
                $be->getMessage()
102
            );
103
        }
104
105
        $f = $this->getInstance();
106
        $f->setRefid(new Reference($this->getProject(), "dummyref"));
107
        try {
108
            $f->setIncludes("**/*.java");
109
            $this->fail(
110
                "Can set includes in "
111
                . $f
112
                . " that is a reference."
113
            );
114
        } catch (BuildException $be) {
115
            $this->assertEquals(
116
                "You must not specify more than one attribute "
117
                . "when using refid",
118
                $be->getMessage()
119
            );
120
        }
121
122
        try {
123
            $f->setIncludesfile(new File("/a"));
124
            $this->fail(
125
                "Can set includesfile in "
126
                . $f
127
                . " that is a reference."
128
            );
129
        } catch (BuildException $be) {
130
            $this->assertEquals(
131
                "You must not specify more than one attribute "
132
                . "when using refid",
133
                $be->getMessage()
134
            );
135
        }
136
137
        try {
138
            $f->setExcludes("**/*.java");
139
            $this->fail(
140
                "Can set excludes in "
141
                . $f
142
                . " that is a reference."
143
            );
144
        } catch (BuildException $be) {
145
            $this->assertEquals(
146
                "You must not specify more than one attribute "
147
                . "when using refid",
148
                $be->getMessage()
149
            );
150
        }
151
152
        try {
153
            $f->setExcludesfile(new File("/a"));
154
            $this->fail(
155
                "Can set excludesfile in "
156
                . $f
157
                . " that is a reference."
158
            );
159
        } catch (BuildException $be) {
160
            $this->assertEquals(
161
                "You must not specify more than one attribute "
162
                . "when using refid",
163
                $be->getMessage()
164
            );
165
        }
166
167
        try {
168
            $f->setDir($this->project->resolveFile("."));
169
            $this->fail(
170
                "Can set dir in "
171
                . $f
172
                . " that is a reference."
173
            );
174
        } catch (BuildException $be) {
175
            $this->assertEquals(
176
                "You must not specify more than one attribute "
177
                . "when using refid",
178
                $be->getMessage()
179
            );
180
        }
181
182
        try {
183
            $f->setExpandSymbolicLinks(true);
184
            $this->fail(
185
                "Can expand symbolic links in "
186
                . $f
187
                . " that is a reference."
188
            );
189
        } catch (BuildException $be) {
190
            $this->assertEquals(
191
                "You must not specify more than one attribute "
192
                . "when using refid",
193
                $be->getMessage()
194
            );
195
        }
196
197
        try {
198
            $f->setFile($this->project->resolveFile(__FILE__));
199
            $this->fail(
200
                "Can set file in "
201
                . $f
202
                . " that is a reference."
203
            );
204
        } catch (BuildException $be) {
205
            $this->assertEquals(
206
                "You must not specify more than one attribute "
207
                . "when using refid",
208
                $be->getMessage()
209
            );
210
        }
211
212
        try {
213
            $f->setCaseSensitive(true);
214
            $this->fail(
215
                "Can set case sensitive in "
216
                . $f
217
                . " that is a reference."
218
            );
219
        } catch (BuildException $be) {
220
            $this->assertEquals(
221
                "You must not specify more than one attribute "
222
                . "when using refid",
223
                $be->getMessage()
224
            );
225
        }
226
227
        try {
228
            $f->createInclude();
229
            $this->fail(
230
                "Can add nested include in "
231
                . $f
232
                . " that is a reference."
233
            );
234
        } catch (BuildException $be) {
235
            $this->assertEquals(
236
                "You must not specify nested elements when using "
237
                . "refid",
238
                $be->getMessage()
239
            );
240
        }
241
242
        try {
243
            $f->createExclude();
244
            $this->fail(
245
                "Can add nested exclude in "
246
                . $f
247
                . " that is a reference."
248
            );
249
        } catch (BuildException $be) {
250
            $this->assertEquals(
251
                "You must not specify nested elements when using "
252
                . "refid",
253
                $be->getMessage()
254
            );
255
        }
256
257
        try {
258
            $f->createIncludesFile();
259
            $this->fail(
260
                "Can add nested includesfile in "
261
                . $f
262
                . " that is a reference."
263
            );
264
        } catch (BuildException $be) {
265
            $this->assertEquals(
266
                "You must not specify nested elements when using "
267
                . "refid",
268
                $be->getMessage()
269
            );
270
        }
271
        try {
272
            $f->createExcludesFile();
273
            $this->fail(
274
                "Can add nested excludesfile in "
275
                . $f
276
                . " that is a reference."
277
            );
278
        } catch (BuildException $be) {
279
            $this->assertEquals(
280
                "You must not specify nested elements when using "
281
                . "refid",
282
                $be->getMessage()
283
            );
284
        }
285
        try {
286
            $f->createPatternSet();
287
            $this->fail(
288
                "Can add nested patternset in "
289
                . $f
290
                . " that is a reference."
291
            );
292
        } catch (BuildException $be) {
293
            $this->assertEquals(
294
                "You must not specify nested elements when using "
295
                . "refid",
296
                $be->getMessage()
297
            );
298
        }
299
    }
300
}
301