Completed
Push — master ( e3c367...50cdb6 )
by Siad
21:57
created

ZipUnzipTaskTest::testZipBaseDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
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
/**
21
 * Tests the Zip and Unzip tasks
22
 *
23
 * @author  Michiel Rook <[email protected]>
24
 * @package phing.tasks.ext
25
 *
26
 * @requires extension zip
27
 */
28
class ZipUnzipTaskTest extends BuildFileTest
29
{
30
    public function setUp(): void
31
    {
32
        $this->configureProject(
33
            PHING_TEST_BASE
34
            . "/etc/tasks/ext/ZipUnzipTaskTest.xml"
35
        );
36
        $this->executeTarget("setup");
37
    }
38
39
    public function tearDown(): void
40
    {
41
        $this->executeTarget("clean");
42
    }
43
44
    public function testSimpleZipContainsOneFile()
45
    {
46
        $filename = PHING_TEST_BASE .
47
            "/etc/tasks/ext/tmp/simple-test.zip";
48
49
        $this->executeTarget(__FUNCTION__);
50
        $this->assertFileExists($filename);
51
52
        $archive = new ZipArchive();
53
        $archive->open($filename);
54
55
        $this->assertEquals('test.txt', $archive->getNameIndex(0));
56
    }
57
58
    public function testZipFileSet()
59
    {
60
        $filename = PHING_TEST_BASE .
61
            "/etc/tasks/ext/tmp/simple-test.zip";
62
63
        $this->executeTarget(__FUNCTION__);
64
        $this->assertFileExists($filename);
65
66
        $archive = new ZipArchive();
67
        $archive->open($filename);
68
69
        $this->assertEquals('test.txt', $archive->getNameIndex(0));
70
    }
71
72
    public function testZipBaseDir()
73
    {
74
        $filename = PHING_TEST_BASE . '/etc/tasks/ext/tmp/simple-test.zip';
75
76
        $this->executeTarget(__FUNCTION__);
77
        $this->assertFileExists($filename);
78
79
        $archive = new ZipArchive();
80
        $archive->open($filename);
81
82
        $this->assertEquals('test.txt', $archive->getNameIndex(0));
83
    }
84
85
    public function testUnzipSimpleZip()
86
    {
87
        $filename = PHING_TEST_BASE .
88
            "/etc/tasks/ext/tmp/test.txt";
89
90
        $this->assertFileNotExists($filename);
91
92
        $this->executeTarget(__FUNCTION__);
93
94
        $this->assertFileExists($filename);
95
        $this->assertStringEqualsFile($filename, 'TEST');
96
    }
97
}
98