Completed
Push — master ( d200fe...a670ca )
by Siad
13:12
created

FileUtilsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 40
rs 10
c 2
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A contentEquals() 0 8 1
A setUp() 0 5 1
A tearDown() 0 3 1
A copyFile() 0 7 1
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
 * @package phing.util
20
 */
21
22
/**
23
 * Testcases for phing.util.FileUtils
24
 *
25
 * @author  Siad Ardroumli |[email protected]>
26
 * @package phing.util
27
 */
28
class FileUtilsTest extends BuildFileTest
29
{
30
    /** @var FileUtils $fu */
31
    private $fu;
32
33
    public function setUp(): void
34
    {
35
        $this->fu = new FileUtils();
36
        $this->configureProject(PHING_TEST_BASE . "/etc/util/fileutils.xml");
37
        $this->executeTarget('dummy');
38
    }
39
40
    public function tearDown(): void
41
    {
42
        $this->fu = null;
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function contentEquals()
49
    {
50
        $this->assertFalse($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile('does_not_exists')));
51
        $this->assertFalse($this->fu->contentEquals(new PhingFile('does_not_exists'), new PhingFile(__FILE__)));
52
        $this->assertFalse($this->fu->contentEquals(new PhingFile(__DIR__), new PhingFile(__DIR__)));
53
        $this->assertFalse($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile(__DIR__)));
54
        $this->assertFalse($this->fu->contentEquals(new PhingFile(__DIR__), new PhingFile(__FILE__)));
55
        $this->assertTrue($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile(__FILE__)));
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function copyFile()
62
    {
63
        $this->fu->copyFile(new PhingFile(__FILE__), new PhingFile('tmp/test.php'), $this->getProject());
64
        try {
65
            $this->assertFileExists('tmp/test.php');
66
        } finally {
67
            @unlink('tmp/test.php');
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

67
            /** @scrutinizer ignore-unhandled */ @unlink('tmp/test.php');

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...
68
        }
69
    }
70
}
71