Skip to content

Commit

Permalink
Fix attachBehavior test
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Aug 22, 2024
1 parent cc05f92 commit be3d8ef
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/framework/base/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -381,6 +380,9 @@ public function testDetachBehavior()

$detachedBehavior = $component->detachBehavior('z');
$this->assertNull($detachedBehavior);

$this->expectException('yii\base\UnknownMethodException');
$component->test();
}

public function testDetachBehaviors()
Expand Down

0 comments on commit be3d8ef

Please sign in to comment.