From a7100e9006b27e7885eb2ce851d9bc0839ca4468 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Tue, 21 Apr 2015 15:00:18 +0100 Subject: [PATCH] FIX: Object::parse_class_spec failed to parse associative arrays --- core/Object.php | 140 ++++++++++++++++++++++++-------------- tests/core/ObjectTest.php | 24 ++++++- 2 files changed, 111 insertions(+), 53 deletions(-) diff --git a/core/Object.php b/core/Object.php index 14b70a301..131511746 100755 --- a/core/Object.php +++ b/core/Object.php @@ -195,77 +195,113 @@ abstract class Object { $tokens = token_get_all("assertEquals( array('Enum',array(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')), - Object::parse_class_spec("Enum(['Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted']") + Object::parse_class_spec("Enum(['Accepted', 'Pending', 'Declined', 'Unsubmitted'], 'Unsubmitted')") ); // 5.4 Nested shorthand array $this->assertEquals( @@ -426,6 +426,28 @@ class ObjectTest extends SapphireTest { Object::parse_class_spec( "Enum(['Accepted', 'Pending', 'Declined', ['UnsubmittedA','UnsubmittedB']], 'Unsubmitted')") ); + + // Associative array + $this->assertEquals( + array('Varchar', array(255, array('nullifyEmpty' => false))), + Object::parse_class_spec("Varchar(255, array('nullifyEmpty' => false))") + ); + // Nested associative array + $this->assertEquals( + array('Test', array('string', array('nested' => array('foo' => 'bar')))), + Object::parse_class_spec("Test('string', array('nested' => array('foo' => 'bar')))") + ); + // 5.4 shorthand associative array + $this->assertEquals( + array('Varchar', array(255, array('nullifyEmpty' => false))), + Object::parse_class_spec("Varchar(255, ['nullifyEmpty' => false])") + ); + // 5.4 shorthand nested associative array + $this->assertEquals( + array('Test', array('string', array('nested' => array('foo' => 'bar')))), + Object::parse_class_spec("Test('string', ['nested' => ['foo' => 'bar']])") + ); + // Namespaced class $this->assertEquals( array('Test\MyClass', array()),