diff --git a/framework/base/Component.php b/framework/base/Component.php index d9b1ae5..4200b26 100644 --- a/framework/base/Component.php +++ b/framework/base/Component.php @@ -135,7 +135,7 @@ class Component elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) { // event, e.g. onClick() $name = strtolower($name); if (!isset($this->_e[$name])) { - $this->_e[$name] = new \yii\collections\Vector; + $this->_e[$name] = new Vector; } return $this->_e[$name]; } @@ -149,7 +149,7 @@ class Component } } } - throw new Exception('Getting unknown property: ' . get_class($this) . '.' $name); + throw new Exception('Getting unknown property: ' . get_class($this) . '.' . $name); } /** @@ -176,7 +176,7 @@ class Component elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) { $name = strtolower($name); if (!isset($this->_e[$name])) { - $this->_e[$name] = new \yii\collections\Vector; + $this->_e[$name] = new Vector; } return $this->_e[$name]->add($value); } @@ -188,10 +188,10 @@ class Component } } if (method_exists($this, 'get' . $name)) { - throw new Exception('Setting read-only property: ' . get_class($this) . '.' $name); + throw new Exception('Setting read-only property: ' . get_class($this) . '.' . $name); } else { - throw new Exception('Setting unknown property: ' . get_class($this) . '.' $name); + throw new Exception('Setting unknown property: ' . get_class($this) . '.' . $name); } } @@ -269,7 +269,7 @@ class Component } } elseif (method_exists($this, 'get' . $name)) { - throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' $name); + throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' . $name); } } @@ -304,7 +304,7 @@ class Component } } } - throw new Exception('Unknown method: ' . get_class($this) . '::' $name . '()'); + throw new Exception('Unknown method: ' . get_class($this) . "::$name()"); } /** diff --git a/framework/test/TestCase.php b/framework/test/TestCase.php index ba2ea1d..7f1a7ce 100644 --- a/framework/test/TestCase.php +++ b/framework/test/TestCase.php @@ -7,7 +7,7 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\test\TestCase; +namespace yii\test; require_once('PHPUnit/Runner/Version.php'); require_once('PHPUnit/Autoload.php'); diff --git a/tests/unit/framework/base/ComponentTest.php b/tests/unit/framework/base/ComponentTest.php index 796db32..af192de 100644 --- a/tests/unit/framework/base/ComponentTest.php +++ b/tests/unit/framework/base/ComponentTest.php @@ -1,6 +1,4 @@ handled=true; } -class ComponentTest extends CTestCase +class ComponentTest extends \yii\test\TestCase { protected $component; @@ -133,7 +131,7 @@ class ComponentTest extends CTestCase { $this->component->attachEventHandler('OnMyEvent',array($this->component,'myEventHandler')); $this->assertFalse($this->component->eventHandled); - $this->component->raiseEvent('OnMyEvent',new CEvent($this)); + $this->component->raiseEvent('OnMyEvent',new \yii\base\Event($this)); $this->assertTrue($this->component->eventHandled); //$this->setExpectedException('CException'); @@ -221,3 +219,53 @@ class ComponentTest extends CTestCase $this->assertEquals('Hello world',$component->evaluateExpression(array($component,'exprEvaluator'),array('who' => 'world'))); } } + +class NewComponent extends \yii\base\Component +{ + private $_object = null; + private $_text = 'default'; + public $eventHandled = false; + public $behaviorCalled = false; + + public function getText() + { + return $this->_text; + } + + public function setText($value) + { + $this->_text=$value; + } + + public function getObject() + { + if(!$this->_object) + { + $this->_object=new NewComponent; + $this->_object->_text='object text'; + } + return $this->_object; + } + + public function onMyEvent() + { + $this->raiseEvent('OnMyEvent',new \yii\base\Event($this)); + } + + public function myEventHandler($event) + { + $this->eventHandled=true; + } + public function exprEvaluator($p1,$comp) { + return "Hello $p1"; + } +} + +class NewBehavior extends \yii\base\Behavior +{ + public function test() + { + $this->owner->behaviorCalled=true; + return 2; + } +}