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
|
|
|
* Test class for the ComposerTask. |
22
|
|
|
* |
23
|
|
|
* @author Nuno Costa <[email protected]> |
24
|
|
|
* @package phing.tasks.ext |
25
|
|
|
*/ |
26
|
|
|
class ComposerTaskTest extends \PHPUnit\Framework\TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ComposerTask |
30
|
|
|
*/ |
31
|
|
|
protected $object; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Sets up the fixture, for example, opens a network connection. |
35
|
|
|
* This method is called before a test is executed. |
36
|
|
|
*/ |
37
|
|
|
protected function setUp(): void |
38
|
|
|
{ |
39
|
|
|
$this->object = new ComposerTask(); |
40
|
|
|
$this->object->setProject(new Project()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Tears down the fixture, for example, closes a network connection. |
45
|
|
|
* This method is called after a test is executed. |
46
|
|
|
*/ |
47
|
|
|
protected function tearDown(): void |
48
|
|
|
{ |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers ComposerTask::setCommand |
53
|
|
|
* @covers ComposerTask::getCommand |
54
|
|
|
*/ |
55
|
|
|
public function testSetGetCommand() |
56
|
|
|
{ |
57
|
|
|
$o = $this->object; |
58
|
|
|
$o->setCommand('foo'); |
59
|
|
|
$this->assertEquals('foo', $o->getCommand()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers ComposerTask::getPhp |
64
|
|
|
* @covers ComposerTask::setPhp |
65
|
|
|
*/ |
66
|
|
|
public function testSetGetPhp() |
67
|
|
|
{ |
68
|
|
|
$o = $this->object; |
69
|
|
|
$o->setPhp('foo'); |
70
|
|
|
$this->assertEquals('foo', $o->getPhp()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers ComposerTask::setComposer |
75
|
|
|
*/ |
76
|
|
|
public function testSetComposer() |
77
|
|
|
{ |
78
|
|
|
$composer = 'foobar'; |
79
|
|
|
$o = $this->object; |
80
|
|
|
$o->setComposer($composer); |
81
|
|
|
|
82
|
|
|
$prop = new ReflectionProperty('ComposerTask', 'composer'); |
83
|
|
|
$prop->setAccessible(true); |
84
|
|
|
|
85
|
|
|
$this->assertEquals($composer, $prop->getValue($o)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers ComposerTask::getComposer |
90
|
|
|
*/ |
91
|
|
|
public function testGetComposerNotOnPath() |
92
|
|
|
{ |
93
|
|
|
$composer = 'bar'; |
94
|
|
|
$o = $this->object; |
95
|
|
|
|
96
|
|
|
$orgPath = getenv("PATH"); |
97
|
|
|
|
98
|
|
|
$prop = new ReflectionProperty('ComposerTask', 'composer'); |
99
|
|
|
$prop->setAccessible(true); |
100
|
|
|
$prop->setValue($o, $composer); |
101
|
|
|
|
102
|
|
|
putenv("PATH=/foo/bar"); |
103
|
|
|
|
104
|
|
|
$pathComposer = $o->getComposer(); |
105
|
|
|
|
106
|
|
|
putenv("PATH=$orgPath"); |
107
|
|
|
|
108
|
|
|
$this->assertEquals($composer, $pathComposer); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @covers ComposerTask::getComposer |
113
|
|
|
*/ |
114
|
|
|
public function testGetComposerFromPath() |
115
|
|
|
{ |
116
|
|
|
$composer = 'foo'; |
117
|
|
|
$o = $this->object; |
118
|
|
|
$o->setComposer($composer); |
119
|
|
|
|
120
|
|
|
$testPath = PHING_TEST_BASE . '/etc/tasks/ext/composer'; |
121
|
|
|
$orgPath = getenv("PATH"); |
122
|
|
|
|
123
|
|
|
$pathSeparator = FileSystem::getFileSystem()->getPathSeparator(); |
124
|
|
|
putenv("PATH=$testPath$pathSeparator$orgPath"); |
125
|
|
|
|
126
|
|
|
$pathComposer = $o->getComposer(); |
127
|
|
|
|
128
|
|
|
putenv("PATH=$orgPath"); |
129
|
|
|
|
130
|
|
|
// The composer found shouldn't be the one we set |
131
|
|
|
$this->assertNotEquals($composer, $pathComposer); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers ComposerTask::createArg |
136
|
|
|
*/ |
137
|
|
|
public function testCreateArg() |
138
|
|
|
{ |
139
|
|
|
$o = $this->object; |
140
|
|
|
$arg = $o->createArg(); |
141
|
|
|
$this->assertTrue(get_class($arg) == 'CommandlineArgument'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testMultipleCalls() |
145
|
|
|
{ |
146
|
|
|
$o = $this->object; |
147
|
|
|
$o->setPhp('php'); |
148
|
|
|
$o->setCommand('install'); |
149
|
|
|
$o->createArg()->setValue('--dry-run'); |
150
|
|
|
$composer = $o->getComposer(); |
151
|
|
|
$method = new ReflectionMethod('ComposerTask', 'prepareCommandLine'); |
152
|
|
|
$method->setAccessible(true); |
153
|
|
|
$this->assertEquals('php ' . $composer . ' install --dry-run', (string) $method->invoke($o)); |
154
|
|
|
$o->setCommand('update'); |
155
|
|
|
$o->createArg()->setValue('--dev'); |
156
|
|
|
$this->assertEquals('php ' . $composer . ' update --dev', (string) $method->invoke($o)); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|