id = 1; $account->status = Account::STATUS_ACTIVE; $account->rules_agreement_version = LATEST_RULES_VERSION; $identity = mock(IdentityInterface::class); $identity->shouldReceive('getAccount')->andReturn($account); $component = mock(Component::class . '[findIdentityByAccessToken]', [['secret' => 'secret']]); $component->shouldDeferMissing(); $component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity); Yii::$app->set('user', $component); $this->assertFalse($rule->execute('token', $item, ['accountId' => 2])); $this->assertFalse($rule->execute('token', $item, ['accountId' => '2'])); $this->assertTrue($rule->execute('token', $item, ['accountId' => 1])); $this->assertTrue($rule->execute('token', $item, ['accountId' => '1'])); $account->rules_agreement_version = null; $this->assertFalse($rule->execute('token', $item, ['accountId' => 1])); $this->assertTrue($rule->execute('token', $item, ['accountId' => 1, 'optionalRules' => true])); $account->rules_agreement_version = LATEST_RULES_VERSION; $account->status = Account::STATUS_BANNED; $this->assertFalse($rule->execute('token', $item, ['accountId' => 1])); $this->assertFalse($rule->execute('token', $item, ['accountId' => 1, 'optionalRules' => true])); } /** * @expectedException \yii\base\InvalidParamException */ public function testExecuteWithException() { (new AccountOwner())->execute('', new Item(), []); } }