Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#1 from juriansluiman/h…
Browse files Browse the repository at this point in the history
…otfix/check-for-arrayvariables-in-viewmodel

Hotfix/check for arrayvariables in viewmodel
  • Loading branch information
TR committed Aug 2, 2012
2 parents 5831b90 + a484696 commit 93921b3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Model/ViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function setVariables($variables, $overwrite = false)
}

if ($overwrite) {
if (!is_object($variables) && !$variables instanceof ArrayAccess && !is_array($variables)) {
if (is_object($variables) && !$variables instanceof ArrayAccess) {
$variables = ArrayUtils::iteratorToArray($variables);
}

Expand Down
36 changes: 36 additions & 0 deletions test/Model/TestAsset/Variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_View
*/

namespace ZendTest\View\Model\TestAsset;

use Iterator;

class Variable implements Iterator
{
public function current()
{
}

public function key()
{
}

public function next()
{
}

public function rewind()
{
}

public function valid()
{
}
}
8 changes: 8 additions & 0 deletions test/Model/ViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit_Framework_TestCase as TestCase;
use Zend\View\Model\ViewModel;
use Zend\View\Variables as ViewVariables;
use ZendTest\View\Model\TestAsset\Variable;

/**
* @category Zend
Expand Down Expand Up @@ -53,6 +54,13 @@ public function testAllowsPassingTraversableArgumentsToVariablesAndOptionsInCons
$this->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'));
Expand Down

0 comments on commit 93921b3

Please sign in to comment.