Completed
Push — master ( d52b96...e2f758 )
by Michiel
11:35
created

classes/phing/types/PearPackageFileSetTest.php (1 issue)

1
<?php
2
/**
3
 *
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 *
20
 * @package phing.util
21
 */
22
23
/**
24
 * Testcases for phing.types.PearPackageFileSet
25
 *
26
 * @author  Christian Weiske <[email protected]>
27
 * @package phing.types
28
 */
29
class PearPackageFileSetTest extends BuildFileTest
30
{
31
    public function setUp(): void
32
    {
33
        if (!class_exists('PEAR_Config')) {
34
            $this->markTestSkipped("This test requires PEAR to be installed");
35
        }
36
37
        if (defined('HHVM_VERSION')) {
38
            $this->markTestSkipped("PEAR tests do not run on HHVM");
39
        }
40
41
        //needed for PEAR's Config and Registry classes
42
        error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
43
    }
44
45
    public function testGetDirectoryScannerConsoleGetopt()
46
    {
47
        $ppfs = new PearPackageFileSet();
48
        $ppfs->setPackage('console_getopt');
49
        $ppfs->setRole('php');
50
        $ds = $ppfs->getDirectoryScanner(new Project());
51
52
        $arFiles = $ds->getIncludedFiles();
53
        $this->assertInternalType(
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

53
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
54
            'array',
55
            $arFiles,
56
            'getIncludedFiles returned no array'
57
        );
58
        $this->assertEquals(1, count($arFiles));
59
        $this->assertContains('Console' . DIRECTORY_SEPARATOR . 'Getopt.php', $arFiles);
60
61
        $fullPath = $ds->getBaseDir() . reset($arFiles);
62
        $this->assertTrue(
63
            file_exists($fullPath),
64
            'File does not exist: ' . $fullPath
65
        );
66
    }
67
68
    public function testRoleDoc()
69
    {
70
        $ppfs = new PearPackageFileSet();
71
        $ppfs->setPackage('pear.php.net/Archive_Tar');
72
        $ppfs->setRole('doc');
73
        $ds = $ppfs->getDirectoryScanner(new Project());
74
75
        $arFiles = $ds->getIncludedFiles();
76
        $this->assertContains('docs/Archive_Tar.txt', $arFiles);
77
        foreach ($arFiles as $file) {
78
            $this->assertNotContains(
79
                '.php',
80
                $file,
81
                'php files should not be in there'
82
            );
83
        }
84
    }
85
86
    public function testGetDir()
87
    {
88
        $proj = new Project();
89
        $ppfs = new PearPackageFileSet();
90
        $ppfs->setPackage('console_getopt');
91
        $ppfs->setRole('php');
92
        $ppfs->getDirectoryScanner($proj);
93
94
        $dir = $ppfs->getDir($proj);
95
        $this->assertTrue(
96
            file_exists($dir),
97
            'Directory does not exist: ' . $dir
98
        );
99
        $this->assertTrue(
100
            is_dir($dir),
101
            '$dir is not a directory: ' . $dir
102
        );
103
    }
104
105
    public function testGetDirWithoutScanner()
106
    {
107
        $ppfs = new PearPackageFileSet();
108
        $ppfs->setPackage('console_getopt');
109
        $ppfs->setRole('php');
110
111
        $dir = $ppfs->getDir(new Project());
112
        $this->assertTrue(
113
            file_exists($dir),
114
            'Directory does not exist: ' . $dir
115
        );
116
        $this->assertTrue(
117
            is_dir($dir),
118
            '$dir is not a directory: ' . $dir
119
        );
120
    }
121
122
    /**
123
     * @expectedException BuildException
124
     * @expectedExceptionMessage Invalid package name
125
     */
126
    public function testSetPackageInvalid()
127
    {
128
        $ppfs = new PearPackageFileSet();
129
        $ppfs->setPackage('pear.php.net/console_getopt/thisiswrong');
130
    }
131
}
132