Commit 7950b793 by Carsten Brandt

Merge pull request #2374 from mintao/master

Some missing base unit tests
parents 89fe3549 7b618734
......@@ -174,9 +174,7 @@ class Component extends Object
}
}
}
if (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '.' . $name);
}
throw new InvalidCallException('Unsetting an unknown or read-only property: ' . get_class($this) . '.' . $name);
}
/**
......
......@@ -303,6 +303,57 @@ class ComponentTest extends TestCase
$this->assertNull($component->getBehavior('a'));
$this->assertNull($component->getBehavior('b'));
}
public function testSetReadOnlyProperty()
{
$this->setExpectedException(
'\yii\base\InvalidCallException',
'Setting read-only property: yiiunit\framework\base\NewComponent::object'
);
$this->component->object = 'z';
}
public function testSetPropertyOfBehavior()
{
$this->assertNull($this->component->getBehavior('a'));
$behavior = new NewBehavior;
$this->component->attachBehaviors([
'a' => $behavior,
]);
$this->component->p = 'Yii is cool.';
$this->assertSame('Yii is cool.', $this->component->getBehavior('a')->p);
}
public function testSettingBehaviorWithSetter()
{
$behaviorName = 'foo';
$this->assertNull($this->component->getBehavior($behaviorName));
$p = 'as ' . $behaviorName;
$this->component->$p = __NAMESPACE__ . '\NewBehavior';
$this->assertSame(__NAMESPACE__ . '\NewBehavior', get_class($this->component->getBehavior($behaviorName)));
}
public function testWriteOnlyProperty()
{
$this->setExpectedException(
'\yii\base\InvalidCallException',
'Getting write-only property: yiiunit\framework\base\NewComponent::writeOnly'
);
$this->component->writeOnly;
}
public function testSuccessfulMethodCheck()
{
$this->assertTrue($this->component->hasMethod('hasProperty'));
}
public function testTurningOffNonExistingBehavior()
{
$this->assertFalse($this->component->hasEventHandlers('foo'));
$this->assertFalse($this->component->off('foo'));
}
}
class NewComponent extends Component
......@@ -357,6 +408,10 @@ class NewComponent extends Component
{
$this->trigger('click', new Event);
}
public function setWriteOnly()
{
}
}
class NewBehavior extends Behavior
......
......@@ -139,6 +139,21 @@ class ObjectTest extends TestCase
$object = new NewObject(['text' => 'test text']);
$this->assertEquals('test text', $object->getText());
}
public function testGetClassName()
{
$object = $this->object;
$this->assertSame(get_class($object), $object::className());
}
public function testReadingWriteOnlyProperty()
{
$this->setExpectedException(
'yii\base\InvalidCallException',
'Getting write-only property: yiiunit\framework\base\NewObject::writeOnly'
);
$this->object->writeOnly;
}
}
......@@ -179,4 +194,6 @@ class NewObject extends Object
{
return $this->_items;
}
public function setWriteOnly(){}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment