Completed
Push — master ( deab8c...277293 )
by Siad
16:00
created

ApplyTaskTest   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 501
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 125
dl 0
loc 501
rs 6.4799
c 0
b 0
f 0
wmc 54

42 Methods

Rating   Name   Duplication   Size   Complexity  
A testPropertySetOs() 0 3 1
A testPropertySetPassthru() 0 3 1
A testPropertySetAppend() 0 3 1
A testPropertySetMaxparallel() 0 3 1
A testPropertySetCheckReturn() 0 3 1
A testPropertySetParallel() 0 3 1
A testPropertySetRelative() 0 3 1
A testPropertySetOutput() 0 5 1
A testPropertySetReturnProperty() 0 3 1
A testExecuteOnCorrectOs() 0 4 1
A testPropertySetSpawn() 0 3 1
A testPropertySetError() 0 5 1
A testPropertySetAddsourcefile() 0 3 1
A testDoNotExecuteOnWrongOs() 0 8 1
A setUp() 0 7 1
A testPropertySetForwardslash() 0 3 1
A testPropertySetEscape() 0 3 1
A testFailOnNonExistingDir() 0 11 1
A testPropertySetOutputProperty() 0 3 1
A testPropertySetDir() 0 3 1
A testReturnProperty() 0 4 1
A testOutputAppend() 0 14 2
A testEscape() 0 7 2
A getConfiguredTask() 0 11 2
A testOutputProperty() 0 4 1
A testError() 0 19 1
A testRelativeSourceFilenames() 0 4 1
A testMissingExecutable() 0 3 1
A testCheckreturnFalse() 0 3 1
A getTaskFromTarget() 0 12 4
A testSourceFilename() 0 5 1
A testPassThru() 0 4 1
A testParallel() 0 8 2
A testSpawn() 0 10 1
A assertAttributeIsSetTo() 0 8 2
A testOutput() 0 14 1
A testCheckreturnTrue() 0 4 1
A testEscapedArg() 0 4 2
A getTargetByName() 0 8 3
A testChangeToDir() 0 4 1
A testMapperSupport() 0 14 2
A testNestedArgs() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like ApplyTaskTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ApplyTaskTest, and based on these observations, apply Extract Interface, too.

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
/**
21
 * Tests the Apply Task
22
 *
23
 * @author  Utsav Handa <handautsav at hotmail dot com>
24
 * @package phing.tasks.system
25
 */
