This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 | |||
21 | namespace Phing\Test; |
||
22 | |||
23 | use Phing\Exception\BuildException; |
||
24 | use Phing\RuntimeConfigurable; |
||
25 | use Phing\Target; |
||
26 | use Phing\Task; |
||
27 | use Phing\Task\System\EchoTask; |
||
28 | use Phing\Test\Support\BuildFileTest; |
||
29 | |||
30 | /** |
||
31 | * UTs for Target component. |
||
32 | * |
||
33 | * @author Victor Farazdagi <[email protected]> |
||
34 | * @author Daniel Holmes |
||
35 | * |
||
36 | * @internal |
||
37 | */ |
||
38 | class TargetTest extends BuildFileTest |
||
39 | { |
||
40 | /** @var Target */ |
||
41 | private $target; |
||
42 | |||
43 | public function setUp(): void |
||
44 | { |
||
45 | $this->configureProject( |
||
46 | PHING_TEST_BASE |
||
47 | . '/etc/components/Target/Target.xml' |
||
48 | ); |
||
49 | |||
50 | $this->target = new Target(); |
||
51 | $this->target->setProject($this->project); |
||
52 | $this->target->setName('MyTarget'); |
||
53 | } |
||
54 | |||
55 | public function testHiddenTargets(): void |
||
56 | { |
||
57 | $phingExecutable = '"' . PHING_TEST_BASE . '/../bin/phing"'; |
||
58 | $buildFile = '"' . PHING_TEST_BASE . '/etc/components/Target/HiddenTargets.xml"'; |
||
59 | $cmd = $phingExecutable . ' -l -f ' . $buildFile; |
||
60 | exec($cmd, $out); |
||
61 | $out = implode("\n", $out); |
||
62 | $offset = strpos($out, 'Subtargets:'); |
||
63 | $this->assertFalse(strpos($out, 'HideInListTarget', $offset)); |
||
64 | $this->assertTrue(false !== strpos($out, 'ShowInListTarget', $offset)); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @dataProvider setDependsValidDataProvider |
||
69 | */ |
||
70 | public function testSetDependsValid(array $expectedDepends, string $depends): void |
||
71 | { |
||
72 | $this->target->setDepends($depends); |
||
73 | |||
74 | $this->assertEquals($expectedDepends, $this->target->getDependencies()); |
||
75 | } |
||
76 | |||
77 | public function setDependsValidDataProvider(): array |
||
78 | { |
||
79 | return [ |
||
80 | [['target1'], 'target1'], |
||
81 | [['target1', 'target2'], 'target1,target2'], |
||
82 | ]; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @dataProvider setDependsInvalidDataProvider |
||
87 | */ |
||
88 | public function testSetDependsInvalid(string $depends): void |
||
89 | { |
||
90 | $this->expectException(BuildException::class); |
||
91 | $this->expectExceptionMessage('Syntax Error: Depend attribute for target MyTarget is malformed.'); |
||
92 | |||
93 | $this->target->setDepends($depends); |
||
94 | } |
||
95 | |||
96 | public function setDependsInvalidDataProvider(): array |
||
97 | { |
||
98 | return [ |
||
99 | [''], |
||
100 | ['target1,'], |
||
101 | ]; |
||
102 | } |
||
103 | |||
104 | public function testGetTasksReturnsCorrectTasks(): void |
||
105 | { |
||
106 | $task = new EchoTask(); |
||
107 | $task->setMessage('Hello World'); |
||
108 | $this->target->addTask($task); |
||
109 | $this->target->addDataType('dataType'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
110 | |||
111 | $tasks = $this->target->getTasks(); |
||
112 | |||
113 | $this->assertEquals([$task], $tasks); |
||
114 | } |
||
115 | |||
116 | public function testGetTasksClonesTasks(): void |
||
117 | { |
||
118 | $task = new EchoTask(); |
||
119 | $task->setMessage('Hello World'); |
||
120 | $this->target->addTask($task); |
||
121 | |||
122 | $tasks = $this->target->getTasks(); |
||
123 | |||
124 | $this->assertNotSame($task, $tasks[0]); |
||
125 | } |
||
126 | |||
127 | public function testMainAppliesConfigurables(): void |
||
128 | { |
||
129 | $configurable = $this->getMockBuilder(RuntimeConfigurable::class) |
||
130 | ->disableOriginalConstructor() |
||
131 | ->getMock() |
||
132 | ; |
||
133 | $configurable->expects($this->once())->method('maybeConfigure')->with($this->project); |
||
134 | $this->target->addDataType($configurable); |
||
135 | |||
136 | $this->target->main(); |
||
137 | } |
||
138 | |||
139 | public function testMainFalseIfDoesntApplyConfigurable(): void |
||
140 | { |
||
141 | $this->project->setProperty('ifProperty', null); |
||
142 | $this->target->setIf('ifProperty'); |
||
143 | |||
144 | $configurable = $this->getMockBuilder(RuntimeConfigurable::class) |
||
145 | ->disableOriginalConstructor() |
||
146 | ->getMock() |
||
147 | ; |
||
148 | $configurable->expects($this->never())->method('maybeConfigure'); |
||
149 | $this->target->addDataType($configurable); |
||
150 | |||
151 | $this->target->main(); |
||
152 | } |
||
153 | |||
154 | public function testMainTrueUnlessDoesntApplyConfigurable(): void |
||
155 | { |
||
156 | $this->project->setProperty('unlessProperty', 'someValue'); |
||
157 | $this->target->setUnless('unlessProperty'); |
||
158 | |||
159 | $configurable = $this->getMockBuilder(RuntimeConfigurable::class) |
||
160 | ->disableOriginalConstructor() |
||
161 | ->getMock() |
||
162 | ; |
||
163 | $configurable->expects($this->never())->method('maybeConfigure'); |
||
164 | $this->target->addDataType($configurable); |
||
165 | |||
166 | $this->target->main(); |
||
167 | } |
||
168 | |||
169 | public function testMainPerformsTasks(): void |
||
170 | { |
||
171 | $task = $this->createMock(Task::class); |
||
172 | $task->expects($this->once())->method('perform'); |
||
173 | $this->target->addTask($task); |
||
174 | |||
175 | $this->target->main(); |
||
176 | } |
||
177 | |||
178 | public function testMainFalseIfDoesntPerformTasks(): void |
||
179 | { |
||
180 | $this->project->setProperty('ifProperty', null); |
||
181 | $this->target->setIf('ifProperty'); |
||
182 | |||
183 | $task = $this->createMock(Task::class); |
||
184 | $task->expects($this->never())->method('perform'); |
||
185 | $this->target->addTask($task); |
||
186 | |||
187 | $this->target->main(); |
||
188 | } |
||
189 | |||
190 | public function testMainTrueUnlessDoesntPerformTasks(): void |
||
191 | { |
||
192 | $this->project->setProperty('unlessProperty', 'someValue'); |
||
193 | $this->target->setUnless('unlessProperty'); |
||
194 | |||
195 | $task = $this->createMock(Task::class); |
||
196 | $task->expects($this->never())->method('perform'); |
||
197 | $this->target->addTask($task); |
||
198 | |||
199 | $this->target->main(); |
||
200 | } |
||
201 | } |
||
202 |