diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index 4af8f3e6..6078feb7 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -262,9 +262,10 @@ public function setVariables($variables, $overwrite = false) } if ($overwrite) { - if (!is_object($variables) && !$variables instanceof ArrayAccess) { + if (is_object($variables) && !$variables instanceof ArrayAccess) { $variables = ArrayUtils::iteratorToArray($variables); } + $this->variables = $variables; return $this; } diff --git a/test/Model/TestAsset/Variable.php b/test/Model/TestAsset/Variable.php new file mode 100644 index 00000000..f1569105 --- /dev/null +++ b/test/Model/TestAsset/Variable.php @@ -0,0 +1,36 @@ +assertSame(iterator_to_array($options), $model->getOptions()); } + public function testAllowsPassingNonArrayAccessObjectsAsArrayInConstructor() + { + $vars = array('foo' => new Variable); + $model = new ViewModel($vars); + $this->assertSame($vars, $model->getVariables()); + } + public function testCanSetVariablesSingly() { $model = new ViewModel(array('foo' => 'bar'));