Исправлен NPE в AccountOwner

This commit is contained in:
ErickSkrauch 2017-12-23 01:10:54 +03:00
parent bd3e8cf2bd
commit 3138a74a7f
2 changed files with 14 additions and 1 deletions

View File

@ -30,7 +30,10 @@ class AccountOwner extends Rule {
}
$identity = Yii::$app->user->findIdentityByAccessToken($accessToken);
/** @noinspection NullPointerExceptionInspection это исключено, т.к. уже сработал authManager */
if ($identity === null) {
return false;
}
$account = $identity->getAccount();
if ($account === null) {
return false;

View File

@ -12,6 +12,16 @@ use const common\LATEST_RULES_VERSION;
class AccountOwnerTest extends TestCase {
public function testIdentityIsNull() {
$component = mock(Component::class . '[findIdentityByAccessToken]', [['secret' => 'secret']]);
$component->shouldDeferMissing();
$component->shouldReceive('findIdentityByAccessToken')->andReturn(null);
Yii::$app->set('user', $component);
$this->assertFalse((new AccountOwner())->execute('some token', new Item(), ['accountId' => 123]));
}
public function testExecute() {
$rule = new AccountOwner();
$item = new Item();