assertInstanceOf(JwtIdentity::class, $identity); // Find identity by oauth2 token $accessToken = new AccessTokenEntity(mock(AbstractServer::class)); $accessToken->setExpireTime(time() + 3600); $accessToken->setId('mock-token'); /** @var AccessTokenInterface|\Mockery\MockInterface $accessTokensStorage */ $accessTokensStorage = mock(AccessTokenInterface::class); $accessTokensStorage->shouldReceive('get')->with('mock-token')->andReturn($accessToken); /** @var Component|\Mockery\MockInterface $component */ $component = mock(Component::class); $component->shouldReceive('getAccessTokenStorage')->andReturn($accessTokensStorage); Yii::$app->set('oauth', $component); $identity = IdentityFactory::findIdentityByAccessToken('mock-token'); $this->assertInstanceOf(LegacyOAuth2Identity::class, $identity); } public function testFindIdentityByAccessTokenWithEmptyValue() { $this->expectException(UnauthorizedHttpException::class); $this->expectExceptionMessage('Incorrect token'); IdentityFactory::findIdentityByAccessToken(''); } protected function _setUp() { parent::_setUp(); Carbon::setTestNow(Carbon::create(2019, 8, 1, 1, 2, 22, 'Europe/Minsk')); } protected function _tearDown() { parent::_tearDown(); Carbon::setTestNow(); } }