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()); |
|
|
|
|
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)); |
|
|
|
|
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()); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testCallStartupShutdown() |
124
|
|
|
{ |
125
|
|
|
$this->assertNull(Phing::startup()); |
|
|
|
|
126
|
|
|
$this->assertNull(Phing::shutdown()); |
|
|
|
|
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
|
|
|
|
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.