diff --git a/tests/framework/base/ComponentTest.php b/tests/framework/base/ComponentTest.php index 725a7ee7878..55634b0011a 100644 --- a/tests/framework/base/ComponentTest.php +++ b/tests/framework/base/ComponentTest.php @@ -328,20 +328,19 @@ public function testAttachBehavior() $this->assertTrue($component->hasProperty('p')); $component->test(); $this->assertTrue($component->behaviorCalled); + } - $this->assertSame($behavior, $component->detachBehavior('a')); - $this->assertFalse($component->hasProperty('p')); - $this->expectException('yii\base\UnknownMethodException'); - $component->test(); - - $p = 'as b'; + public function testAs() + { $component = new NewComponent(); - $component->$p = ['class' => 'NewBehavior']; - $this->assertSame($behavior, $component->getBehavior('a')); + $component->{'as a'} = new NewBehavior(); $this->assertTrue($component->hasProperty('p')); $component->test(); $this->assertTrue($component->behaviorCalled); + $component->{'as b'} = ['class' => NewBehavior::class]; + $this->assertNotNull($component->getBehavior('b')); + $component->{'as c'} = ['__class' => NewBehavior::class]; $this->assertNotNull($component->getBehavior('c')); @@ -381,6 +380,9 @@ public function testDetachBehavior() $detachedBehavior = $component->detachBehavior('z'); $this->assertNull($detachedBehavior); + + $this->expectException('yii\base\UnknownMethodException'); + $component->test(); } public function testDetachBehaviors()