summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/TComponent.php20
-rw-r--r--tests/UnitTests/framework/common.php20
-rw-r--r--tests/UnitTests/framework/utComponent.php3
3 files changed, 22 insertions, 21 deletions
diff --git a/framework/TComponent.php b/framework/TComponent.php
index 8df1f235..04c99f2a 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -490,13 +490,29 @@ class TPropertyValue
}
/**
- * Converts a value to array type.
+ * Converts a value to array type. If the value is a string and it is
+ * in the form (a,b,c) then an array consisting of each of the elements
+ * will be returned. If the value is a string and it is not in this form
+ * then an array consisting of just the string will be returned. If the value
+ * is not a string then
* @param mixed the value to be converted.
* @return array
*/
public static function ensureArray($value)
{
- return (array)$value;
+ if (is_string($value)) {
+ $trimmed = trim($value);
+ $len = strlen($value);
+ if ($len >= 2 && $trimmed{0} == '(' && $trimmed{$len-1} == ')') {
+ return explode(",", substr($trimmed,1,$len-2));
+ } else if ($len > 0) {
+ return array($value);
+ } else {
+ return array();
+ }
+ } else {
+ return (array)$value;
+ }
}
/**
diff --git a/tests/UnitTests/framework/common.php b/tests/UnitTests/framework/common.php
index bcff7a89..80514875 100644
--- a/tests/UnitTests/framework/common.php
+++ b/tests/UnitTests/framework/common.php
@@ -40,23 +40,11 @@ class PradoUnitTestCase extends UnitTestCase {
* @param string the type of exception that should be raised.
* @return boolean true
*/
- public function assertException(string $code, string $exception) {
- $pass = false;
- $code = "
-try {
- $code
-} catch ($exception \$e) {
- \$pass = true;
-}";
- eval($code);
- if ($pass) {
- $this->pass();
- } else {
- $this->fail("Code did not produce correct exception (wanted $exception, got something else");
- }
+ public function assertException(string $code, string $exceptionType) {
+ $ex = null;
+ eval("try { $code } catch ($exceptionType \$e) { \$ex = \$e; }");
+ $this->assertIsA($ex, $exceptionType);
}
}
-
-
?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/utComponent.php b/tests/UnitTests/framework/utComponent.php
index b47c3de9..bd13b8cb 100644
--- a/tests/UnitTests/framework/utComponent.php
+++ b/tests/UnitTests/framework/utComponent.php
@@ -293,9 +293,6 @@ class utComponent extends UnitTestCase
public function testEnsureObject()
{
$this->assertEqual(TPropertyValue::ensureObject($this->component), $this->component);
- $this->assertNull(TPropertyValue::ensureObject(array(1,2,3)));
- $this->assertNull(TPropertyValue::ensureObject(1));
- $this->assertNull(TPropertyValue::ensureObject("foo"));
}
/**