Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Console GetoptPlus/Exception tests
4
 *
5
 * PHP version 5
6
 *
7
 * All rights reserved.
8
 * Redistribution and use in source and binary forms, with or without modification,
9
 * are permitted provided that the following conditions are met:
10
 * + Redistributions of source code must retain the above copyright notice,
11
 * this list of conditions and the following disclaimer.
12
 * + Redistributions in binary form must reproduce the above copyright notice,
13
 * this list of conditions and the following disclaimer in the documentation and/or
14
 * other materials provided with the distribution.
15
 * + The names of its contributors may not be used to endorse or
16
 * promote products derived from this software without specific prior written permission.
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * @category  PHP
30
 * @package   Console_GetoptPlus
31
 * @author    Michel Corne <mcorne@yahoo.com>
32
 * @copyright 2008 Michel Corne
33
 * @license   http://www.opensource.org/licenses/bsd-license.php The BSD License
34
 * @version   SVN: $Id: ExceptionTest.php 51 2008-01-19 08:54:13Z mcorne $
35
 * @link      http://pear.php.net/package/Console_GetoptPlus
36
 */
37
// Call tests_GetoptPlus_ExceptionTest::main() if this source file is executed directly.
38
if (!defined("PHPUnit_MAIN_METHOD")) {
39
    define("PHPUnit_MAIN_METHOD", "tests_GetoptPlus_ExceptionTest::main");
40
}
41
 
42
require_once "PHPUnit/Framework/TestCase.php";
43
require_once "PHPUnit/Framework/TestSuite.php";
44
 
45
require_once 'Console/GetoptPlus/Exception.php';
46
 
47
/**
48
 * Test class for Console_GetoptPlus_Getopt.
49
 * Generated by PHPUnit_Util_Skeleton on 2007-05-17 at 11:00:39.
50
 *
51
 * @category  PHP
52
 * @package   Console_GetoptPlus
53
 * @author    Michel Corne <mcorne@yahoo.com>
54
 * @copyright 2008 Michel Corne
55
 * @license   http://www.opensource.org/licenses/bsd-license.php The BSD License
56
 * @version   Release:@package_version@
57
 * @link      http://pear.php.net/package/Console_GetoptPlus
58
 */
59
class tests_GetoptPlus_ExceptionTest extends PHPUnit_Framework_TestCase
60
{
61
    /**
62
     * Runs the test methods of this class.
63
     *
64
     * @access public
65
     * @static
66
     */
67
    public static function main()
68
    {
69
        require_once "PHPUnit/TextUI/TestRunner.php";
70
 
71
        $suite = new PHPUnit_Framework_TestSuite("Console_GetoptPlus_ExceptionTest");
72
        $result = PHPUnit_TextUI_TestRunner::run($suite);
73
    }
74
 
75
    /**
76
     * Sets up the fixture, for example, open a network connection.
77
     * This method is called before a test is executed.
78
     *
79
     * @access protected
80
     */
81
    protected function setUp()
82
    {
83
    }
84
 
85
    /**
86
     * Tears down the fixture, for example, close a network connection.
87
     * This method is called after a test is executed.
88
     *
89
     * @access protected
90
     */
91
    protected function tearDown()
92
    {
93
    }
94
 
95
    /**
96
     * Tests exception
97
     */
98
    public function testException()
99
    {
100
        // format: <exception ID and parameters>, <expected exception code and message>
101
        $test = array(// /
102
            array(array('foo'), array(1, 'Console_Getopt: unknown error ID (foo)')),
103
            array(array('mandatory', 'foo'), array(11, 'Console_Getopt: option requires an argument --foo')),
104
            array(array('noargs'), array(13, 'Console_Getopt: Could not read cmd args (register_argc_argv=Off?)')),
105
            );
106
 
107
        foreach($test as $idx => $values) {
108
            list($exception, $expected) = $values;
109
            // triggers the exception and catches the expected exception
110
            try {
111
                throw new Console_GetoptPlus_Exception($exception);
112
            }
113
            catch(Console_GetoptPlus_Exception $e) {
114
                $result = array($e->getCode(), $e->getMessage());
115
            }
116
            $this->assertEquals($expected, $result , 'test #' . $idx);
117
        }
118
    }
119
}
120
// Call tests_GetoptPlus_ExceptionTest::main() if this source file is executed directly.
121
if (PHPUnit_MAIN_METHOD == "tests_GetoptPlus_ExceptionTest::main") {
122
    tests_GetoptPlus_ExceptionTest::main();
123
}
124
 
125
?>