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#1880 from weierophinne…
Browse files Browse the repository at this point in the history
…y/hotfix/view-model-property-overloading

Property overloading was not working in ViewModel
  • Loading branch information
padraic committed Jul 13, 2012
2 parents 376bf70 + 389a65f commit 19f0ef6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Model/ViewModel.php
Expand Up @@ -100,8 +100,7 @@ public function __construct($variables = null, $options = null)
*/
public function __set($name, $value)
{
$variables = $this->getVariables();
$variables[$name] = $value;
$this->setVariable($name, $value);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/Model/ViewModelTest.php
Expand Up @@ -233,4 +233,17 @@ public function testPropertyOverloadingGivesAccessToProperties()
$this->assertFalse(isset($model->foo));
$this->assertFalse(isset($variables['foo']));
}

public function testPropertyOverloadingAllowsWritingPropertiesAfterSetVariablesHasBeenCalled()
{
$model = new ViewModel();
$model->setVariables(array('foo' => 'bar'));
$model->bar = 'baz';

$this->assertTrue(isset($model->bar));
$this->assertEquals('baz', $model->bar);
$variables = $model->getVariables();
$this->assertArrayHasKey('bar', $variables);
$this->assertEquals('baz', $variables['bar']);
}
}

0 comments on commit 19f0ef6

Please sign in to comment.