5 * @author Yoshinari Takaoka <takaoka@beatcraft.com>
9 class Dummy_Ethna_Error extends Ethna_Error
14 function dummy_error_callback_global(&$error)
16 $GLOBALS['_dummy_error_callback_global'] = $error->getMessage();
21 * Test Case For Ethna class
25 class Ethna_Class_Test extends Ethna_UnitTestBase
27 var $dummy_error_value_class;
31 $GLOBALS['_dummy_error_callback_global'] = NULL;
32 $this->dummy_error_value_class = NULL;
33 Ethna::clearErrorCallback();
36 function dummy_error_callback_obj(&$error)
38 $this->dummy_error_value_class = $error->getMessage();
42 function test_isError()
44 $error = new Ethna_Error();
45 $this->assertTrue(Ethna::isError($error));
47 $error = 'this is not object, but string.';
48 $this->assertFalse(Ethna::isError($error));
50 $error = new Dummy_Ethna_Error('Error Message', E_CACHE_GENERAL,
51 ETHNA_ERROR_DUMMY, E_USER_ERROR,
54 $this->assertFalse(Ethna::isError($error, E_FORM_REQUIRED));
55 $this->assertTrue(Ethna::isError($error, E_CACHE_GENERAL));
57 $error = new stdClass();
58 $this->assertFalse(Ethna::isError($error));
61 $this->assertFalse(Ethna::isError($error));
63 // Ethna はPEARに依存しないので、
64 // PEAR_Error を渡してもfalse が返らなければならない
65 $fp = @fopen('PEAR.php', 'r', true);
67 require_once 'PEAR.php';
68 $error = new PEAR_Error();
69 $this->assertFalse(Ethna::isError($error));
76 function test_raiseError()
78 $error = Ethna::raiseError('Error!!!!!');
79 $this->assertEqual('Error!!!!!', $error->getMessage());
80 $this->assertEqual(E_USER_ERROR, $error->getLevel());
81 $this->assertEqual(E_GENERAL, $error->getCode());
83 $error = Ethna::raiseError('Error', E_CACHE_GENERAL);
84 $this->assertEqual(E_CACHE_GENERAL, $error->getCode());
88 //{{{ raiseWarning test
89 function test_raiseWarning()
91 $error = Ethna::raiseWarning('Error!!!!!');
92 $this->assertEqual('Error!!!!!', $error->getMessage());
93 $this->assertEqual(E_USER_WARNING, $error->getLevel());
94 $this->assertEqual(E_GENERAL, $error->getCode());
96 $error = Ethna::raiseWarning('Error!!!!!', E_CACHE_GENERAL);
97 $this->assertEqual(E_CACHE_GENERAL, $error->getCode());
101 //{{{ raiseNotice test
102 function test_raiseNotice()
104 $error = Ethna::raiseNotice('Error!!!!!');
105 $this->assertEqual('Error!!!!!', $error->getMessage());
106 $this->assertEqual(E_USER_NOTICE, $error->getLevel());
107 $this->assertEqual(E_GENERAL, $error->getCode());
109 $error = Ethna::raiseNotice('Error!!!!!', E_CACHE_GENERAL);
110 $this->assertEqual(E_CACHE_GENERAL, $error->getCode());
115 function test_error_callback_obj()
117 $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
118 $this->assertNULL($this->dummy_error_value_class);
120 // array の場合は クラス名|オブジェクト + method
121 Ethna::setErrorCallback(array(&$this, 'dummy_error_callback_obj'));
122 Ethna::raiseError('dummy_error_obj!!!');
123 $this->assertEqual('dummy_error_obj!!!', $this->dummy_error_value_class);
124 $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
127 function test_error_callback_global()
129 $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
130 $this->assertNULL($this->dummy_error_value_class);
132 // string の場合はグローバル関数
133 Ethna::setErrorCallback('dummy_error_callback_global');
134 Ethna::raiseError('dummy_error_global!!!');
135 $this->assertEqual('dummy_error_global!!!', $GLOBALS['_dummy_error_callback_global']);
138 function test_error_callback_mixed()
140 // string の場合はグローバル関数
141 Ethna::setErrorCallback('dummy_error_callback_global');
142 Ethna::setErrorCallback(array(&$this, 'dummy_error_callback_obj'));
143 Ethna::raiseError('dummy_error_global!!!');
144 $this->assertEqual('dummy_error_global!!!', $GLOBALS['_dummy_error_callback_global']);
145 $this->assertEqual('dummy_error_global!!!', $this->dummy_error_value_class);