Completed
Push — master ( dfa745...7082f0 )
by Siad
15:38
created

PhingTest::testPrintUsage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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
 * Core Phing class test
22
 * Do not know why there was no test at all
23
 *
24
 * // TODO implement all methods
25
 *
26
 * @author Kirill chEbba Chebunin <[email protected]>
27
 * @version $Revision: $
28
 * @package phing
29
 */
30
class PhingTest extends \PHPUnit\Framework\TestCase
31
{
32
    const NAMESPACED_CLASS = 'Vendor\\Package\\Sub_Package\\Separated_FullSeparatedClass';
33
    const SEPARATED_CLASS = 'Vendor_Package_SeparatedClass';
34
    const DOTED_CLASS = 'Vendor.Package.DotedClass';
35
    const DOTED_CLASS_SHORTNAME = 'DotedClass';
36
37
    protected $classpath;
38
39
    /**
40
     * Test a PSR-0 support of class loading
41
     * @link http://groups.google.com/group/php-standards/web/psr-0-final-proposal
42
     */
43
    public function testImportPSR0()
44
    {
45
        // Test the namespace support
46
        $className = Phing::import(self::NAMESPACED_CLASS, self::getClassPath());
47
        self::assertEquals(self::NAMESPACED_CLASS, $className);
48
        self::assertTrue(class_exists(self::NAMESPACED_CLASS));
49
50
        // Test PEAR standard
51
        $className = Phing::import(self::SEPARATED_CLASS, self::getClassPath());
52
        self::assertEquals(self::SEPARATED_CLASS, $className);
53
        self::assertTrue(class_exists(self::SEPARATED_CLASS));
54
    }
55
56
    /**
57
     * Test the default dot separated class loading
58
     */
59
    public function testImportDotPath()
60
    {
61
        $className = Phing::import(self::DOTED_CLASS, self::getClassPath());
62
        self::assertEquals(self::DOTED_CLASS_SHORTNAME, $className);
63
        self::assertTrue(class_exists(self::DOTED_CLASS_SHORTNAME));
64
    }
65
66
    /**
67
     * Test the convertShorthand function
68
     */
69
    public function testConvertShorthand()
70
    {
71
        self::assertEquals(0, Phing::convertShorthand('0'));
72
        self::assertEquals(-1, Phing::convertShorthand('-1'));
73
        self::assertEquals(100, Phing::convertShorthand('100'));
74
        self::assertEquals(1024, Phing::convertShorthand('1k'));
75
        self::assertEquals(1024, Phing::convertShorthand('1K'));
76
        self::assertEquals(2048, Phing::convertShorthand('2K'));
77
        self::assertEquals(1048576, Phing::convertShorthand('1M'));
78
        self::assertEquals(1048576, Phing::convertShorthand('1m'));
79
        self::assertEquals(1073741824, Phing::convertShorthand('1G'));
80
        self::assertEquals(1073741824, Phing::convertShorthand('1g'));
81
82
        self::assertEquals(200, Phing::convertShorthand('200j'));
83
    }
84
85
    public function testTimer()
86
    {
87
        $this->assertInstanceOf('Timer', Phing::getTimer());
88
    }
89
90
    public function testFloatOnCurrentTimeMillis()
91
    {
92
        if (method_exists($this, 'assertIsFloat')) {
93
            $this->assertIsFloat(Phing::currentTimeMillis());
94
        } else {
95
            $this->assertInternalType('float', Phing::currentTimeMillis());
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

95
            /** @scrutinizer ignore-deprecated */ $this->assertInternalType('float', Phing::currentTimeMillis());

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...
96
        }
97
    }
98
99
    public function testGetPhingVersion()
100
    {
101
        $this->assertStringStartsWith('Phing ', Phing::getPhingVersion());
102
    }
103
104
    public function testPrintTargets()
105
    {
106
        $target = $this->getMockBuilder(Target::class)->getMock();
107
        $project = $this->getMockBuilder(Project::class)->disableOriginalConstructor()->getMock();
108
        $project->method('getTargets')->willReturn([$target]);
109
        $phing = new Phing();
110
        $phing::setOutputStream($this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock());
111
112
        $this->assertNull($phing->printTargets($project));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $phing->printTargets($project) targeting Phing::printTargets() 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...
113
    }
114
115
    public function testPrintUsage(): void
116
    {
117
        $phing = new Phing();
118
        $phing::setErrorStream($this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock());
119
120
        $this->assertNull($phing::printUsage());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $phing::printUsage() targeting Phing::printUsage() 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...
121
    }
122
123
    public function testCallStartupShutdown()
124
    {
125
        $this->assertNull(Phing::startup());
0 ignored issues
show
Bug introduced by
Are you sure the usage of Phing::startup() targeting Phing::startup() 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...
126
        $this->assertNull(Phing::shutdown());
0 ignored issues
show
Bug introduced by
Are you sure the usage of Phing::shutdown() targeting Phing::shutdown() 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...
127
    }
128
129
    public function testCurrentProject()
130
    {
131
        $project = new Project();
132
        $currProj = Phing::getCurrentProject();
133
        $this->assertNotSame($project, $currProj);
134
135
        Phing::setCurrentProject($project);
136
        $this->assertSame($project, Phing::getCurrentProject());
137
138
        Phing::unsetCurrentProject();
139
        $this->assertNull(Phing::getCurrentProject());
140
    }
141
142
    /**
143
     * Get fixtures classpath
144
     *
145
     * @return string Classpath
146
     */
147
    protected static function getClassPath()
148
    {
149
        return __DIR__ . '/../../etc/importclasses';
150
    }
151
}
152