|
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
|
|
|
namespace Phing\Task\System; |
|
21
|
|
|
|
|
22
|
|
|
use Phing\Support\BuildFileTest; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Tests the Echo Task |
|
26
|
|
|
* |
|
27
|
|
|
* @author Christian Weiske <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class TryCatchTest extends BuildFileTest |
|
30
|
|
|
{ |
|
31
|
|
|
public function setUp(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->configureProject( |
|
34
|
|
|
PHING_TEST_BASE . '/etc/tasks/system/TryCatchTest.xml' |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testTryCatchFinally() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->executeTarget(__FUNCTION__); |
|
41
|
|
|
$this->assertInLogs('In <catch>.'); |
|
42
|
|
|
$this->assertInLogs('In <finally>.'); |
|
43
|
|
|
$this->assertStringEndsWith('Tada!', $this->project->getProperty("prop." . __FUNCTION__)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testExceptionInCatch() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->expectBuildExceptionContaining( |
|
49
|
|
|
__FUNCTION__, |
|
50
|
|
|
'Exception ref.' . __FUNCTION__, |
|
51
|
|
|
'Failing in try' |
|
52
|
|
|
); |
|
53
|
|
|
$this->assertPropertyEquals('prop.' . __FUNCTION__ . '.infinally', 'true'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testExceptionInFinally() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->expectBuildExceptionContaining( |
|
59
|
|
|
__FUNCTION__, |
|
60
|
|
|
'Exception ref.' . __FUNCTION__, |
|
61
|
|
|
'Failing in finally' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertStringContainsString( |
|
65
|
|
|
'Failing in try', |
|
66
|
|
|
$this->project->getProperty('prop.' . __FUNCTION__ . '.message') |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testNoCatch() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->expectBuildExceptionContaining( |
|
73
|
|
|
__FUNCTION__, |
|
74
|
|
|
'Exception ref.' . __FUNCTION__, |
|
75
|
|
|
'Failing in try' |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertPropertyEquals( |
|
79
|
|
|
'prop.' . __FUNCTION__ . '.infinally', |
|
80
|
|
|
'true' |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|