Passed
Push — master ( 06f87c...33b6d3 )
by Siad
08:23
created

PhingTest::testConvertShorthand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 14
rs 9.9
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A PhingTest::testGetPhingVersion() 0 3 1
A PhingTest::testFloatOnCurrentTimeMillis() 0 6 2
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
 * @package phing
28
 */
29
class PhingTest extends \PHPUnit\Framework\TestCase
30
{
31
    private const NAMESPACED_CLASS = 'Vendor\\Package\\Sub_Package\\Separated_FullSeparatedClass';
32
    private const SEPARATED_CLASS = 'Vendor_Package_SeparatedClass';
33
    private const DOTED_CLASS = 'Vendor.Package.DotedClass';
34
    private const DOTED_CLASS_SHORTNAME = 'DotedClass';
35
36
    protected $classpath;
37
38
    /**
39
     * Test a PSR-0 support of class loading
40
     * @link http://groups.google.com/group/php-standards/web/psr-0-final-proposal
41
     */
42
    public function testImportPSR0()
43
    {
44
        // Test the namespace support
45
        $className = Phing::import(self::NAMESPACED_CLASS, self::getClassPath());
46
        self::assertEquals(self::NAMESPACED_CLASS, $className);
47
        self::assertTrue(class_exists(self::NAMESPACED_CLASS));
48
49
        // Test PEAR standard
50
        $className = Phing::import(self::SEPARATED_CLASS, self::getClassPath());
51
        self::assertEquals(self::SEPARATED_CLASS, $className);
52
        self::assertTrue(class_exists(self::SEPARATED_CLASS));
53
    }
54
55
    /**
56
     * Test the default dot separated class loading
57
     */
58
    public function testImportDotPath()
59
    {
60
        $className = Phing::import(self::DOTED_CLASS, self::getClassPath());
61
        self::assertEquals(self::DOTED_CLASS_SHORTNAME, $className);
62
        self::assertTrue(class_exists(self::DOTED_CLASS_SHORTNAME));
63
    }
64
65
    public function testTimer()
66
    {
67
        $this->assertInstanceOf('Timer', Phing::getTimer());
68
    }
69
70
    public function testFloatOnCurrentTimeMillis()
71
    {
72
        if (method_exists($this, 'assertIsFloat')) {
73
            $this->assertIsFloat(Phing::currentTimeMillis());
74
        } else {
75
            $this->assertInternalType('float', Phing::currentTimeMillis());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not exist on PhingTest. Did you maybe mean assertIsIterable()? ( Ignorable by Annotation )

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

75
            $this->/** @scrutinizer ignore-call */ 
76
                   assertInternalType('float', Phing::currentTimeMillis());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
        }
77
    }
78
79
    public function testGetPhingVersion()
80
    {
81
        $this->assertStringStartsWith('Phing ', Phing::getPhingVersion());
82
    }
83
84
    /**
85
     * @requires PHP >= 7.2
86
     */
87
    public function testPrintTargets()
88
    {
89
        $target = $this->getMockBuilder(Target::class)->getMock();
90
        $target->method('getDependencies')->willReturn([]);
91
        $project = $this->getMockBuilder(Project::class)->disableOriginalConstructor()->getMock();
92
        $project->method('getTargets')->willReturn([$target]);
93
        $phing = new Phing();
94
        $phing::setOutputStream($this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock());
95
96
        $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...
97
    }
98
99
    /**
100
     * @requires PHP >= 7.2
101
     */
102
    public function testPrintUsage(): void
103
    {
104
        $phing = new Phing();
105
        $phing::setErrorStream($this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock());
106
107
        $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...
108
    }
109
110
    public function testCallStartupShutdown()
111
    {
112
        $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...
113
        $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...
114
    }
115
116
    public function testCurrentProject()
117
    {
118
        $project = new Project();
119
        $currProj = Phing::getCurrentProject();
120
        $this->assertNotSame($project, $currProj);
121
122
        Phing::setCurrentProject($project);
123
        $this->assertSame($project, Phing::getCurrentProject());
124
125
        Phing::unsetCurrentProject();
126
        $this->assertNull(Phing::getCurrentProject());
127
    }
128
129
    /**
130
     * Get fixtures classpath
131
     *
132
     * @return string Classpath
133
     */
134
    protected static function getClassPath()
135
    {
136
        return __DIR__ . '/../../etc/importclasses';
137
    }
138
}
139