26
class ApplyTaskTest extends BuildFileTest
27
{
28
    /**
29
     * Whether test is being run on windows
30
     * @var bool
31
     */
32
    protected $windows;
33
34
    /**
35
     * Setup the test
36
     */
37
    public function setUp(): void
38
    {
39
        // Tests definitions
40
        $this->configureProject(PHING_TEST_BASE . '/etc/tasks/system/ApplyTest.xml');
41
42
        // Identifying the running environment
43
        $this->windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
44
    }
45
46
    /**********************************************************************************/
47
    /************************************** T E S T S *********************************/
48
    /**********************************************************************************/
49
50
    /**
51
     * Tests the OS configuration setting
52
     */
53
    public function testPropertySetOs()
54
    {
55
        $this->assertAttributeIsSetTo('os', 'linux');
56
    }
57
58
    /**
59
     * Tests the dir configuration setting
60
     */
61
    public function testPropertySetDir()
62
    {
63
        $this->assertAttributeIsSetTo('dir', new PhingFile($this->project->getProperty('php.tmpdir')));
64
    }
65
66
    /**
67
     * Tests the escape configuration setting
68
     */
69
    public function testPropertySetEscape()
70
    {
71
        $this->assertAttributeIsSetTo('escape', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
        $this->assertAttributeIsSetTo('escape', /** @scrutinizer ignore-type */ true);
Loading history...
72
    }
73
74
    /**
75
     * Tests the pass-thru configuration setting
76
     */
77
    public function testPropertySetPassthru()
78
    {
79
        $this->assertAttributeIsSetTo('passthru', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $this->assertAttributeIsSetTo('passthru', /** @scrutinizer ignore-type */ true);
Loading history...
80
    }
81
82
    /**
83
     * Tests the spawn configuration setting
84
     */
85
    public function testPropertySetSpawn()
86
    {
87
        $this->assertAttributeIsSetTo('spawn', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $this->assertAttributeIsSetTo('spawn', /** @scrutinizer ignore-type */ true);
Loading history...
88
    }
89
90
    /**
91
     * Tests the returnProperty configuration setting
92
     */
93
    public function testPropertySetReturnProperty()
94
    {
95
        $this->assertAttributeIsSetTo('returnProperty', 'retval');
96
    }
97
98
    /**
99
     * Tests the outputProperty configuration setting
100
     */
101
    public function testPropertySetOutputProperty()
102
    {
103
        $this->assertAttributeIsSetTo('outputProperty', 'outval');
104
    }
105
106
    /**
107
     * Tests the checkReturn/failonerror configuration setting
108
     */
109
    public function testPropertySetCheckReturn()
110
    {
111
        $this->assertAttributeIsSetTo('checkreturn', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
        $this->assertAttributeIsSetTo('checkreturn', /** @scrutinizer ignore-type */ true);
Loading history...
112
    }
113
114
    /**
115
     * Tests the output configuration setting
116
     */
117
    public function testPropertySetOutput()
118
    {
119
        $this->assertAttributeIsSetTo(
120
            'output',
121
            new PhingFile($this->project->getProperty('php.tmpdir') . '/outputfilename')
122
        );
123
    }
124
125
    /**
126
     * Tests the error configuration setting
127
     */
128
    public function testPropertySetError()
129
    {
130
        $this->assertAttributeIsSetTo(
131
            'error',
132
            new PhingFile($this->project->getProperty('php.tmpdir') . '/errorfilename')
133
        );
134
    }
135
136
    /**
137
     * Tests the append configuration setting
138
     */
139
    public function testPropertySetAppend()
140
    {
141
        $this->assertAttributeIsSetTo('append', true, 'appendoutput');
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

141
        $this->assertAttributeIsSetTo('append', /** @scrutinizer ignore-type */ true, 'appendoutput');
Loading history...
142
    }
143
144
    /**
145
     * Tests the parallel configuration setting
146
     */
147
    public function testPropertySetParallel()
148
    {
149
        $this->assertAttributeIsSetTo('parallel', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
        $this->assertAttributeIsSetTo('parallel', /** @scrutinizer ignore-type */ false);
Loading history...
150
    }
151
152
    /**
153
     * Tests the addsourcefile configuration setting
154
     */
155
    public function testPropertySetAddsourcefile()
156
    {
157
        $this->assertAttributeIsSetTo('addsourcefile', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

157
        $this->assertAttributeIsSetTo('addsourcefile', /** @scrutinizer ignore-type */ false);
Loading history...
158
    }
159
160
    /**
161
     * Tests the relative configuration setting
162
     */
163
    public function testPropertySetRelative()
164
    {
165
        $this->assertAttributeIsSetTo('relative', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

165
        $this->assertAttributeIsSetTo('relative', /** @scrutinizer ignore-type */ false);
Loading history...
166
    }
167
168
    /**
169
     * Tests the forwardslash configuration setting
170
     */
171
    public function testPropertySetForwardslash()
172
    {
173
        $this->assertAttributeIsSetTo('forwardslash', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of ApplyTaskTest::assertAttributeIsSetTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

173
        $this->assertAttributeIsSetTo('forwardslash', /** @scrutinizer ignore-type */ true);
Loading history...
174
    }
175
176
    /**
177
     * Tests the maxparallel configuration setting
178
     */
179
    public function testPropertySetMaxparallel()
180
    {
181
        $this->assertAttributeIsSetTo('maxparallel', 10);
182
    }
183
184
    /**
185
     * Tests the OS execution for the unspecified OS
186
     */
187
    public function testDoNotExecuteOnWrongOs()
188
    {
189
190
        // Process
191
        $this->executeTarget(__FUNCTION__);
192
        $this->assertInLogs('was not found in the specified list of valid OSes: unknownos');
193
194
        $this->assertNotContains('this should not be executed', $this->getOutput());
195
    }
196
197
    /**
198
     * Tests the OS execution for the specified OS list
199
     */
200
    public function testExecuteOnCorrectOs()
201
    {
202
        $this->executeTarget(__FUNCTION__);
203
        $this->assertInLogs('this should be executed');
204
    }
205
206
    /**
207
     * Tests the dir changing on a non-existent directory
208
     */
209
    public function testFailOnNonExistingDir()
210
    {
211
        $nonExistentDir = $this->project->getProperty('php.tmpdir') . DIRECTORY_SEPARATOR
212
            . 'non' . DIRECTORY_SEPARATOR
213
            . 'existent' . DIRECTORY_SEPARATOR
214
            . 'dir';
215
216
        return $this->expectBuildExceptionContaining(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->expectBuildExcept...not a valid directory') targeting BuildFileTest::expectBuildExceptionContaining() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
217
            __FUNCTION__,
218
            __FUNCTION__,
219
            "'$nonExistentDir' is not a valid directory"
220
        );
221
    }
222
223
    /**
224
     * Tests the dir changing on an existent directory
225
     *
226
     * @requires OS ^(?:(?!Win).)*$
227
     */
228
    public function testChangeToDir()
229
    {
230
        $this->executeTarget(__FUNCTION__);
231
        $this->assertInLogs('Working directory change successful');
232
    }
233
234
    /**
235
     * Tests the failonerror/checkreturn value for 'true'
236
     *
237
     * @requires OS ^(?:(?!Win).)*$
238
     */
239
    public function testCheckreturnTrue()
240
    {
241
        $this->executeTarget(__FUNCTION__);
242
        $this->assertTrue(true);
243
    }
244
245
    /**
246
     * Tests the failonerror/checkreturn value for 'false'
247
     *
248
     * @requires OS ^(?:(?!Win).)*$
249
     */
250
    public function testCheckreturnFalse()
251
    {
252
        return $this->expectBuildExceptionContaining(__FUNCTION__, __FUNCTION__, 'Task exited with code (1)');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->expectBuildExcept... exited with code (1)') targeting BuildFileTest::expectBuildExceptionContaining() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
253
    }
254
255
    /**
256
     * Tests the outputProperty setting
257
     */
258
    public function testOutputProperty()
259
    {
260
        $this->executeTarget(__FUNCTION__);
261
        $this->assertInLogs('The output property\'s value is: "foo"');
262
    }
263
264
    /**
265
     * Tests the returnProperty setting
266
     */
267
    public function testReturnProperty()
268
    {
269
        $this->executeTarget(__FUNCTION__);
270
        $this->assertInLogs('The return property\'s value is: "1"');
271
    }
272
273
    /**
274
     * Tests the command escaping for execution
275
     */
276
    public function testEscape()
277
    {
278
        $this->executeTarget(__FUNCTION__);
279
        $this->assertInLogs(
280
            $this->windows
281
                ? (escapeshellarg('echo') . ' ' . escapeshellarg('foo') . " " . escapeshellarg('|') . " " . escapeshellarg('cat'))
282
            : ("'echo' 'foo' '|' 'cat'")
283
        );
284
    }
285
286
    /**
287
     * Tests the command execution with 'passthru' function
288
     */
289
    public function testPassThru()
290
    {
291
        $this->executeTarget(__FUNCTION__);
292
        $this->assertInLogs('Executing command:');
293
    }
294
295
    /**
296
     * Tests the output file functionality
297
     */
298
    public function testOutput()
299
    {
300
301
        // Getting a temp. file
302
        $tempfile = tempnam(FileUtils::getTempDir(), 'phing-exectest-');
303
304
        // Setting the property
305
        $this->project->setProperty('execTmpFile', $tempfile);
306
        $this->executeTarget(__FUNCTION__);
307
308
        // Validating the output
309
        $output = @file_get_contents($tempfile);
310
        @unlink($tempfile);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

310
        /** @scrutinizer ignore-unhandled */ @unlink($tempfile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
311
        $this->assertEquals('outfoo', rtrim($output));
312
    }
313
314
    /**
315
     * Tests the error file functionality
316
     *
317
     * @requires OS ^(?:(?!Win).)*$
318
     */
319
    public function testError()
320
    {
321
        // Getting a temp. file
322
        $tempfile = tempnam(FileUtils::getTempDir(), 'phing-exectest-');
323
324
        $scriptFile = getcwd() . "/error_output.sh";
325
        file_put_contents($scriptFile, "echo errfoo 1>&2");
326
        chmod($scriptFile, 0744);
327
328
        // Setting the property
329
        $this->project->setProperty('executable', $scriptFile);
330
        $this->project->setProperty('execTmpFile', $tempfile);
331
        $this->executeTarget(__FUNCTION__);
332
333
        // Validating the output
334
        $output = @file_get_contents($tempfile);
335
        @unlink($tempfile);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

335
        /** @scrutinizer ignore-unhandled */ @unlink($tempfile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
336
        @unlink($scriptFile);
337
        $this->assertEquals("errfoo", rtrim($output));
338
    }
339
340
    /**
341
     * Tests the execution with the background process spawning
342
     *
343
     * @requires OS ^(?:(?!Win).)*$
344
     */
345
    public function testSpawn()
346
    {
347
        // Process
348
        $start = time();
349
        $this->executeTarget(__FUNCTION__);
350
        $end = time();
351
        $this->assertLessThan(
352
            4,
353
            ($end - $start),
354
            'Execution time should be lower than 4 seconds, otherwise spawning did not work'
355
        );
356
    }
357
358
    /**
359
     * Tests the nested arguments specified for the execution
360
     */
361
    public function testNestedArgs()
362
    {
363
        $this->executeTarget(__FUNCTION__);
364
        $this->assertInLogs('echo Hello World');
365
    }
366
367
    /**
368
     * Tests the missing/unspecified executable information
369
     */
370
    public function testMissingExecutable()
371
    {
372
        $this->expectBuildExceptionContaining(__FUNCTION__, __FUNCTION__, 'Please provide "executable" information');
373
    }
374
375
    /**
376
     * Tests the escape functionality for special characters in argument
377
     */
378
    public function testEscapedArg()
379
    {
380
        $this->executeTarget(__FUNCTION__);
381
        $this->assertPropertyEquals('outval', $this->windows ? 'abc$b3 SB' : 'abc$b3!SB');
382
    }
383
384
    /**
385
     * Tests the relative source filenames functionality
386
     *
387
     * @requires OS ^(?:(?!Win).)*$
388
     */
389
    public function testRelativeSourceFilenames()
390
    {
391
        $this->executeTarget(__FUNCTION__);
392
        $this->assertNotInLogs('/etc/');
393
    }
394
395
    /**
396
     * Tests the source filename addition functionality
397
     *
398
     * @requires OS ^(?:(?!Win).)*$
399
     */
400
    public function testSourceFilename()
401
    {
402
        $this->executeTarget(__FUNCTION__);
403
        // As the addsourcefilename is 'off', only the executable should be processed in the execution
404
        $this->assertInLogs('Executing command: ls');
405
    }
406
407
    /**
408
     * Tests the output file append functionality
409
     */
410
    public function testOutputAppend()
411
    {
412
413
        // Getting a temp. file
414
        $tempfile = tempnam(FileUtils::getTempDir(), 'phing-exectest-');
415
416
        // Setting the property
417
        $this->project->setProperty('execTmpFile', $tempfile);
418
        $this->executeTarget(__FUNCTION__);
419
420
        // Validating the output
421
        $output = @file_get_contents($tempfile);
422
        @unlink($tempfile);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

422
        /** @scrutinizer ignore-unhandled */ @unlink($tempfile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
423
        $this->assertEquals($this->windows ? "Append OK \r\nAppend OK" : "Append OK\nAppend OK", rtrim($output));
424
    }
425
426
    /**
427
     * Tests the parallel configuration
428
     */
429
    public function testParallel()
430
    {
431
        $this->executeTarget(__FUNCTION__);
432
        $messages = [];
433
        foreach ($this->logBuffer as $log) {
434
            $messages[] = $log['message'];
435
        }
436
        $this->assertEquals(1, substr_count(implode("\n", $messages), 'Executing command:'));
437
    }
438
439
    public function testMapperSupport()
440
    {
441
        // Getting a temp. file
442
        $tempfile = tempnam(FileUtils::getTempDir(), 'phing-exectest-');
443
444
        // Setting the property
445
        $this->project->setProperty('execTmpFile', $tempfile);
446
447
        $this->executeTarget(__FUNCTION__);
448
        $messages = [];
449
        foreach ($this->logBuffer as $log) {
450
            $messages[] = $log['message'];
451
        }
452
        $this->assertContains('Applied echo to 4 files and 0 directories.', $messages);
453
    }
454
455
456
    /**********************************************************************************/
457
    /************************** H E L P E R  M E T H O D S ****************************/
458
    /**********************************************************************************/
459
460
    /**
461
     * @param  string $name
462
     * @return Target
463
     * @throws Exception
464
     */
465
    protected function getTargetByName($name)
466
    {
467
        foreach ($this->project->getTargets() as $target) {
468
            if ($target->getName() == $name) {
469
                return $target;
470
            }
471
        }
472
        throw new Exception(sprintf('Target "%s" not found', $name));
473
    }
474
475
    /**
476
     * @param  string $target
477
     * @param  string $taskName
478
     * @param  int $pos
479
     * @return Task
480
     * @throws Exception
481
     */
482
    protected function getTaskFromTarget($target, $taskName, $pos = 0)
483
    {
484
        $rchildren = new ReflectionProperty(get_class($target), 'children');
0 ignored issues
show
Bug introduced by
$target of type string is incompatible with the type object expected by parameter $object of get_class(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

484
        $rchildren = new ReflectionProperty(get_class(/** @scrutinizer ignore-type */ $target), 'children');
Loading history...
485
        $rchildren->setAccessible(true);
486
        $n = -1;
487
        foreach ($rchildren->getValue($target) as $child) {
0 ignored issues
show
Bug introduced by
$target of type string is incompatible with the type object expected by parameter $object of ReflectionProperty::getValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

487
        foreach ($rchildren->getValue(/** @scrutinizer ignore-type */ $target) as $child) {
Loading history...
488
            if ($child instanceof Task && ++$n == $pos) {
489
                return $child;
490
            }
491
        }
492
493
        throw new Exception(sprintf('%s #%d not found in task', $taskName, $pos));
494
    }
495
496
    /**
497
     * @param  string $target
498
     * @param  string $task
499
     * @return Task
500
     */
501
    protected function getConfiguredTask($target, $task)
502
    {
503
        $target = $this->getTargetByName($target);
504
        $task = $this->getTaskFromTarget($target, $task);
505
        $task->maybeConfigure();
506
507
        if ($task instanceof UnknownElement) {
508
            return $task->getRuntimeConfigurableWrapper()->getProxy();
509
        }
510
511
        return $task;
512
    }
513
514
    /**
515
     * @param string $property
516
     * @param string $value
517
     * @param string $propertyName
518
     */
519
    protected function assertAttributeIsSetTo($property, $value, $propertyName = null)
520
    {
521
        $task = $this->getConfiguredTask('testPropertySet' . ucfirst($property), 'ApplyTask');
522
523
        $propertyName = ($propertyName === null) ? $property : $propertyName;
524
        $rprop = new ReflectionProperty('ApplyTask', $propertyName);
525
        $rprop->setAccessible(true);
526
        $this->assertEquals($value, $rprop->getValue($task));
527
    }
528
}
529