Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2683577
D25326.1734684512.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
D25326.1734684512.diff
View Options
diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php
--- a/src/utils/__tests__/PhutilUtilsTestCase.php
+++ b/src/utils/__tests__/PhutilUtilsTestCase.php
@@ -1070,4 +1070,50 @@
}
}
+
+ public function testStringCasting() {
+ $cases = array(
+ array(123, '123', 'number'),
+ array(null, '', 'null to empty string'),
+ array('text', 'text', 'string'),
+ array(17.4, '17.4', 'float'),
+ array(true, '1', 'boolean true (well done php?)'),
+ array(false, '', 'boolean false (to empty string)'),
+ array(0, '0', 'zero (int)'),
+ array(0.0, '0', 'zero (float'),
+ array(
+ new PhutilURI('http://www.example.com'),
+ 'http://www.example.com',
+ 'Object with toString()',
+ ),
+ );
+
+ $exception_cases = array(
+ array(array(), 'array'),
+ );
+
+ foreach ($cases as $test_case) {
+ list($input, $expected_output, $test_name) = $test_case;
+
+ $actual = phutil_string_cast($input);
+
+ $this->assertEqual($expected_output, $actual, $test_name);
+ }
+
+
+ $expect_exceptions = array('Exception');
+ foreach ($exception_cases as $test_case) {
+ list($input, $test_name) = $test_case;
+
+ try {
+ phutil_string_cast($input);
+ } catch (Exception $ex) {
+ $caught = $ex;
+ } catch (Throwable $ex) {
+ $caught = $ex;
+ }
+
+ $this->assertCaught($expect_exceptions, $caught, $test_name);
+ }
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 08:48 (20 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1017146
Default Alt Text
D25326.1734684512.diff (1 KB)
Attached To
Mode
D25326: Add explicit tests for phutil_string_cast
Attached
Detach File
Event Timeline
Log In to Comment